Create README.md
Browse files
README.md
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
datasets:
|
| 4 |
+
- stanfordnlp/imdb
|
| 5 |
+
language:
|
| 6 |
+
- en
|
| 7 |
+
base_model:
|
| 8 |
+
- google-bert/bert-base-uncased
|
| 9 |
+
pipeline_tag: text-classification
|
| 10 |
+
tags:
|
| 11 |
+
- IMDB
|
| 12 |
+
- Sentiment Analysis
|
| 13 |
+
---
|
| 14 |
+
# BERT-Based Sentiment Analysis Models
|
| 15 |
+
|
| 16 |
+
## Model Description
|
| 17 |
+
|
| 18 |
+
This repository contains two versions of BERT-based models fine-tuned for sentiment analysis tasks:
|
| 19 |
+
|
| 20 |
+
- **BERT-1**: Fine-tuned on the IMDB movie reviews dataset.
|
| 21 |
+
- **BERT-2**: Fine-tuned on a combined dataset of IMDB movie reviews dataset and Twitter comments.
|
| 22 |
+
|
| 23 |
+
Both models are based on the `bert-base-uncased` pre-trained model from Hugging Face's Transformers library.
|
| 24 |
+
|
| 25 |
+
## Intended Use
|
| 26 |
+
|
| 27 |
+
These models are intended for binary sentiment analysis of English text data. They can be used to classify text into positive or negative sentiment categories.
|
| 28 |
+
|
| 29 |
+
### Loading the Models
|
| 30 |
+
|
| 31 |
+
```python
|
| 32 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 33 |
+
|
| 34 |
+
# Load BERT-1
|
| 35 |
+
tokenizer_bert1 = AutoTokenizer.from_pretrained("verneylmavt/bert-base-uncased_sentiment-analysis/bert-1")
|
| 36 |
+
model_bert1 = AutoModelForSequenceClassification.from_pretrained("verneylmavt/bert-base-uncased_sentiment-analysis/bert-1")
|
| 37 |
+
|
| 38 |
+
# Load BERT-2
|
| 39 |
+
tokenizer_bert2 = AutoTokenizer.from_pretrained("verneylmavt/bert-base-uncased_sentiment-analysis/bert-2")
|
| 40 |
+
model_bert2 = AutoModelForSequenceClassification.from_pretrained("verneylmavt/bert-base-uncased_sentiment-analysis/bert-2")
|
| 41 |
+
```
|
| 42 |
+
|
| 43 |
+
### Performing Sentiment Analysis
|
| 44 |
+
|
| 45 |
+
```python
|
| 46 |
+
from transformers import pipeline
|
| 47 |
+
|
| 48 |
+
# Initialize pipelines
|
| 49 |
+
sentiment_pipeline_bert1 = pipeline("sentiment-analysis", model=model_bert1, tokenizer=tokenizer_bert1)
|
| 50 |
+
sentiment_pipeline_bert2 = pipeline("sentiment-analysis", model=model_bert2, tokenizer=tokenizer_bert2)
|
| 51 |
+
|
| 52 |
+
# Sample text
|
| 53 |
+
text = "I absolutely loved this product! It exceeded my expectations."
|
| 54 |
+
|
| 55 |
+
# Get predictions
|
| 56 |
+
result_bert1 = sentiment_pipeline_bert1(text)
|
| 57 |
+
result_bert2 = sentiment_pipeline_bert2(text)
|
| 58 |
+
|
| 59 |
+
print("BERT-1 Prediction:", result_bert1)
|
| 60 |
+
print("BERT-2 Prediction:", result_bert2)
|
| 61 |
+
```
|
| 62 |
+
|
| 63 |
+
## Training Details
|
| 64 |
+
|
| 65 |
+
### BERT-1
|
| 66 |
+
|
| 67 |
+
- **Dataset**: [IMDB Movie Reviews Dataset](https://ai.stanford.edu/~amaas/data/sentiment/)
|
| 68 |
+
- **Objective**: Binary sentiment classification (positive/negative)
|
| 69 |
+
- **Optimizer**: AdamW with a learning rate `lr` (value unspecified)
|
| 70 |
+
- **Scheduler**: Linear scheduler with warmup (`get_linear_schedule_with_warmup`)
|
| 71 |
+
- **Epochs**: `num_epochs = 3`
|
| 72 |
+
- **Device**: Trained on GPU if available
|
| 73 |
+
- **Metrics Monitored**: Training loss, training accuracy, testing accuracy per epoch
|
| 74 |
+
|
| 75 |
+
### BERT-2
|
| 76 |
+
|
| 77 |
+
- **Dataset**:
|
| 78 |
+
- [IMDB Movie Reviews Dataset](https://ai.stanford.edu/~amaas/data/sentiment/)
|
| 79 |
+
- [Twitter Comment - Sentiment Analysis Dataset](https://www.kaggle.com/datasets/abhi8923shriv/sentiment-analysis-dataset)
|
| 80 |
+
- **Objective**: Binary sentiment classification (positive/negative)
|
| 81 |
+
- **Optimizer**: AdamW with weight decay (`0.01`) and parameters requiring gradients
|
| 82 |
+
- **Scheduler**: Linear scheduler with warmup (`10%` of total steps)
|
| 83 |
+
- **Gradient Clipping**: Applied with `max_norm=1.0`
|
| 84 |
+
- **Early Stopping**: Implemented with a patience of `2` epochs without improvement in validation loss
|
| 85 |
+
- **Epochs**: `num_epochs = 3`, training may stop early due to early stopping
|
| 86 |
+
- **Device**: Trained on GPU if available
|
| 87 |
+
- **Metrics Monitored**: Training loss, training accuracy, validation loss, validation accuracy per epoch
|
| 88 |
+
|
| 89 |
+
## Limitations and Biases
|
| 90 |
+
|
| 91 |
+
- **Data Bias**: The models are trained on specific datasets, which may contain inherent biases such as demographic or cultural biases.
|
| 92 |
+
- **Language Support**: Only supports English language text.
|
| 93 |
+
- **Generalization**: Performance may degrade on text significantly different from the training data (e.g., slang, jargon).
|
| 94 |
+
- **Ethical Considerations**: Users should be cautious of potential biases in predictions and should not use the model for critical decisions without human oversight.
|
| 95 |
+
|
| 96 |
+
## License
|
| 97 |
+
|
| 98 |
+
The models are distributed under the same license as the original `bert-base-uncased` model ([Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0)).
|
| 99 |
+
|
| 100 |
+
## Acknowledgements
|
| 101 |
+
|
| 102 |
+
- Thanks to the Hugging Face team for providing the Transformers library and model hosting.
|
| 103 |
+
- The IMDB dataset is made available by [Maas et al.](https://ai.stanford.edu/~amaas/data/sentiment/) under a [Creative Commons Attribution-NonCommercial 3.0 Unported License](https://creativecommons.org/licenses/by-nc/3.0/).
|
| 104 |
+
|
| 105 |
+
---
|
| 106 |
+
|
| 107 |
+
**Disclaimer**: The models are provided "as is" without warranty of any kind. The author is not responsible for any outcomes resulting from the use of these models.
|