Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: mit
|
3 |
+
datasets:
|
4 |
+
- Yelp/yelp_review_full
|
5 |
+
metrics:
|
6 |
+
- accuracy
|
7 |
+
base_model:
|
8 |
+
- distilbert/distilbert-base-uncased
|
9 |
+
library_name: transformers
|
10 |
+
tags:
|
11 |
+
- Sentiment Analysis
|
12 |
+
- Text Classification
|
13 |
+
- BERT
|
14 |
+
- Yelp Reviews
|
15 |
+
- Fine-tuned
|
16 |
+
---
|
17 |
+
# Yelp Review Classifier
|
18 |
+
|
19 |
+
This model is a sentiment classification model for Yelp reviews, trained to predict whether a review is **positive** or **negative**. The model was fine-tuned using the `distilbert-base-uncased` model architecture, based on the [DistilBERT model](https://huggingface.co/distilbert/distilbert-base-uncased) from Hugging Face, and trained on a Yelp reviews dataset.
|
20 |
+
|
21 |
+
## Model Details
|
22 |
+
- **Model Type**: DistilBERT-based model for sequence classification
|
23 |
+
- **Model Architecture**: `distilbert-base-uncased`
|
24 |
+
- **Number of Parameters**: Approximately 66M parameters
|
25 |
+
- **Training Dataset**: The model was trained on a curated Yelp reviews dataset, labeled for sentiment (positive/negative).
|
26 |
+
- **Fine-Tuning Task**: Sentiment analysis for Yelp reviews (positive or negative sentiment)
|
27 |
+
|
28 |
+
## Training Data
|
29 |
+
- **Dataset**: Custom Yelp reviews dataset
|
30 |
+
- **Data Description**: The dataset consists of Yelp reviews, each labeled with a sentiment (positive/negative).
|
31 |
+
- **Preprocessing**: The dataset was preprocessed by cleaning the reviews to remove unwanted characters and URLs.
|
32 |
+
|
33 |
+
## Training Details
|
34 |
+
- **Training Framework**: Hugging Face Transformers and PyTorch
|
35 |
+
- **Learning Rate**: 2e-5
|
36 |
+
- **Epochs**: 6
|
37 |
+
- **Batch Size**: 16
|
38 |
+
- **Optimizer**: AdamW
|
39 |
+
- **Training Time**: Approximately 2 hours on a GPU
|
40 |
+
|
41 |
+
## Usage
|
42 |
+
To use the model for inference, you can use the following code:
|
43 |
+
|
44 |
+
```python
|
45 |
+
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
46 |
+
import torch
|
47 |
+
|
48 |
+
# Load the fine-tuned model and tokenizer from Hugging Face
|
49 |
+
model_name = "kmack/YELP-Review_Classifier" # Replace with your model name if different
|
50 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
51 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
52 |
+
|
53 |
+
# List of reviews for prediction
|
54 |
+
reviews = [
|
55 |
+
"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!",
|
56 |
+
"It was decent, but nothing special. The food was okay, but the service was a bit slow. I think there are better places around.",
|
57 |
+
"I had a terrible experience. The waiter was rude, and the food was cold when it arrived. I won't be returning anytime soon."
|
58 |
+
]
|
59 |
+
|
60 |
+
# Map prediction to star ratings
|
61 |
+
label_map = {
|
62 |
+
0: "1 Star",
|
63 |
+
1: "2 Stars",
|
64 |
+
2: "3 Stars",
|
65 |
+
3: "4 Stars",
|
66 |
+
4: "5 Stars"
|
67 |
+
}
|
68 |
+
|
69 |
+
# Iterate over each review and get the prediction
|
70 |
+
for review in reviews:
|
71 |
+
# Tokenize the input text
|
72 |
+
inputs = tokenizer(review, return_tensors="pt", padding=True, truncation=True)
|
73 |
+
|
74 |
+
# Get predictions
|
75 |
+
with torch.no_grad():
|
76 |
+
outputs = model(**inputs)
|
77 |
+
|
78 |
+
# Get the predicted label (0 to 4 for star ratings)
|
79 |
+
prediction = torch.argmax(outputs.logits, dim=-1).item()
|
80 |
+
|
81 |
+
# Map prediction to star rating
|
82 |
+
predicted_rating = label_map[prediction]
|
83 |
+
|
84 |
+
print(f"Rating: {predicted_rating}\n")
|
85 |
+
```
|
86 |
+
|
87 |
+
## Citation
|
88 |
+
|
89 |
+
If you use this model in your research, please cite the following:
|
90 |
+
|
91 |
+
```@misc{YELP-Review_Classifier,
|
92 |
+
author = {Kmack},
|
93 |
+
title = {YELP-Review_Classifier},
|
94 |
+
year = {2024},
|
95 |
+
url = {https://huggingface.co/kmack/YELP-Review_Classifier}
|
96 |
+
}
|
97 |
+
```
|