Views
No views yet
transformers library.pytorch_model.bin: Model weightsconfig.json: Model configurationtokenizer.json: Tokenizer vocabularyspecial_tokens_map.json: Special token mappingstokenizer_config.json: Tokenizer configuration1from transformers import AutoModelForSequenceClassification, AutoTokenizer
2import torch
3
4# Load the model and tokenizer from Hugging Face Hub
5model_name = "vinD27/stock_news" # Replace with your model repo name
6model = AutoModelForSequenceClassification.from_pretrained(model_name)
7tokenizer = AutoTokenizer.from_pretrained(model_name)
8
9# Map label indices to human-readable class names
10label_mapping = {
11 0: "negative",
12 1: "neutral",
13 2: "positive"
14}
15
16# Input text
17input_text = "Wow. The stock is amazing"
18
19# Tokenize and predict
20inputs = tokenizer(input_text, return_tensors="pt", truncation=True, padding=True, max_length=128)
21outputs = model(**inputs)
22predicted_class_idx = torch.argmax(outputs.logits, dim=-1).item() # Get the predicted label index
23
24# Print the results
25print(f"Your input is: '{input_text}'")
26print(f"And the prediction is: {label_mapping[predicted_class_idx]} ({predicted_class_idx})")