Debopam Dey commited on
Commit
7075cd1
·
verified ·
1 Parent(s): 9eadbbc

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +95 -60
README.md CHANGED
@@ -1,118 +1,140 @@
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
- from transformers import BertTokenizer, BertForSequenceClassification
 
 
 
 
39
 
40
  # Load the model and tokenizer from the Hugging Face model hub
41
- mymodel = BertForSequenceClassification.from_pretrained("pritam2014/SentimentBERT")
42
- mytokenizer = BertTokenizer.from_pretrained("pritam2014/SentimentBERT",use_auth_token=True)
43
- ```
44
- ```
45
  def preprocess_text(text):
46
- # Preprocess the input text
47
  inputs = mytokenizer.encode_plus(
48
  text,
49
- max_length=512,
50
  padding='max_length',
51
  truncation=True,
52
  return_attention_mask=True,
53
  return_tensors='pt'
54
  )
55
  return inputs
56
- ```
57
- ```
58
  def make_prediction(text):
59
- # Preprocess the input text
60
  inputs = preprocess_text(text)
61
-
62
- # Make predictions using the loaded model
63
  with torch.no_grad():
64
  outputs = mymodel(inputs['input_ids'], attention_mask=inputs['attention_mask'])
65
  logits = outputs.logits
66
  predicted_class_id = torch.argmax(logits).item()
67
-
68
- # Map the predicted class ID to a sentiment label
69
  sentiment_labels = {0: 'Negative', 1: 'Positive'}
70
- predicted_sentiment = sentiment_labels[predicted_class_id]
71
 
72
- return predicted_sentiment
73
- ```
74
- ```
75
- text = "I love this product"
76
- predicted_sentiment = make_prediction(text)
77
- print(predicted_sentiment)
78
  ```
79
  <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
80
 
81
  ### Direct Use
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82
 
 
 
 
 
 
83
  <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
84
 
85
- [More Information Needed]
86
 
87
  ### Downstream Use [optional]
88
 
89
  <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
90
 
91
- [More Information Needed]
92
 
93
  ### Out-of-Scope Use
94
 
95
  <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
96
 
97
- [More Information Needed]
98
 
99
  ## Bias, Risks, and Limitations
100
 
101
  <!-- This section is meant to convey both technical and sociotechnical limitations. -->
102
 
103
- [More Information Needed]
 
 
104
 
105
  ### Recommendations
106
 
107
  <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
108
 
109
- Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
110
 
111
  ## How to Get Started with the Model
112
 
113
- Use the code below to get started with the model.
114
 
115
- [More Information Needed]
116
 
117
  ## Training Details
118
 
@@ -120,11 +142,16 @@ Use the code below to get started with the model.
120
 
121
  <!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
122
 
123
- [More Information Needed]
124
 
125
  ### Training Procedure
126
 
127
  <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
 
 
 
 
 
128
 
129
  #### Preprocessing [optional]
130
 
@@ -144,6 +171,7 @@ Use the code below to get started with the model.
144
  ## Evaluation
145
 
146
  <!-- This section describes the evaluation protocols and provides the results. -->
 
147
 
148
  ### Testing Data, Factors & Metrics
149
 
@@ -187,7 +215,7 @@ Carbon emissions can be estimated using the [Machine Learning Impact calculator]
187
 
188
  - **Hardware Type:** [More Information Needed]
189
  - **Hours used:** [More Information Needed]
190
- - **Cloud Provider:** [More Information Needed]
191
  - **Compute Region:** [More Information Needed]
192
  - **Carbon Emitted:** [More Information Needed]
193
 
@@ -215,7 +243,14 @@ Carbon emissions can be estimated using the [Machine Learning Impact calculator]
215
 
216
  **BibTeX:**
217
 
218
- [More Information Needed]
 
 
 
 
 
 
 
219
 
220
  **APA:**
221
 
@@ -229,12 +264,12 @@ Carbon emissions can be estimated using the [Machine Learning Impact calculator]
229
 
230
  ## More Information [optional]
231
 
232
- [More Information Needed]
233
 
234
  ## Model Card Authors [optional]
235
 
236
- [More Information Needed]
237
 
238
  ## Model Card Contact
239
 
240
- [More Information Needed]
 
1
+ ---
2
+ library_name: transformers
3
+ tags:
4
+ - sentiment-analysis
5
+ - bert
6
+ - fine-tuned-model
7
+ - NLP
8
+ license: apache-2.0
9
+ language:
10
+ - en
11
+ base_model:
12
+ - google-bert/bert-base-uncased
13
+ datasets:
14
+ - adilbekovich/Sentiment140Twitter
15
+ ---
16
+
17
+ # Model Card for SentimentBERT
18
+
19
+ This model is a fine-tuned version of `bert-base-uncased` for sentiment analysis. It has been trained on the **Sentiment140 Kaggle dataset**, enabling it to classify text as **positive** or **negative**.
20
 
21
  ## Model Details
22
 
23
  ### Model Description
24
 
25
+ This model is fine-tuned using the `bert-base-uncased` architecture to perform sentiment analysis. It accepts text input and predicts whether the sentiment expressed in the text is positive or negative.
 
 
26
 
27
+ - **Developed by:** Debopam(Pritam) Dey
28
+ - **Funded by [optional]:** Not specified
29
+ - **Shared by [optional]:** Debopam(Pritam) Dey
30
+ - **Model type:** Sequence classification (binary sentiment analysis)
31
+ - **Language(s) (NLP):** English
32
+ - **License:** Apache 2.0
33
+ - **Finetuned from model [optional]:** bert-base-uncased
34
 
35
  ### Model Sources [optional]
36
 
37
+ - **Repository:** [SentimentBERT](https://huggingface.co/pritam2014/SentimentBERT)
38
+ - **Demo [optional]:** Coming Soon
 
 
 
39
 
40
  ## Uses
41
+
42
+ Here’s how to use the model for sentiment analysis:
43
+
44
+ ```python
45
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
46
+ import torch
47
 
