1from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
2
3model_id = "your-username/sentiment-bert-small"
4
5# Load tokenizer and model
6tokenizer = AutoTokenizer.from_pretrained(model_id)
7model = AutoModelForSequenceClassification.from_pretrained(model_id)
8
9# Create a pipeline
10sentiment = pipeline("text-classification", model=model, tokenizer=tokenizer, return_all_scores=False)
11
12examples = [
13 "I absolutely loved the product — exceeded my expectations.",
14 "The update made things worse; I'm very disappointed."
15]
16
17for text in examples:
18 result = sentiment(text)[0]
19 print(f"Text: {text}\nLabel: {result['label']}, Score: {result['score']:.4f}\n")