Views
No views yet
1---
2language: en
3license: mit
4base_model: cardiffnlp/twitter-roberta-base-sentiment-latest
5tags:
6- sentiment-analysis
7- food-reviews
8- roberta
9- text-classification
10- fine-tuned
11datasets:
12- food-com-recipes-and-user-interactions
13pipeline_tag: text-classification
14widget:
15- text: "This recipe was absolutely delicious! Will make again."
16 example_title: "Positive review"
17- text: "Too salty and instructions were confusing."
18 example_title: "Negative review"
19- text: "It was okay, nothing special."
20 example_title: "Neutral review"
21---1from transformers import pipeline
2
3# Load the model
4analyzer = pipeline(
5 "sentiment-analysis",
6 model="TahianaAndriambahoaka/sentiment-analysis-food-reviews"
7)
8
9# Analyze a review
10result = analyzer("This recipe is amazing!")
11print(result)
12# Output: [{'label': 'positive', 'score': 0.9876}]
13
14### Batch processing multiple reviews
15
16```python
17reviews = [
18 "Amazing! Will make again.",
19 "Too salty, not recommended.",
20 "It was okay, nothing special."
21]
22
23results = analyzer(reviews)
24for review, result in zip(reviews, results):
25 print(f"{review}: {result['label']} ({result['score']:.2%})")1from transformers import AutoTokenizer, AutoModelForSequenceClassification
2import torch
3
4model_name = "TahianaAndriambahoaka/sentiment-analysis-food-reviews"
5tokenizer = AutoTokenizer.from_pretrained(model_name)
6model = AutoModelForSequenceClassification.from_pretrained(model_name)
7
8text = "This recipe is amazing!"
9inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True, max_length=256)
10
11with torch.no_grad():
12 outputs = model(**inputs)
13 predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)
14 predicted_class = torch.argmax(predictions, dim=-1).item()
15
16label_map = {0: "negative", 1: "neutral", 2: "positive"}
17print(f"Sentiment: {label_map[predicted_class]}")@article{food-com-dataset,
title={Food.com Recipes and User Interactions},
author={Shuyang Li},
year={2019},
url={https://www.kaggle.com/shuyangli94/food-com-recipes-and-user-interactions}
}