Added updated README.md to the model repository
Browse files
README.md
CHANGED
@@ -1,199 +1,205 @@
|
|
1 |
-
---
|
2 |
-
library_name: transformers
|
3 |
-
tags: []
|
4 |
-
---
|
5 |
-
|
6 |
-
# Model Card for Model ID
|
7 |
-
|
8 |
-
<!-- Provide a quick summary of what the model is/does. -->
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
## Model Details
|
13 |
-
|
14 |
-
### Model Description
|
15 |
-
|
16 |
-
<!-- Provide a longer summary of what this model is. -->
|
17 |
-
|
18 |
-
This is the model card of a 🤗 transformers model that has been pushed on the Hub. This model card has been automatically generated.
|
19 |
-
|
20 |
-
- **Developed by:** [More Information Needed]
|
21 |
-
- **Funded by [optional]:** [More Information Needed]
|
22 |
-
- **Shared by [optional]:** [More Information Needed]
|
23 |
-
- **Model type:** [More Information Needed]
|
24 |
-
- **Language(s) (NLP):** [More Information Needed]
|
25 |
-
- **License:** [More Information Needed]
|
26 |
-
- **Finetuned from model [optional]:** [More Information Needed]
|
27 |
-
|
28 |
-
### Model Sources [optional]
|
29 |
-
|
30 |
-
<!-- Provide the basic links for the model. -->
|
31 |
-
|
32 |
-
- **Repository:** [More Information Needed]
|
33 |
-
- **Paper [optional]:** [More Information Needed]
|
34 |
-
- **Demo [optional]:** [More Information Needed]
|
35 |
-
|
36 |
-
## Uses
|
37 |
-
|
38 |
-
<!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
|
39 |
-
|
40 |
-
### Direct Use
|
41 |
-
|
42 |
-
<!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
|
43 |
-
|
44 |
-
[More Information Needed]
|
45 |
-
|
46 |
-
### Downstream Use [optional]
|
47 |
-
|
48 |
-
<!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
|
49 |
|
50 |
-
|
51 |
|
52 |
-
|
53 |
|
54 |
-
|
55 |
-
|
56 |
-
[More Information Needed]
|
57 |
-
|
58 |
-
## Bias, Risks, and Limitations
|
59 |
-
|
60 |
-
<!-- This section is meant to convey both technical and sociotechnical limitations. -->
|
61 |
-
|
62 |
-
[More Information Needed]
|
63 |
-
|
64 |
-
### Recommendations
|
65 |
-
|
66 |
-
<!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
|
67 |
-
|
68 |
-
Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
|
69 |
-
|
70 |
-
## How to Get Started with the Model
|
71 |
|
72 |
-
|
73 |
|
74 |
-
|
75 |
|
76 |
-
|
|
|
|
|
|
|
77 |
|
78 |
-
|
79 |
|
80 |
-
|
81 |
|
82 |
-
|
83 |
|
84 |
-
|
|
|
85 |
|
86 |
-
|
87 |
|
88 |
-
|
89 |
|
90 |
-
|
|
|
|
|
|
|
91 |
|
|
|
92 |
|
93 |
-
|
|
|
|
|
94 |
|
95 |
-
|
96 |
|
97 |
-
|
98 |
|
99 |
-
|
100 |
|
101 |
-
|
|
|
|
|
|
|
|
|
|
|
102 |
|
103 |
-
|
104 |
|
105 |
-
|
|
|
|
|
|
|
|
|
106 |
|
107 |
-
|
108 |
|
109 |
-
|
110 |
|
111 |
-
|
112 |
|
113 |
-
|
|
|
|
|
|
|
114 |
|
115 |
-
|
116 |
|
117 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
118 |
|
119 |
-
|
120 |
|
121 |
-
|
122 |
|
123 |
-
|
124 |
|
125 |
-
|
126 |
|
127 |
-
|
|
|
128 |
|
129 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
130 |
|
131 |
-
|
|
|
|
|
|
|
|
|
132 |
|
|
|
|
|
|
|
133 |
|
|
|
134 |
|
135 |
-
##
|
136 |
|
137 |
-
|
138 |
|
139 |
-
|
|
|
|
|
140 |
|
141 |
-
|
|
|
|
|
142 |
|
143 |
-
|
|
|
|
|
144 |
|
145 |
-
|
|
|
|
|
146 |
|
147 |
-
|
148 |
-
- **Hours used:** [More Information Needed]
|
149 |
-
- **Cloud Provider:** [More Information Needed]
|
150 |
-
- **Compute Region:** [More Information Needed]
|
151 |
-
- **Carbon Emitted:** [More Information Needed]
|
152 |
|
153 |
-
##
|
154 |
|
155 |
-
|
156 |
|
157 |
-
|
|
|
|
|
|
|
158 |
|
159 |
-
|
160 |
|
161 |
-
|
162 |
|
163 |
-
|
164 |
|
165 |
-
|
166 |
|
167 |
-
|
|
|
|
|
168 |
|
169 |
-
|
170 |
|
171 |
-
##
|
172 |
|
173 |
-
|
174 |
|
175 |
-
|
|
|
176 |
|
177 |
-
|
|
|
|
|
|
|
178 |
|
179 |
-
|
|
|
|
|
|
|
|
|
|
|
180 |
|
181 |
-
|
182 |
|
183 |
-
##
|
184 |
|
185 |
-
|
186 |
|
187 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
188 |
|
189 |
-
|
190 |
|
191 |
-
|
192 |
|
193 |
-
|
194 |
|
195 |
-
|
196 |
|
197 |
-
##
|
198 |
|
199 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
|
2 |
+
# FLAN-T5 Sentiment Analysis Model
|
3 |
|
4 |
+
This is a fine-tuned version of the **FLAN-T5** model for sentiment analysis on healthcare-related reviews and general text classification. The model is trained on a combination of two sentiment-labeled datasets, utilizing custom weighting to address class imbalance. The model can classify text into three sentiment categories: **Positive**, **Neutral**, and **Negative**.
|
5 |
|
6 |
+
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
+
## Model Description
|
9 |
|
10 |
+
The model is based on **T5 (Text-To-Text Transfer Transformer)**, a versatile transformer architecture that performs various NLP tasks by casting them into a text-to-text framework. In this case, the model has been fine-tuned for **sentiment classification** using a custom dataset.
|
11 |
|
12 |
+
**Model Type:**
|
13 |
+
- **Transformer**
|
14 |
+
- **Text-to-Text Model**
|
15 |
+
- **Pre-trained Base:** Google FLAN-T5 (flan-t5-base)
|
16 |
|
17 |
+
---
|
18 |
|
19 |
+
## Training Data
|
20 |
|
21 |
+
### Datasets Used
|
22 |
|
23 |
+
- **Dataset 1**: Balanced Sentiment Dataset
|
24 |
+
- **Dataset 2**: Final Dataset with New Negative Sentiments
|
25 |
|
26 |
+
Both datasets contain labeled sentiment data, where the target labels are `negative`, `neutral`, and `positive`.
|
27 |
|
28 |
+
### Text Normalization
|
29 |
|
30 |
+
Text data has been preprocessed by:
|
31 |
+
1. Converting all text to lowercase.
|
32 |
+
2. Removing URLs, special characters, and excessive whitespaces.
|
33 |
+
3. Handling missing data by filling with an empty string.
|
34 |
|
35 |
+
### Sample Weighting
|
36 |
|
37 |
+
We applied **sample weighting** to address class imbalances:
|
38 |
+
- Samples from **Dataset 1** are assigned a weight of 1.
|
39 |
+
- Samples from **Dataset 2** are assigned a higher weight of 3 to account for their greater importance.
|
40 |
|
41 |
+
---
|
42 |
|
43 |
+
## Evaluation Results
|
44 |
|
45 |
+
The model has been evaluated on a separate test set, and the following metrics were achieved:
|
46 |
|
47 |
+
| Metric | Score |
|
48 |
+
|-----------------|---------|
|
49 |
+
| **Accuracy** | 99.01% |
|
50 |
+
| **Precision** | 99.02% |
|
51 |
+
| **Recall** | 99.01% |
|
52 |
+
| **F1-Score** | 98.89% |
|
53 |
|
54 |
+
### Class-Wise Performance
|
55 |
|
56 |
+
| Class | Precision | Recall | F1-Score | Support |
|
57 |
+
|-----------|-----------|--------|----------|---------|
|
58 |
+
| **Negative** | 1.0000 | 1.0000 | 1.0000 | 4 |
|
59 |
+
| **Neutral** | 0.9899 | 1.0000 | 0.9949 | 1575 |
|
60 |
+
| **Positive** | 1.0000 | 0.9897 | 0.9419 | 39 |
|
61 |
|
62 |
+
---
|
63 |
|
64 |
+
## Model Training
|
65 |
|
66 |
+
### Model Architecture
|
67 |
|
68 |
+
- **Base Model**: `google/flan-t5-base`
|
69 |
+
- **Tokenization**: Using the `T5Tokenizer` to tokenize the input text before feeding it to the model.
|
70 |
+
- **Loss Function**: CrossEntropyLoss (with weights applied for class imbalance).
|
71 |
+
- **Optimization**: Adam optimizer with a learning rate of `3e-5`.
|
72 |
|
73 |
+
### Hyperparameters
|
74 |
|
75 |
+
- **Batch Size**: 8
|
76 |
+
- **Learning Rate**: `3e-5`
|
77 |
+
- **Number of Epochs**: 3
|
78 |
+
- **Warmup Steps**: 500
|
79 |
+
- **Weight Decay**: 0.01
|
80 |
+
- **FP16**: Yes (for faster computation)
|
81 |
+
- **Save Strategy**: Save the model after each epoch.
|
82 |
|
83 |
+
---
|
84 |
|
85 |
+
## Model Usage
|
86 |
|
87 |
+
The fine-tuned model can be used for text classification tasks such as **sentiment analysis** on reviews or general text. Below is an example of how to use the model for inference.
|
88 |
|
89 |
+
### Inference Example
|
90 |
|
91 |
+
```python
|
92 |
+
from transformers import pipeline
|
93 |
|
94 |
+
# Load the fine-tuned model
|
95 |
+
model_name = "ShahzaibAli-1/sentiment_model_2_flant_5_base"
|
96 |
+
classifier = pipeline(
|
97 |
+
"text2text-generation",
|
98 |
+
model=model_name,
|
99 |
+
device=0 if torch.cuda.is_available() else -1
|
100 |
+
)
|
101 |
|
102 |
+
# Test the model with some sample text
|
103 |
+
def test_prompt(prompt):
|
104 |
+
response = classifier(prompt, max_new_tokens=10, temperature=0.1, do_sample=False)
|
105 |
+
print(f"Prompt: {prompt}
|
106 |
+
Output: {response[0]['generated_text'].strip()}")
|
107 |
|
108 |
+
# Test with a sample sentiment classification
|
109 |
+
test_prompt("classify sentiment: The physical therapy sessions completely relieved my chronic back pain")
|
110 |
+
```
|
111 |
|
112 |
+
---
|
113 |
|
114 |
+
## Example Outputs
|
115 |
|
116 |
+
Here are some example outputs for various test cases:
|
117 |
|
118 |
+
- **Healthcare Review**:
|
119 |
+
Prompt: `"The physical therapy sessions completely relieved my chronic back pain"`
|
120 |
+
Output: `positive`
|
121 |
|
122 |
+
- **Mixed Review**:
|
123 |
+
Prompt: `"The facility was excellent but the doctor was always late"`
|
124 |
+
Output: `negative`
|
125 |
|
126 |
+
- **Ambiguous Review**:
|
127 |
+
Prompt: `"The treatment was... interesting"`
|
128 |
+
Output: `positive`
|
129 |
|
130 |
+
- **Promotional Text**:
|
131 |
+
Prompt: `"Experience pain-free living with our new therapy techniques!"`
|
132 |
+
Output: `neutral`
|
133 |
|
134 |
+
---
|
|
|
|
|
|
|
|
|
135 |
|
136 |
+
## Evaluation Metrics
|
137 |
|
138 |
+
The following evaluation metrics were used to assess the model's performance:
|
139 |
|
140 |
+
- **Accuracy**: The percentage of correct predictions over the total number of predictions.
|
141 |
+
- **Precision**: The proportion of positive predictions that were actually correct.
|
142 |
+
- **Recall**: The proportion of actual positives that were correctly identified.
|
143 |
+
- **F1-Score**: The harmonic mean of precision and recall.
|
144 |
|
145 |
+
The model demonstrated strong performance across all metrics, particularly with accuracy close to 99%.
|
146 |
|
147 |
+
---
|
148 |
|
149 |
+
## Limitations
|
150 |
|
151 |
+
While the model performs well on the test set, there are some limitations:
|
152 |
|
153 |
+
- **Sarcasm Detection**: The model struggles with detecting sarcasm in text, as shown in some test cases where sarcastic reviews were classified as neutral.
|
154 |
+
- **Multilingual Support**: The model primarily works with English text and might not perform well on multilingual inputs.
|
155 |
+
- **Contextual Nuances**: Some complex or ambiguous cases (e.g., mixed sentiment reviews) might require further refinement in training.
|
156 |
|
157 |
+
---
|
158 |
|
159 |
+
## Model Deployment
|
160 |
|
161 |
+
Once the model was trained, it was pushed to the Hugging Face model hub for easy access. You can use the model with the following command:
|
162 |
|
163 |
+
```python
|
164 |
+
from transformers import T5ForConditionalGeneration, T5Tokenizer
|
165 |
|
166 |
+
# Load the model and tokenizer from the Hugging Face Hub
|
167 |
+
model_name = "ShahzaibAli-1/sentiment_model_2_flant_5_base"
|
168 |
+
model = T5ForConditionalGeneration.from_pretrained(model_name)
|
169 |
+
tokenizer = T5Tokenizer.from_pretrained(model_name)
|
170 |
|
171 |
+
# Use the model to classify sentiment
|
172 |
+
inputs = tokenizer("classify sentiment: The therapist was excellent!", return_tensors="pt")
|
173 |
+
outputs = model.generate(**inputs)
|
174 |
+
predicted_sentiment = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
175 |
+
print(f"Predicted Sentiment: {predicted_sentiment}")
|
176 |
+
```
|
177 |
|
178 |
+
---
|
179 |
|
180 |
+
## Citation
|
181 |
|
182 |
+
If you use this model in your research or projects, please cite it as follows:
|
183 |
|
184 |
+
```
|
185 |
+
@article{shahzaib2025sentiment,
|
186 |
+
title={Fine-Tuning FLAN-T5 for Sentiment Analysis},
|
187 |
+
author={Shahzaib Ali},
|
188 |
+
journal={Hugging Face Model Hub},
|
189 |
+
year={2025},
|
190 |
+
url={https://huggingface.co/ShahzaibAli-1/sentiment_model_2_flant_5_base}
|
191 |
+
}
|
192 |
+
```
|
193 |
|
194 |
+
---
|
195 |
|
196 |
+
## License
|
197 |
|
198 |
+
The model is released under the [MIT License](https://opensource.org/licenses/MIT). Feel free to use it in your applications and research.
|
199 |
|
200 |
+
---
|
201 |
|
202 |
+
## Contact
|
203 |
|
204 |
+
For any questions or suggestions, feel free to open an issue or contact the model creator at:
|
205 |
+
- **Hugging Face**: [ShahzaibAli-1](https://huggingface.co/ShahzaibAli-1)
|