first commit
Browse files- README.md +78 -0
- config.json +39 -0
- convert_flax_to_pytorch.py +3 -0
- convert_pytorch_to_flax.py +3 -0
- convert_pytorch_to_tensorflow.py +3 -0
- flax_model.msgpack +3 -0
- pytorch_model.bin +3 -0
- special_tokens_map.json +1 -0
- tf_model.h5 +3 -0
- tokenizer_config.json +1 -0
- vocab.txt +0 -0
README.md
ADDED
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
language:
|
3 |
+
- en
|
4 |
+
thumbnail: https://avatars3.githubusercontent.com/u/32437151?s=460&u=4ec59abc8d21d5feea3dab323d23a5860e6996a4&v=4
|
5 |
+
tags:
|
6 |
+
- text-classification
|
7 |
+
- emotion
|
8 |
+
- pytorch
|
9 |
+
license: apache-2.0
|
10 |
+
datasets:
|
11 |
+
- emotion
|
12 |
+
metrics:
|
13 |
+
- Accuracy, F1 Score
|
14 |
+
---
|
15 |
+
# Distilbert-base-uncased-emotion
|
16 |
+
|
17 |
+
## Model description:
|
18 |
+
[Distilbert](https://arxiv.org/abs/1910.01108) is created with knowledge distillation during the pre-training phase which reduces the size of a BERT model by 40%, while retaining 97% of its language understanding. It's smaller, faster than Bert and any other Bert-based model.
|
19 |
+
|
20 |
+
[Distilbert-base-uncased](https://huggingface.co/distilbert-base-uncased) finetuned on the emotion dataset using HuggingFace Trainer with below Hyperparameters
|
21 |
+
```
|
22 |
+
learning rate 2e-5,
|
23 |
+
batch size 64,
|
24 |
+
num_train_epochs=8,
|
25 |
+
```
|
26 |
+
|
27 |
+
## Model Performance Comparision on Emotion Dataset from Twitter:
|
28 |
+
|
29 |
+
| Model | Accuracy | F1 Score | Test Sample per Second |
|
30 |
+
| --- | --- | --- | --- |
|
31 |
+
| [Distilbert-base-uncased-emotion](https://huggingface.co/bhadresh-savani/distilbert-base-uncased-emotion) | 93.8 | 93.79 | 398.69 |
|
32 |
+
| [Bert-base-uncased-emotion](https://huggingface.co/bhadresh-savani/bert-base-uncased-emotion) | 94.05 | 94.06 | 190.152 |
|
33 |
+
| [Roberta-base-emotion](https://huggingface.co/bhadresh-savani/roberta-base-emotion) | 93.95 | 93.97| 195.639 |
|
34 |
+
| [Albert-base-v2-emotion](https://huggingface.co/bhadresh-savani/albert-base-v2-emotion) | 93.6 | 93.65 | 182.794 |
|
35 |
+
|
36 |
+
## How to Use the model:
|
37 |
+
```python
|
38 |
+
from transformers import pipeline
|
39 |
+
classifier = pipeline("text-classification",model='bhadresh-savani/distilbert-base-uncased-emotion', return_all_scores=True)
|
40 |
+
prediction = classifier("I love using transformers. The best part is wide range of support and its easy to use", )
|
41 |
+
print(prediction)
|
42 |
+
|
43 |
+
"""
|
44 |
+
Output:
|
45 |
+
[[
|
46 |
+
{'label': 'sadness', 'score': 0.0006792712374590337},
|
47 |
+
{'label': 'joy', 'score': 0.9959300756454468},
|
48 |
+
{'label': 'love', 'score': 0.0009452480007894337},
|
49 |
+
{'label': 'anger', 'score': 0.0018055217806249857},
|
50 |
+
{'label': 'fear', 'score': 0.00041110432357527316},
|
51 |
+
{'label': 'surprise', 'score': 0.0002288572577526793}
|
52 |
+
]]
|
53 |
+
"""
|
54 |
+
```
|
55 |
+
|
56 |
+
## Dataset:
|
57 |
+
[Twitter-Sentiment-Analysis](https://huggingface.co/nlp/viewer/?dataset=emotion).
|
58 |
+
|
59 |
+
## Training procedure
|
60 |
+
[Colab Notebook](https://github.com/bhadreshpsavani/ExploringSentimentalAnalysis/blob/main/SentimentalAnalysisWithDistilbert.ipynb)
|
61 |
+
|
62 |
+
## Eval results
|
63 |
+
```json
|
64 |
+
{
|
65 |
+
'test_accuracy': 0.938,
|
66 |
+
'test_f1': 0.937932884041714,
|
67 |
+
'test_loss': 0.1472451239824295,
|
68 |
+
'test_mem_cpu_alloc_delta': 0,
|
69 |
+
'test_mem_cpu_peaked_delta': 0,
|
70 |
+
'test_mem_gpu_alloc_delta': 0,
|
71 |
+
'test_mem_gpu_peaked_delta': 163454464,
|
72 |
+
'test_runtime': 5.0164,
|
73 |
+
'test_samples_per_second': 398.69
|
74 |
+
}
|
75 |
+
```
|
76 |
+
|
77 |
+
## Reference:
|
78 |
+
* [Natural Language Processing with Transformer By Lewis Tunstall, Leandro von Werra, Thomas Wolf](https://learning.oreilly.com/library/view/natural-language-processing/9781098103231/)
|
config.json
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_name_or_path": "./",
|
3 |
+
"activation": "gelu",
|
4 |
+
"architectures": [
|
5 |
+
"DistilBertForSequenceClassification"
|
6 |
+
],
|
7 |
+
"attention_dropout": 0.1,
|
8 |
+
"dim": 768,
|
9 |
+
"dropout": 0.1,
|
10 |
+
"hidden_dim": 3072,
|
11 |
+
"id2label": {
|
12 |
+
"0": "sadness",
|
13 |
+
"1": "joy",
|
14 |
+
"2": "love",
|
15 |
+
"3": "anger",
|
16 |
+
"4": "fear",
|
17 |
+
"5": "surprise"
|
18 |
+
},
|
19 |
+
"initializer_range": 0.02,
|
20 |
+
"label2id": {
|
21 |
+
"anger": 3,
|
22 |
+
"fear": 4,
|
23 |
+
"joy": 1,
|
24 |
+
"love": 2,
|
25 |
+
"sadness": 0,
|
26 |
+
"surprise": 5
|
27 |
+
},
|
28 |
+
"max_position_embeddings": 512,
|
29 |
+
"model_type": "distilbert",
|
30 |
+
"n_heads": 12,
|
31 |
+
"n_layers": 6,
|
32 |
+
"pad_token_id": 0,
|
33 |
+
"qa_dropout": 0.1,
|
34 |
+
"seq_classif_dropout": 0.2,
|
35 |
+
"sinusoidal_pos_embds": false,
|
36 |
+
"tie_weights_": true,
|
37 |
+
"transformers_version": "4.11.0.dev0",
|
38 |
+
"vocab_size": 30522
|
39 |
+
}
|
convert_flax_to_pytorch.py
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import AutoModelForSequenceClassification
|
2 |
+
model = AutoModelForSequenceClassification.from_pretrained("./", from_flax=True)
|
3 |
+
model.save_pretrained("./")
|
convert_pytorch_to_flax.py
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import FlaxAutoModelForSequenceClassification
|
2 |
+
model = FlaxAutoModelForSequenceClassification.from_pretrained("./", from_pt=True)
|
3 |
+
model.save_pretrained("./")
|
convert_pytorch_to_tensorflow.py
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import TFAutoModelForSequenceClassification
|
2 |
+
model = TFAutoModelForSequenceClassification.from_pretrained("./", from_pt=True)
|
3 |
+
model.save_pretrained("./")
|
flax_model.msgpack
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:d925341280e22bf3041ac1cd44bc7e00b7ca267add097a8ffe14238b9e067826
|
3 |
+
size 267836005
|
pytorch_model.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:5aa7398d830fcc94f95af88d7cc3013813668cfc58a07d75a8116cfd8af75c4d
|
3 |
+
size 267875479
|
special_tokens_map.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"unk_token": "[UNK]", "sep_token": "[SEP]", "pad_token": "[PAD]", "cls_token": "[CLS]", "mask_token": "[MASK]"}
|
tf_model.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:abd2741ba3b64886080d795f4b58771f4a1597b8ea8ae2b6cad9ef2e2357a0c3
|
3 |
+
size 267964184
|
tokenizer_config.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"do_lower_case": true, "unk_token": "[UNK]", "sep_token": "[SEP]", "pad_token": "[PAD]", "cls_token": "[CLS]", "mask_token": "[MASK]", "tokenize_chinese_chars": true, "strip_accents": null, "model_max_length": 512, "special_tokens_map_file": null, "name_or_path": "distilbert-base-uncased"}
|
vocab.txt
ADDED
The diff for this file is too large to render.
See raw diff
|
|