Text Classification
Transformers
TensorBoard
Safetensors
roberta
yelp
sentiment-analysis
polarity
Eval Results (legacy)
text-embeddings-inference
Instructions to use ErphanRajai/yelp-polarity-roberta with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use ErphanRajai/yelp-polarity-roberta with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="ErphanRajai/yelp-polarity-roberta")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForSequenceClassification tokenizer = AutoTokenizer.from_pretrained("ErphanRajai/yelp-polarity-roberta") model = AutoModelForSequenceClassification.from_pretrained("ErphanRajai/yelp-polarity-roberta", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Download app.py from ErphanRajai/yelp-polarity-roberta: direct link, hf CLI and curl.
- Browser
- Download file 1.25 kB
-
https://huggingface.co/ErphanRajai/yelp-polarity-roberta/resolve/main/app.py
- Command line
-
hf download hf://ErphanRajai/yelp-polarity-roberta/app.py
-
curl -L -o app.py https://huggingface.co/ErphanRajai/yelp-polarity-roberta/resolve/main/app.py
1.25 kB
| import gradio as gr | |
| import torch | |
| from transformers import AutoTokenizer, AutoModelForSequenceClassification | |
| # Load model and tokenizer (make sure you push your trained model to Hugging Face Hub) | |
| MODEL_NAME = "your-username/yelp-polarity-roberta" # change to your repo after push | |
| device = "cuda" if torch.cuda.is_available() else "cpu" | |
| tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME) | |
| model = AutoModelForSequenceClassification.from_pretrained(MODEL_NAME).to(device) | |
| labels = ["Negative", "Positive"] | |
| def predict_sentiment(text): | |
| inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True, max_length=128).to(device) | |
| with torch.no_grad(): | |
| outputs = model(**inputs) | |
| probs = torch.softmax(outputs.logits, dim=-1).cpu().numpy()[0] | |
| return {labels[i]: float(probs[i]) for i in range(len(labels))} | |
| demo = gr.Interface( | |
| fn=predict_sentiment, | |
| inputs=gr.Textbox(lines=3, placeholder="Write a Yelp review here..."), | |
| outputs=gr.Label(num_top_classes=2), | |
| title="Yelp Polarity Classifier", | |
| description="A sentiment classifier trained on the Yelp Polarity dataset. Enter a review and get predicted sentiment." | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() | |