Views
No views yet
pip install transformers torch1
2from transformers import RobertaTokenizerFast, RobertaForSequenceClassification, Trainer, TrainingArguments
3import torch
4
5
6
7# Load tokenizer
8
9tokenizer = RobertaTokenizerFast.from_pretrained("roberta-base")
10
11# Define a test sentence
12
13test_sentence = "The food was absolutely delicious and the service was amazing!"
14
15# Tokenize input
16
17inputs = tokenizer(test_sentence, return_tensors="pt", padding=True, truncation=True, max_length=128)
18
19# Ensure input tensors are in correct dtype
20
21inputs["input_ids"] = inputs["input_ids"].long() # Convert to long type
22
23inputs["attention_mask"] = inputs["attention_mask"].long() # Convert to long type
24
25
26# Make prediction
27
28with torch.no_grad():
29
30 outputs = quantized_model(**inputs)
31
32# Get predicted class
33
34predicted_class = torch.argmax(outputs.logits, dim=1).item()
35
36print(f"Predicted Class: {predicted_class}")
37
38
39label_mapping = {0: "Negative", 1: "Neutral", 2: "Positive"}
40
41#Example
42
43predicted_label = label_mapping[predicted_class]
44
45print(f"Predicted Label: {predicted_label}")
46
.
├── config.json
├── tokenizer_config.json
├── special_tokens_map.json
├── tokenizer.json
├── model.safetensors # Fine Tuned Model
├── README.md # Model documentation