48
  # Load the model and tokenizer from the Hugging Face model hub
49
+ mymodel = AutoModelForSequenceClassification.from_pretrained("pritam2014/SentimentBERT")
50
+ mytokenizer = AutoTokenizer.from_pretrained("pritam2014/SentimentBERT")
51
+
52
+ # Preprocess the text input
53
  def preprocess_text(text):
 
54
  inputs = mytokenizer.encode_plus(
55
  text,
56
+ max_length=50,
57
  padding='max_length',
58
  truncation=True,
59
  return_attention_mask=True,
60
  return_tensors='pt'
61
  )
62
  return inputs
63
+
64
+ # Predict sentiment
65
  def make_prediction(text):
 
66
  inputs = preprocess_text(text)
 
 
67
  with torch.no_grad():
68
  outputs = mymodel(inputs['input_ids'], attention_mask=inputs['attention_mask'])
69
  logits = outputs.logits
70
  predicted_class_id = torch.argmax(logits).item()
 
 
71
  sentiment_labels = {0: 'Negative', 1: 'Positive'}
72
+ return sentiment_labels[predicted_class_id]
73
 
74
+ # Example
75
+ text = "I love this product!"
76
+ print(make_prediction(text)) # Output: Positive
 
 
 
77
  ```
78
  <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
79
 
80
  ### Direct Use
81
+ The model can be used for text classification tasks without additional fine-tuning.
82
+ ```python
83
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
84
+
85
+ tokenizer = AutoTokenizer.from_pretrained("pritam2014/SentimentBERT")
86
+ model = AutoModelForSequenceClassification.from_pretrained("pritam2014/SentimentBERT")
87
+
88
+ from transformers import pipeline
89
+
90
+ # Initialize pipeline
91
+ sentiment_pipeline = pipeline("sentiment-analysis", model=model, tokenizer=tokenizer)
92
+
93
+ # Example input
94
+ tweets = [
95
+ "I love this product!",
96
+ "I'm not happy with the service.",
97
+ "It's okay, could be better."
98
+ ]
99
 
100
+ # Predict sentiment
101
+ results = sentiment_pipeline(tweets)
102
+ for tweet, result in zip(tweets, results):
103
+ print(f"Tweet: {tweet}\nSentiment: {result['label']}, Score: {result['score']:.4f}\n")
104
+ ```
105
  <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
106
 
 
107
 
108
  ### Downstream Use [optional]
109
 
110
  <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
111
 
112
+ Users can fine-tune the model on other sentiment datasets or adapt it for related tasks like emotion detection.
113
 
114
  ### Out-of-Scope Use
115
 
116
  <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
117
 
118
+ The model is not suitable for multilingual sentiment analysis or highly nuanced text where sentiment depends on complex context.
119
 
120
  ## Bias, Risks, and Limitations
121
 
122
  <!-- This section is meant to convey both technical and sociotechnical limitations. -->
123
 
124
+ - The model may inherit biases present in the Sentiment140 dataset.
125
+ - It is designed for English text and may perform poorly on non-English or mixed-language text.
126
+
127
 
128
  ### Recommendations
129
 
130
  <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
131
 
132
+ Use the model in scenarios where binary sentiment classification is sufficient. Avoid deploying it in critical systems without further testing for biases and limitations.
133
 
134
  ## How to Get Started with the Model
135
 
136
+ Refer to the "Uses" section above to see the sample usage code. For more details, visit the Hugging Face Hub page.
137
 
 
138
 
139
  ## Training Details
140
 
 
142
 
143
  <!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
144
 
145
+ The model was fine-tuned on the Sentiment140 dataset, which contains 1.6 million tweets labelled as positive or negative.
146
 
147
  ### Training Procedure
148
 
149
  <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
150
+ - Optimizer: AdamW
151
+ - Batch size: 760
152
+ - Learning rate: 1e-5
153
+ - Epochs: 2
154
+ - Hardware: Kaggle T4 GPU
155
 
156
  #### Preprocessing [optional]
157
 
 
171
  ## Evaluation
172
 
173
  <!-- This section describes the evaluation protocols and provides the results. -->
174
+ The model was evaluated on a validation split of the Sentiment140 dataset.
175
 
176
  ### Testing Data, Factors & Metrics
177
 
 
215
 
216
  - **Hardware Type:** [More Information Needed]
217
  - **Hours used:** [More Information Needed]
218
+ - **Cloud Provider:** Kaggle T4 GPU
219
  - **Compute Region:** [More Information Needed]
220
  - **Carbon Emitted:** [More Information Needed]
221
 
 
243
 
244
  **BibTeX:**
245
 
246
+ @misc{pritam2014SentimentBERT,
247
+ author = {Debopam(Pritam) Dey},
248
+ title = {SentimentBERT},
249
+ year = {2025},
250
+ publisher = {Hugging Face},
251
+ howpublished = {\url{https://huggingface.co/pritam2014/SentimentBERT}},
252
+ }
253
+
254
 
255
  **APA:**
256
 
 
264
 
265
  ## More Information [optional]
266
 
267
+ The model performs well on short texts like tweets but may require further fine-tuning for longer or domain-specific text.
268
 
269
  ## Model Card Authors [optional]
270
 
271
+ [More Information Needed]
272
 
273
  ## Model Card Contact
274
 
275
+ For questions or feedback, feel free to contact me via the Hugging Face repository or email at ([email protected])