Yelp/yelp_review_full
Viewer • Updated • 700k • 22.6k • 144
How to use kmack/YELP-Review_Classifier with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-classification", model="kmack/YELP-Review_Classifier") # Load model directly
from transformers import AutoTokenizer, AutoModelForSequenceClassification
tokenizer = AutoTokenizer.from_pretrained("kmack/YELP-Review_Classifier")
model = AutoModelForSequenceClassification.from_pretrained("kmack/YELP-Review_Classifier")This model is a sentiment classification model for Yelp reviews, trained to predict whether a review is star ratings (1 to 5 stars). The model was fine-tuned using the distilbert-base-uncased model architecture, based on the DistilBERT model from Hugging Face, and trained on a Yelp reviews dataset.
distilbert-base-uncasedTo use the model for inference, you can use the following code:
from transformers import AutoModelForSequenceClassification, AutoTokenizer
import torch
# Load the fine-tuned model and tokenizer from Hugging Face
model_name = "kmack/YELP-Review_Classifier" # Replace with your model name if different
model = AutoModelForSequenceClassification.from_pretrained(model_name)
tokenizer = AutoTokenizer.from_pretrained(model_name)
# List of reviews for prediction
reviews = [
"The food was absolutely delicious, and the atmosphere was perfect for a family gathering. The staff was friendly, and we had a great time. Definitely coming back!",
"It was decent, but nothing special. The food was okay, but the service was a bit slow. I think there are better places around.",
"I had a terrible experience. The waiter was rude, and the food was cold when it arrived. I won't be returning anytime soon."
]
# Map prediction to star ratings
label_map = {
0: "1 Star",
1: "2 Stars",
2: "3 Stars",
3: "4 Stars",
4: "5 Stars"
}
# Iterate over each review and get the prediction
for review in reviews:
# Tokenize the input text
inputs = tokenizer(review, return_tensors="pt", padding=True, truncation=True)
# Get predictions
with torch.no_grad():
outputs = model(**inputs)
# Get the predicted label (0 to 4 for star ratings)
prediction = torch.argmax(outputs.logits, dim=-1).item()
# Map prediction to star rating
predicted_rating = label_map[prediction]
print(f"Rating: {predicted_rating}\n")
If you use this model in your research, please cite the following:
author = {Kmack},
title = {YELP-Review_Classifier},
year = {2024},
url = {https://huggingface.co/kmack/YELP-Review_Classifier}
}
Base model
distilbert/distilbert-base-uncased