Views
No views yet
1from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
2
3device = "cuda"
4
5tokenizer = AutoTokenizer.from_pretrained("humarin/chatgpt_paraphraser_on_T5_base")
6
7model = AutoModelForSeq2SeqLM.from_pretrained("humarin/chatgpt_paraphraser_on_T5_base").to(device)
8
9def paraphrase(
10 question,
11 num_beams=5,
12 num_beam_groups=5,
13 num_return_sequences=5,
14 repetition_penalty=10.0,
15 diversity_penalty=3.0,
16 no_repeat_ngram_size=2,
17 temperature=0.7,
18 max_length=128
19):
20 input_ids = tokenizer(
21 f'paraphrase: {question}',
22 return_tensors="pt", padding="longest",
23 max_length=max_length,
24 truncation=True,
25 ).input_ids.to(device)
26
27 outputs = model.generate(
28 input_ids, temperature=temperature, repetition_penalty=repetition_penalty,
29 num_return_sequences=num_return_sequences, no_repeat_ngram_size=no_repeat_ngram_size,
30 num_beams=num_beams, num_beam_groups=num_beam_groups,
31 max_length=max_length, diversity_penalty=diversity_penalty
32 )
33
34 res = tokenizer.batch_decode(outputs, skip_special_tokens=True)
35
36 return res1text = 'What are the best places to see in New York?'
2paraphrase(text)1['What are some must-see places in New York?',
2 'Can you suggest some must-see spots in New York?',
3 'Where should one go to experience the best NYC has to offer?',
4 'Which places should I visit in New York?',
5 'What are the top destinations to explore in New York?']1text = "Rammstein's album Mutter was recorded in the south of France in May and June 2000, and mixed in Stockholm in October of that year."
2paraphrase(text)1['In May and June 2000, Rammstein travelled to the south of France to record his album Mutter, which was mixed in Stockholm in October of that year.',
2 'The album Mutter by Rammstein was recorded in the south of France during May and June 2000, with mixing taking place in Stockholm in October of that year.',
3 'The album Mutter by Rammstein was recorded in the south of France during May and June 2000, with mixing taking place in Stockholm in October of that year. It',
4 'Mutter, the album released by Rammstein, was recorded in southern France during May and June 2000, with mixing taking place between October and September.',
5 'In May and June 2000, Rammstein recorded his album Mutter in the south of France, with the mix being made at Stockholm during October.']1epochs = 5
2batch_size = 64
3max_length = 128
4lr = 5e-5
5batches_qty = 196465
6betas = (0.9, 0.999)
7eps = 1e-081@inproceedings{chatgpt_paraphraser,
2 author={Vladimir Vorobev, Maxim Kuznetsov},
3 title={A paraphrasing model based on ChatGPT paraphrases},
4 year={2023}
5}