File size: 3,833 Bytes
7da33c0
 
b92f4df
 
 
 
 
a8a18a4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c8c5151
 
a8a18a4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
---
license: openrail
datasets:
- humarin/chatgpt-paraphrases
language:
- en
library_name: transformers
---
This model was trained on our [ChatGPT paraphrase dataset](https://huggingface.co/datasets/humarin/chatgpt-paraphrases).



This dataset is based on the [Quora paraphrase question](https://www.kaggle.com/competitions/quora-question-pairs), texts from the [SQUAD 2.0](https://huggingface.co/datasets/squad_v2) and the [CNN news dataset](https://huggingface.co/datasets/cnn_dailymail).

This model is based on the T5-base model. We used "transfer learning" to get our model to generate paraphrases as well as ChatGPT. Now we can say that this is one of the best paraphrases of the Hugging Face.

[Kaggle](https://www.kaggle.com/datasets/vladimirvorobevv/chatgpt-paraphrases) link

**Deploying example:**
```python
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM

device = "cuda"

tokenizer = AutoTokenizer.from_pretrained("humarin/chatgpt_paraphraser_on_T5_base")

model = AutoModelForSeq2SeqLM.from_pretrained("humarin/chatgpt_paraphraser_on_T5_base").to(device)

def paraphrase(text, max_length=128, num_return_sequences=5, num_beams=25, temperature=0.7):
    input_ids = tokenizer(
        f'paraphrase: {text}',
        return_tensors="pt", padding="longest",
        max_length=max_length,
        truncation=True,
    ).input_ids.to(device)
    
    outputs = model.generate(
        input_ids, temperature=temperature, repetition_penalty=1.5,
        num_return_sequences=num_return_sequences, no_repeat_ngram_size=5, num_beams=num_beams, max_length=max_length
    )

    res = tokenizer.batch_decode(outputs, skip_special_tokens=True)

    return res
```

**Usage examples**

**Input:**
```python
text = 'What are the best places to see in New York?'
paraphrase(text)
```
**Output:**
```python
['What are some of the must-visit places in New York?',
 'Which places should I not miss when visiting New York?',
 'Which are the top tourist destinations in New York?',
 'Which places should I not miss while visiting New York?',
 'What are some of the must-visit locations in New York?']
```

**Input:**
```python
text = "This Year's Model is the second studio album by the English singer-songwriter Elvis Costello (pictured), released on 17 March 1978 through Radar Records with his new backing band, the Attractions. It was recorded at Eden Studios in late 1977 and early 1978."
paraphrase(text)
```
**Output:**
```python
["The English singer-songwriter Elvis Costello's second studio album, This Year's Model, was released on 17 March 1978 through Radar Records with his new backing band, the Attractions. It was recorded at Eden Studios in late 1977 and early 1978.",
 "This Year's Model, the second studio album of Elvis Costello (pictured), was released on 17 March 1978 through Radar Records with his new backing band, the Attractions. It was recorded at Eden Studios in late 1977 and early 1978.",
 "The English singer-songwriter Elvis Costello's second studio album, This Year's Model, was released on March 17, 1978, through Radar Records with his new backing band, the Attractions. It was recorded at Eden Studios in late 1977 and early 1978.",
 "The English singer-songwriter Elvis Costello (pictured) released his second studio album, This Year's Model, on 17 March 1978 through Radar Records with his new backing band, the Attractions, which was recorded at Eden Studios in late 1977 and early 1978.",
 "The English singer-songwriter Elvis Costello (pictured) released his second studio album, This Year's Model, on March 17, 1978, through Radar Records with his new backing band, the Attractions. It was recorded at Eden Studios in late 1977 and early 1978."]
```


**Train parameters:**
```python
epochs = 1
batch_size = 128
lr = 5e-5
batches_qty = 82849
betas = (0.9, 0.999)
eps = 1e-08
```