Instructions to use godlykmathews/BERT-Sentiment_Classifier with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use godlykmathews/BERT-Sentiment_Classifier with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="godlykmathews/BERT-Sentiment_Classifier")# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("godlykmathews/BERT-Sentiment_Classifier", device_map="auto") - Notebooks
- Google Colab
- Kaggle
|
Download README.md from godlykmathews/BERT-Sentiment_Classifier: direct link, hf CLI and curl.
- Browser
- Download file 3.96 kB
-
https://huggingface.co/godlykmathews/BERT-Sentiment_Classifier/resolve/main/README.md
- Command line
-
hf download hf://godlykmathews/BERT-Sentiment_Classifier/README.md
-
curl -L -o README.md https://huggingface.co/godlykmathews/BERT-Sentiment_Classifier/resolve/main/README.md
3.96 kB
| language: | |
| - en | |
| library_name: transformers | |
| pipeline_tag: text-classification | |
| base_model: google-bert/bert-base-uncased | |
| datasets: | |
| - Yelp/yelp_review_full | |
| tags: | |
| - bert | |
| - sentiment-analysis | |
| - pytorch | |
| - text-classification | |
| metrics: | |
| - accuracy | |
| - precision | |
| - recall | |
| - f1 | |
| # BERT Sentiment Classifier | |
| A fine-tuned BERT model for classifying English reviews as **Negative**, **Neutral**, or **Positive**. | |
| The model was fine-tuned from [google-bert/bert-base-uncased](https://huggingface.co/google-bert/bert-base-uncased) using a subset of [Yelp Review Full](https://huggingface.co/datasets/Yelp/yelp_review_full). | |
| ## Labels | |
| | Class ID | Sentiment | Original Yelp rating | | |
| |---|---|---| | |
| | 0 | Negative | 1–2 stars | | |
| | 1 | Neutral | 3 stars | | |
| | 2 | Positive | 4–5 stars | | |
| Three-star reviews serve as a neutral proxy and may contain mixed opinions. | |
| ## Usage | |
| ```python | |
| import html | |
| import re | |
| from transformers import pipeline | |
| classifier = pipeline( | |
| "text-classification", | |
| model="godlykmathews/BERT-Sentiment_Classifier", | |
| ) | |
| def clean_text(text): | |
| text = html.unescape(text) | |
| text = re.sub(r"<br\s*/?>", " ", text, flags=re.IGNORECASE) | |
| text = text.replace("\\n", " ").replace("\\t", " ") | |
| return re.sub(r"\s+", " ", text).strip() | |
| review = "The food was wonderful and the service was excellent!" | |
| result = classifier( | |
| clean_text(review), | |
| truncation=True, | |
| max_length=128, | |
| ) | |
| print(result) | |
| ``` | |
| ## Training Data | |
| | Split | Reviews | | |
| |---|---:| | |
| | Training | 15,000 | | |
| | Validation | 1,500 | | |
| | Test | 3,000 | | |
| Training and validation samples were selected from Yelp’s official training split. Test samples were selected from its official test split. | |
| Sampling was stratified with a random seed of 42. Empty reviews, duplicate normalized text, and conflicting duplicate labels were removed from the sampled pools. Duplicate text shared between the development and test samples was excluded. | |
| Preprocessing decoded HTML entities, normalized line breaks, and collapsed whitespace. Negation, punctuation, and stopwords were retained. | |
| ## Training Configuration | |
| | Setting | Value | | |
| |---|---| | |
| | Framework | PyTorch | | |
| | Transformers version | 5.12.1 | | |
| | Optimizer | AdamW | | |
| | Learning rate | 2e-5 | | |
| | Epochs | 3 | | |
| | Batch size | 4 | | |
| | Gradient accumulation steps | 4 | | |
| | Effective batch size | 16 on one device | | |
| | Maximum sequence length | 128 tokens | | |
| | Weight decay | 0.01 | | |
| | Warmup | Approximately 10% of update steps | | |
| | Random seed | 42 | | |
| The BERT encoder and classification layer were both fine-tuned. Validation ran after each epoch, and the checkpoint with the highest validation macro F1 was selected for final evaluation. | |
| ## Evaluation Results | |
| Results on the held-out sample of 3,000 Yelp reviews: | |
| | Metric | Value | | |
| |---|---:| | |
| | Accuracy | 0.7740 | | |
| | Macro precision | 0.7281 | | |
| | Macro recall | 0.7275 | | |
| | Macro F1 | 0.7278 | | |
| | Weighted F1 | 0.7734 | | |
| ### Per-class Results | |
| | Sentiment | Precision | Recall | F1 | Support | | |
| |---|---:|---:|---:|---:| | |
| | Negative | 0.8280 | 0.8425 | 0.8352 | 1,200 | | |
| | Neutral | 0.5042 | 0.4950 | 0.4996 | 600 | | |
| | Positive | 0.8521 | 0.8450 | 0.8485 | 1,200 | | |
| Macro averages weight each class equally. Neutral classification was the weakest area in this evaluation. | |
| ## Intended Uses | |
| - Educational sentiment-analysis projects. | |
| - Classifying English review text. | |
| - Demonstrations through a Streamlit interface. | |
| ## Limitations | |
| - Neutral labels are derived from three-star ratings rather than independent neutral-sentiment annotations. | |
| - Performance on Yelp does not establish performance on movie reviews, other product domains, or other languages. | |
| - Reviews longer than 128 tokens are truncated. | |
| - Sarcasm, mixed opinions, and ambiguous language may produce incorrect predictions. | |
| - Output probabilities are not calibrated guarantees of correctness. | |
| ## Project | |
| [Source code, training notebook, and Streamlit app](https://github.com/godlykmathews/bert-sentiment-classifier) |