Update README.md
Browse files
README.md
CHANGED
@@ -15,185 +15,125 @@ pipeline_tag: feature-extraction
|
|
15 |
|
16 |
# Model Card for Model ID
|
17 |
|
18 |
-
|
19 |
-
|
20 |
|
21 |
|
22 |
## Model Details
|
23 |
|
24 |
-
|
25 |
-
|
26 |
-
<!-- Provide a longer summary of what this model is. -->
|
27 |
-
|
28 |
-
This is the model card of a 🤗 transformers model that has been pushed on the Hub. This model card has been automatically generated.
|
29 |
-
|
30 |
-
- **Developed by:** [Abdallah Ashraf]
|
31 |
-
- **Model type:** [More Information Needed]
|
32 |
- **Language(s) (NLP):** [English]
|
33 |
-
- **Finetuned from model
|
34 |
-
|
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 |
-
|
43 |
|
44 |
-
[More Information Needed]
|
45 |
|
46 |
### Downstream Use [optional]
|
47 |
|
48 |
-
|
49 |
|
50 |
-
[More Information Needed]
|
51 |
|
52 |
### Out-of-Scope Use
|
53 |
|
54 |
-
|
55 |
|
56 |
-
[More Information Needed]
|
57 |
|
58 |
## Bias, Risks, and Limitations
|
59 |
|
60 |
-
|
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 |
## Training Details
|
77 |
|
78 |
-
### Training Data
|
79 |
-
|
80 |
-
<!-- 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. -->
|
81 |
-
|
82 |
-
[More Information Needed]
|
83 |
-
|
84 |
### Training Procedure
|
85 |
|
86 |
<!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
|
87 |
-
|
88 |
-
#### Preprocessing [optional]
|
89 |
-
|
90 |
-
[More Information Needed]
|
91 |
-
|
92 |
|
93 |
#### Training Hyperparameters
|
94 |
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
|
|
|
|
100 |
|
101 |
-
[More Information Needed]
|
102 |
|
103 |
## Evaluation
|
104 |
|
105 |
-
<!-- This section describes the evaluation protocols and provides the results. -->
|
106 |
-
|
107 |
### Testing Data, Factors & Metrics
|
108 |
|
109 |
#### Testing Data
|
110 |
|
111 |
-
|
112 |
-
|
113 |
-
[More Information Needed]
|
114 |
-
|
115 |
-
#### Factors
|
116 |
-
|
117 |
-
<!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
|
118 |
-
|
119 |
-
[More Information Needed]
|
120 |
|
121 |
#### Metrics
|
122 |
|
123 |
-
|
124 |
-
|
125 |
-
[More Information Needed]
|
126 |
|
127 |
### Results
|
128 |
|
129 |
-
|
130 |
-
|
131 |
-
#### Summary
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
## Model Examination [optional]
|
136 |
-
|
137 |
-
<!-- Relevant interpretability work for the model goes here -->
|
138 |
-
|
139 |
-
[More Information Needed]
|
140 |
-
|
141 |
-
## Environmental Impact
|
142 |
-
|
143 |
-
<!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
|
144 |
-
|
145 |
-
Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
|
146 |
-
|
147 |
-
- **Hardware Type:** [More Information Needed]
|
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 |
-
## Technical Specifications [optional]
|
154 |
-
|
155 |
-
### Model Architecture and Objective
|
156 |
-
|
157 |
-
[More Information Needed]
|
158 |
-
|
159 |
-
### Compute Infrastructure
|
160 |
-
|
161 |
-
[More Information Needed]
|
162 |
-
|
163 |
-
#### Hardware
|
164 |
-
|
165 |
-
[More Information Needed]
|
166 |
-
|
167 |
-
#### Software
|
168 |
-
|
169 |
-
[More Information Needed]
|
170 |
-
|
171 |
-
## Citation [optional]
|
172 |
-
|
173 |
-
<!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
|
174 |
-
|
175 |
-
**BibTeX:**
|
176 |
-
|
177 |
-
[More Information Needed]
|
178 |
-
|
179 |
-
**APA:**
|
180 |
-
|
181 |
-
[More Information Needed]
|
182 |
-
|
183 |
-
## Glossary [optional]
|
184 |
-
|
185 |
-
<!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
|
186 |
-
|
187 |
-
[More Information Needed]
|
188 |
-
|
189 |
-
## More Information [optional]
|
190 |
-
|
191 |
-
[More Information Needed]
|
192 |
-
|
193 |
-
## Model Card Authors [optional]
|
194 |
-
|
195 |
-
[More Information Needed]
|
196 |
-
|
197 |
-
## Model Card Contact
|
198 |
-
|
199 |
-
[More Information Needed]
|
|
|
15 |
|
16 |
# Model Card for Model ID
|
17 |
|
18 |
+
This is an idiomatic expression classifier based on the BERT model from Hugging Face's Transformers library.
|
19 |
+
The model is trained to classify sentences containing idiomatic expressions as either figurative or literal.
|
20 |
|
21 |
|
22 |
## Model Details
|
23 |
|
24 |
+
- **Developed by:** Abdallah Ashraf
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
- **Language(s) (NLP):** [English]
|
26 |
+
- **Finetuned from model:** bert-base-uncased
|
|
|
27 |
|
28 |
## Uses
|
29 |
|
|
|
|
|
30 |
### Direct Use
|
31 |
|
32 |
+
The model can be used directly for classifying idiomatic expressions in text data.
|
33 |
|
|
|
34 |
|
35 |
### Downstream Use [optional]
|
36 |
|
37 |
+
The model can also be fine-tuned for specific downstream tasks, such as sentiment analysis or natural language understanding, by incorporating it into larger NLP pipelines.
|
38 |
|
|
|
39 |
|
40 |
### Out-of-Scope Use
|
41 |
|
42 |
+
The model may not perform well on non-idiomatic text or text in languages other than English.
|
43 |
|
|
|
44 |
|
45 |
## Bias, Risks, and Limitations
|
46 |
|
47 |
+
The model's performance may be influenced by biases present in the training data, such as cultural or linguistic biases. Additionally, the model's accuracy may vary depending on the complexity and context of the idiomatic expressions.
|
|
|
|
|
|
|
|
|
48 |
|
|
|
|
|
|
|
49 |
|
50 |
## How to Get Started with the Model
|
51 |
|
52 |
+
To use the model, instantiate the `IdiomClassifier` class and load the pre-trained weights. Then, tokenize the input text using the BERT tokenizer and pass it through the model for classification.
|
53 |
+
|
54 |
+
```python
|
55 |
+
from transformers import BertModel, BertTokenizer
|
56 |
+
import torch.nn as nn
|
57 |
+
|
58 |
+
# Load the BERT model and tokenizer
|
59 |
+
bert_model = BertModel.from_pretrained('abdallahashrafx/Bert_idiom_classifier')
|
60 |
+
tokenizer = BertTokenizer.from_pretrained('abdallahashrafx/Bert_idiom_classifier')
|
61 |
+
|
62 |
+
# Define the IdiomClassifier class
|
63 |
+
class IdiomClassifier(nn.Module):
|
64 |
+
def __init__(self):
|
65 |
+
super(IdiomClassifier, self).__init__()
|
66 |
+
self.bert = bert_model
|
67 |
+
self.drop = nn.Dropout(p=0.4)
|
68 |
+
self.out = nn.Linear(self.bert.config.hidden_size, 1)
|
69 |
+
|
70 |
+
def forward(self, input_ids, attention_mask):
|
71 |
+
_, pooled_output = self.bert(input_ids=input_ids, attention_mask=attention_mask)
|
72 |
+
output = self.drop(pooled_output)
|
73 |
+
return self.out(output)
|
74 |
+
|
75 |
+
# Instantiate the model and move it to the GPU
|
76 |
+
model = IdiomClassifier().to(device)
|
77 |
+
```
|
78 |
+
## How to run inference (predict on raw text)
|
79 |
+
|
80 |
+
```python
|
81 |
+
sentence = "A little bird told me it was your birthday, he said."
|
82 |
+
|
83 |
+
# Tokenize and encode the sentence
|
84 |
+
encoded_sentence = tokenizer.encode_plus(
|
85 |
+
sentence,
|
86 |
+
max_length=MAX_LEN,
|
87 |
+
add_special_tokens=True,
|
88 |
+
return_token_type_ids=False,
|
89 |
+
pad_to_max_length=True,
|
90 |
+
return_attention_mask=True,
|
91 |
+
return_tensors='pt',
|
92 |
+
)
|
93 |
+
|
94 |
+
input_ids = encoded_sentence['input_ids'].to(device)
|
95 |
+
attention_mask = encoded_sentence['attention_mask'].to(device)
|
96 |
+
|
97 |
+
output = model(input_ids, attention_mask)
|
98 |
+
# Apply sigmoid to convert logits to probabilities
|
99 |
+
probs = torch.sigmoid(output)
|
100 |
+
|
101 |
+
# Round probabilities to get predictions
|
102 |
+
prediction = (probs > 0.5).int()
|
103 |
+
|
104 |
+
print(f'sentence: {sentence}')
|
105 |
+
print(f'class : {class_names[prediction]}')
|
106 |
+
```
|
107 |
## Training Details
|
108 |
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
### Training Procedure
|
110 |
|
111 |
<!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
|
112 |
+
The model was trained using the AdamW optimizer with a learning rate of 2e-6 and weight decay of 0.01. A linear scheduler with no warmup was used to adjust the learning rate during training.
|
|
|
|
|
|
|
|
|
113 |
|
114 |
#### Training Hyperparameters
|
115 |
|
116 |
+
Training Hyperparameters
|
117 |
+
Training regime: Full fine-tuning
|
118 |
+
Optimizer: AdamW
|
119 |
+
Learning rate: 2e-6
|
120 |
+
momentum: 90-95
|
121 |
+
Weight decay: 0.01
|
122 |
+
loss function : Binary cross entropy loss
|
123 |
|
|
|
124 |
|
125 |
## Evaluation
|
126 |
|
|
|
|
|
127 |
### Testing Data, Factors & Metrics
|
128 |
|
129 |
#### Testing Data
|
130 |
|
131 |
+
The model was evaluated on a separate test dataset containing sentences with idiomatic expressions and their ground truth classifications.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
132 |
|
133 |
#### Metrics
|
134 |
|
135 |
+
The evaluation metrics used to assess the model's performance include accuracy, precision, recall, and F1-score for both figurative and literal classifications.
|
|
|
|
|
136 |
|
137 |
### Results
|
138 |
|
139 |
+
The model achieved an overall accuracy of 90% on the test dataset, with balanced precision, recall, and F1-score for both figurative and literal classifications.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|