Instructions to use karimbkh/BERT_fineTuned_Sentiment_Classification_Yelp with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use karimbkh/BERT_fineTuned_Sentiment_Classification_Yelp with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="karimbkh/BERT_fineTuned_Sentiment_Classification_Yelp")# Load model directly from transformers import AutoTokenizer, AutoModelForSequenceClassification tokenizer = AutoTokenizer.from_pretrained("karimbkh/BERT_fineTuned_Sentiment_Classification_Yelp") model = AutoModelForSequenceClassification.from_pretrained("karimbkh/BERT_fineTuned_Sentiment_Classification_Yelp", device_map="auto") - Notebooks
- Google Colab
- Kaggle
metadata
license: mit
datasets:
- yelp_review_full
language:
- en
metrics:
- accuracy
- f1
library_name: transformers
Model Card
Sentiment Analysis of Restaurant Reviews from Yelp Dataset
Overview
- Task: Sentiment classification of restaurant reviews from the Yelp dataset.
- Model: Fine-tuned BERT (Bidirectional Encoder Representations from Transformers) for sequence classification.
- Training Dataset: Yelp dataset containing restaurant reviews.
- Training Framework: PyTorch and Transformers library.
Model Details
- Pre-trained Model: BERT-base-uncased.
- Input: Cleaned and preprocessed restaurant reviews.
- Output: Binary classification (positive or negative sentiment).
- Tokenization: BERT tokenizer with a maximum sequence length of 240 tokens.
- Optimizer: AdamW with a learning rate of 3e-5.
- Learning Rate Scheduler: Linear scheduler with no warmup steps.
- Loss Function: CrossEntropyLoss.
- Batch Size: 16.
- Number of Epochs: 2.
Data Preprocessing
- Loaded Yelp reviews dataset and business dataset.
- Merged datasets on the "business_id" column.
- Removed unnecessary columns and duplicates.
- Translated star ratings into binary sentiment labels (positive or negative).
- Upsampled the minority class (negative sentiment) to address imbalanced data.
- Cleaned text data by removing non-letters, converting to lowercase, and tokenizing.
Model Training
- Split the dataset into training (70%), validation (15%), and test (15%) sets.
- Tokenized, padded, and truncated input sequences.
- Created attention masks to differentiate real tokens from padding.
- Fine-tuned BERT using the specified hyperparameters.
- Tracked training and validation accuracy and loss for each epoch.
Model Evaluation
- Achieved high accuracy and F1 scores on both the validation and test sets.
- Generalization observed, as the accuracy on the test set was similar to the validation set.
- The model showed improvement in validation loss, indicating no overfitting.
Model Deployment
- Saved the trained model and tokenizer.
- Published the model and tokenizer to the Hugging Face Model Hub.
- Demonstrated how to load and use the model for making predictions.
Model Performance
- Validation Accuracy: ≈ 97.5% - 97.8%
- Test Accuracy: ≈ 97.8%
- F1 Score: ≈ 97.8% - 97.9%
Limitations
- Excluding stopwords may impact contextual understanding, but it was necessary to handle token length limitations.
- Performance may vary on reviews in languages other than English.
Conclusion
The fine-tuned BERT model demonstrates robust sentiment analysis on Yelp restaurant reviews. Its high accuracy and F1 scores indicate effectiveness in capturing sentiment from user-generated content. The model is suitable for deployment in applications requiring sentiment classification for restaurant reviews.