julien-c HF staff commited on
Commit
c425864
1 Parent(s): 65b76a9

Migrate model card from transformers-repo

Browse files

Read announcement at https://discuss.huggingface.co/t/announcement-all-model-cards-will-be-migrated-to-hf-co-model-repos/2755
Original file history: https://github.com/huggingface/transformers/commits/master/model_cards/mrm8488/t5-base-finetuned-sarcasm-twitter/README.md

Files changed (1) hide show
  1. README.md +112 -0
README.md ADDED
@@ -0,0 +1,112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language: en
3
+ ---
4
+
5
+ # T5-base fine-tuned for Sarcasm Detection 🙄
6
+ [Google's T5](https://ai.googleblog.com/2020/02/exploring-transfer-learning-with-t5.html) base fine-tuned on [ Twitter Sarcasm Dataset](https://github.com/EducationalTestingService/sarcasm) for **Sequence classification (as text generation)** downstream task.
7
+
8
+ ## Details of T5
9
+
10
+ The **T5** model was presented in [Exploring the Limits of Transfer Learning with a Unified Text-to-Text Transformer](https://arxiv.org/pdf/1910.10683.pdf) by *Colin Raffel, Noam Shazeer, Adam Roberts, Katherine Lee, Sharan Narang, Michael Matena, Yanqi Zhou, Wei Li, Peter J. Liu* in Here the abstract:
11
+
12
+ Transfer learning, where a model is first pre-trained on a data-rich task before being fine-tuned on a downstream task, has emerged as a powerful technique in natural language processing (NLP). The effectiveness of transfer learning has given rise to a diversity of approaches, methodology, and practice. In this paper, we explore the landscape of transfer learning techniques for NLP by introducing a unified framework that converts every language problem into a text-to-text format. Our systematic study compares pre-training objectives, architectures, unlabeled datasets, transfer approaches, and other factors on dozens of language understanding tasks. By combining the insights from our exploration with scale and our new “Colossal Clean Crawled Corpus”, we achieve state-of-the-art results on many benchmarks covering summarization, question answering, text classification, and more. To facilitate future work on transfer learning for NLP, we release our dataset, pre-trained models, and code.
13
+
14
+ ![model image](https://i.imgur.com/jVFMMWR.png)
15
+ ## Details of the downstream task (Sequence Classification as Text generation) - Dataset 📚
16
+
17
+ [ Twitter Sarcasm Dataset](https://github.com/EducationalTestingService/sarcasm)
18
+
19
+
20
+ For Twitter training and testing datasets are provided for sarcasm detection tasks in jsonlines format.
21
+
22
+ Each line contains a JSON object with the following fields :
23
+ - ***label*** : `SARCASM` or `NOT_SARCASM`
24
+ - **NOT** in test data
25
+ - ***id***: String identifier for sample. This id will be required when making submissions.
26
+ - **ONLY** in test data
27
+ - ***response*** : the sarcastic response, whether a sarcastic Tweet
28
+ - ***context*** : the conversation context of the ***response***
29
+ - Note, the context is an ordered list of dialogue, i.e., if the context contains three elements, `c1`, `c2`, `c3`, in that order, then `c2` is a reply to `c1` and `c3` is a reply to `c2`. Further, if the sarcastic response is `r`, then `r` is a reply to `c3`.
30
+
31
+ For instance, for the following training example :
32
+
33
+ `"label": "SARCASM", "response": "Did Kelly just call someone else messy? Baaaahaaahahahaha", "context": ["X is looking a First Lady should . #classact, "didn't think it was tailored enough it looked messy"]`
34
+
35
+ The response tweet, "Did Kelly..." is a reply to its immediate context "didn't think it was tailored..." which is a reply to "X is looking...". Your goal is to predict the label of the "response" while also using the context (i.e, the immediate or the full context).
36
+
37
+ ***Dataset size statistics*** :
38
+
39
+ | | Train | Val | Test |
40
+ |---------|-------|------|------|
41
+ | Twitter | 4050 | 450 | 500 |
42
+
43
+ The datasets was preprocessed to convert it to a **text-to-text** (classfication as generation task).
44
+
45
+ ## Model fine-tuning 🏋️‍
46
+
47
+ The training script is a slightly modified version of [this Colab Notebook](https://github.com/patil-suraj/exploring-T5/blob/master/t5_fine_tuning.ipynb) created by [Suraj Patil](https://github.com/patil-suraj), so all credits to him!
48
+
49
+ ## Test set metrics 🧾
50
+
51
+ | | precision| recall | f1-score |support|
52
+ |----------|----------|---------|----------|-------|
53
+ | derison | 0.84 | 0.80 | 0.82 | 246 |
54
+ | normal | 0.82 | 0.85 | 0.83 | 254 |
55
+ | |
56
+ |accuracy| | | 0.83| 500|
57
+ |macro avg| 0.83| 0.83| 0.83| 500|
58
+ |weighted avg| 0.83| 0.83| 0.83| 500|
59
+
60
+
61
+
62
+ ## Model in Action 🚀
63
+
64
+ ```python
65
+ from transformers import AutoTokenizer, AutoModelWithLMHead
66
+ tokenizer = AutoTokenizer.from_pretrained("mrm8488/t5-base-finetuned-sarcasm-twitter")
67
+
68
+ model = AutoModelWithLMHead.from_pretrained("mrm8488/t5-base-finetuned-sarcasm-twitter")
69
+
70
+ def eval_conversation(text):
71
+
72
+ input_ids = tokenizer.encode(text + '</s>', return_tensors='pt')
73
+
74
+ output = model.generate(input_ids=input_ids, max_length=3)
75
+
76
+ dec = [tokenizer.decode(ids) for ids in output]
77
+
78
+ label = dec[0]
79
+
80
+ return label
81
+
82
+ # For similarity with the training dataset we should replace users mentions in twits for @USER token and urls for URL token.
83
+
84
+ twit1 = "Trump just suspended the visa program that allowed me to move to the US to start @USER!" +
85
+ " Unfortunately, I won’t be able to vote in a few months but if you can, please vote him out, " +
86
+ "he's destroying what made America great in so many different ways!"
87
+
88
+ twit2 = "@USER @USER @USER We have far more cases than any other country, " +
89
+ "so leaving remote workers in would be disastrous. Makes Trump sense."
90
+
91
+ twit3 = "My worry is that i wouldn’t be surprised if half the country actually agrees with this move..."
92
+
93
+ me = "Trump doing so??? It must be a mistake... XDDD"
94
+
95
+ conversation = twit1 + twit2
96
+
97
+ eval_conversation(conversation) #Output: 'derison'
98
+
99
+ conversation = twit1 + twit3
100
+
101
+ eval_conversation(conversation) #Output: 'normal'
102
+
103
+ conversation = twit1 + me
104
+
105
+ eval_conversation(conversation) #Output: 'derison'
106
+
107
+ # We will get 'normal' when sarcasm is not detected and 'derison' when detected
108
+ ```
109
+
110
+ > Created by [Manuel Romero/@mrm8488](https://twitter.com/mrm8488) | [LinkedIn](https://www.linkedin.com/in/manuel-romero-cs/)
111
+
112
+ > Made with <span style="color: #e25555;">&hearts;</span> in Spain