Update README.md
Browse files
README.md
CHANGED
@@ -1,3 +1,84 @@
|
|
1 |
---
|
|
|
|
|
2 |
license: cc-by-nc-sa-4.0
|
|
|
|
|
|
|
|
|
|
|
3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
+
language: it
|
3 |
+
datasets: tapaco
|
4 |
license: cc-by-nc-sa-4.0
|
5 |
+
tags:
|
6 |
+
- mt5
|
7 |
+
- paraphrase-generation
|
8 |
+
- paraphrasing
|
9 |
+
|
10 |
---
|
11 |
+
|
12 |
+
# MT5-base fine-tuned on Tapaco dataset for Paraphrasing
|
13 |
+
|
14 |
+
MT5-base Italian paraphraser fine-tuned on [TaPaCo](https://huggingface.co/datasets/tapaco) dataset.
|
15 |
+
|
16 |
+
## Details of MT5
|
17 |
+
|
18 |
+
The **MT5** model was presented in [mT5: A massively multilingual pre-trained text-to-text transformer](https://arxiv.org/abs/2010.11934) by *Linting Xue, Noah Constant, Adam Roberts, Mihir Kale, Rami Al-Rfou, Aditya Siddhant, Aditya Barua, Colin Raffel* in 2020. Here the abstract:
|
19 |
+
|
20 |
+
The recent "Text-to-Text Transfer Transformer" (T5) leveraged a unified text-to-text format and scale to attain state-of-the-art results on a wide variety of English-language NLP tasks. In this paper, we introduce mT5, a multilingual variant of T5 that was pre-trained on a new Common Crawl-based dataset covering 101 languages. We detail the design and modified training of mT5 and demonstrate its state-of-the-art performance on many multilingual benchmarks. We also describe a simple technique to prevent "accidental translation" in the zero-shot setting, where a generative model chooses to (partially) translate its prediction into the wrong language. All of the code and model checkpoints used in this work are publicly available.
|
21 |
+
|
22 |
+
## Model fine-tuning
|
23 |
+
|
24 |
+
The training script is a slightly modified version of this [Colab notebook](https://colab.research.google.com/drive/1DGeF190gJ3DjRFQiwhFuZalp427iqJNQ) after having prepared an adapted italian version of mt5 model by following this other [Colab notebook](https://gist.github.com/avidale/44cd35bfcdaf8bedf51d97c468cc8001)
|
25 |
+
|
26 |
+
## Model in Action
|
27 |
+
|
28 |
+
```python
|
29 |
+
from transformers import T5ForConditionalGeneration, T5Tokenizer
|
30 |
+
import torch
|
31 |
+
|
32 |
+
raw_model = 'aiknowyou/mt5-base-it-paraphraser'
|
33 |
+
|
34 |
+
# Model and Tokenizer definition #
|
35 |
+
model = T5ForConditionalGeneration.from_pretrained(raw_model)
|
36 |
+
tokenizer = T5Tokenizer.from_pretrained(raw_model)
|
37 |
+
|
38 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
39 |
+
max_size = 10000
|
40 |
+
|
41 |
+
def get_paraphrased_sentences(model, tokenizer, sentence, num_return_sequences=5, num_beams=5):
|
42 |
+
# tokenize the text to be form of a list of token IDs
|
43 |
+
inputs = tokenizer([sentence], truncation=True, padding="longest", return_tensors="pt").to(model.device)
|
44 |
+
# generate the paraphrased sentences
|
45 |
+
outputs = model.generate(
|
46 |
+
**inputs,
|
47 |
+
num_beams=num_beams,
|
48 |
+
num_return_sequences=num_return_sequences,
|
49 |
+
max_length=max_size
|
50 |
+
)
|
51 |
+
# decode the generated sentences using the tokenizer to get them back to text
|
52 |
+
return tokenizer.batch_decode(outputs, skip_special_tokens=True)
|
53 |
+
|
54 |
+
# sentence = "Vorrei chiedervi la procedura per recuperare la chiave di accesso al mio profilo personale. L'ho persa e vorrei recuperarla."
|
55 |
+
# get_paraphrased_sentences(model, tokenizer, sentence, num_beams=100, num_return_sequences=5)
|
56 |
+
|
57 |
+
```
|
58 |
+
|
59 |
+
## Output
|
60 |
+
```
|
61 |
+
Original Question ::
|
62 |
+
"Vorrei chiedervi la procedura per recuperare la chiave di accesso al mio profilo personale. L'ho persa e vorrei recuperarla."
|
63 |
+
|
64 |
+
Paraphrased Questions ::
|
65 |
+
'Vorrei chiedervi la procedura per recuperare la chiave di accesso al mio profilo personale.',
|
66 |
+
'Vorrei chiederti la procedura per recuperare la chiave di accesso al mio profilo personale.',
|
67 |
+
'Vorrei chiedervi la procedura per restituire la chiave di accesso al mio profilo personale.',
|
68 |
+
'Vorrei chiedere la procedura per recuperare la chiave di accesso al mio profilo personale.',
|
69 |
+
'Vorrei chiedervi la procedura per recuperare la chiave di accesso al mio profilo personale. L'ho persa e vorrei recuperarla.'
|
70 |
+
```
|
71 |
+
|
72 |
+
## Contribution
|
73 |
+
|
74 |
+
Thanks to [@tradicio](https://huggingface.co/tradicio) for adding this model.
|
75 |
+
|
76 |
+
## License
|
77 |
+
|
78 |
+
This work is licensed under a
|
79 |
+
[Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License][cc-by-nc-sa].
|
80 |
+
|
81 |
+
[![CC BY-NC-SA 4.0][cc-by-nc-sa-image]][cc-by-nc-sa]
|
82 |
+
|
83 |
+
[cc-by-nc-sa]: http://creativecommons.org/licenses/by-nc-sa/4.0/
|
84 |
+
[cc-by-nc-sa-image]: https://licensebuttons.net/l/by-nc-sa/4.0/88x31.png
|