Files changed (1) hide show
  1. app.py +38 -6
app.py CHANGED
@@ -7,7 +7,17 @@ tokenizer = AutoTokenizer.from_pretrained('humarin/chatgpt_paraphraser_on_T5_ba
7
  model = AutoModelForSeq2SeqLM.from_pretrained('humarin/chatgpt_paraphraser_on_T5_base', cache_dir='./Models')
8
  # torch.quantization.quantize_dynamic(model, {torch.nn.Linear}, dtype=torch.qint8, inplace=True)
9
 
10
- def paraphrase(model, text, max_length=128, num_return_sequences=5, num_beams=25, temperature=0.7):
 
 
 
 
 
 
 
 
 
 
11
  input_ids = tokenizer(
12
  f'paraphrase: {text}',
13
  return_tensors="pt", padding="longest",
@@ -16,20 +26,42 @@ def paraphrase(model, text, max_length=128, num_return_sequences=5, num_beams=25
16
  ).input_ids
17
 
18
  outputs = model.generate(
19
- input_ids, temperature=temperature, repetition_penalty=1.5,
20
- num_return_sequences=num_return_sequences, no_repeat_ngram_size=5, num_beams=num_beams, max_length=max_length
 
 
21
  )
22
 
23
  res = tokenizer.batch_decode(outputs, skip_special_tokens=True)
24
 
25
  return res
26
 
27
- def fn(text, results_num=5, beams_num=25, temperature=0.7):
28
- return '\n'.join(paraphrase(model, text, num_return_sequences=results_num, num_beams=beams_num, temperature=temperature))
 
 
 
 
 
 
 
 
 
 
29
 
30
  demo = gr.Interface(
31
  fn=fn,
32
- inputs=[gr.Textbox(lines=3, placeholder='Enter Text To Paraphrase'), gr.Slider(minimum=1, maximum=10, step=1, value=5), gr.Slider(minimum=1, maximum=50, step=1, value=25), gr.Slider(minimum=0.0, maximum=1.0, step=0.01, value=0.7)],
 
 
 
 
 
 
 
 
 
 
33
  outputs=['text'],
34
  )
35
 
 
7
  model = AutoModelForSeq2SeqLM.from_pretrained('humarin/chatgpt_paraphraser_on_T5_base', cache_dir='./Models')
8
  # torch.quantization.quantize_dynamic(model, {torch.nn.Linear}, dtype=torch.qint8, inplace=True)
9
 
10
+ def paraphrase(
11
+ text,
12
+ num_beams=5,
13
+ num_beam_groups=5,
14
+ num_return_sequences=5,
15
+ repetition_penalty=10.0,
16
+ diversity_penalty=3.0,
17
+ no_repeat_ngram_size=2,
18
+ temperature=0.7,
19
+ max_length=128
20
+ ):
21
  input_ids = tokenizer(
22
  f'paraphrase: {text}',
23
  return_tensors="pt", padding="longest",
 
26
  ).input_ids
27
 
28
  outputs = model.generate(
29
+ input_ids, temperature=temperature, repetition_penalty=repetition_penalty,
30
+ num_return_sequences=num_return_sequences, no_repeat_ngram_size=no_repeat_ngram_size,
31
+ num_beams=num_beams, num_beam_groups=num_beam_groups,
32
+ max_length=max_length, diversity_penalty=diversity_penalty
33
  )
34
 
35
  res = tokenizer.batch_decode(outputs, skip_special_tokens=True)
36
 
37
  return res
38
 
39
+ def fn(
40
+ text,
41
+ num_beams=5,
42
+ num_beam_groups=5,
43
+ num_return_sequences=5,
44
+ repetition_penalty=10.0,
45
+ diversity_penalty=3.0,
46
+ no_repeat_ngram_size=2,
47
+ temperature=0.7,
48
+ max_length=128
49
+ ):
50
+ return '\n'.join(paraphrase(text, num_beams, num_beam_groups, num_return_sequences, repetition_penalty, diversity_penalty, no_repeat_ngram_size, temperature, max_length))
51
 
52
  demo = gr.Interface(
53
  fn=fn,
54
+ inputs=[
55
+ gr.Textbox(lines=3, placeholder='Enter Text To Paraphrase'),
56
+ gr.Slider(minimum=1, maximum=25, step=1, value=5),
57
+ gr.Slider(minimum=1, maximum=25, step=1, value=5),
58
+ gr.Slider(minimum=1, maximum=20, step=1, value=5),
59
+ gr.Slider(minimum=0.6, maximum=20.1, step=0.5, value=10.1),
60
+ gr.Slider(minimum=0.6, maximum=20.1, step=0.5, value=3.1),
61
+ gr.Slider(minimum=1, maximum=10, step=1, value=2),
62
+ gr.Slider(minimum=0.0, maximum=1000, step=0.1, value=0.7),
63
+ gr.Slider(minimum=32, maximum=512, step=1, value=128),
64
+ ],
65
  outputs=['text'],
66
  )
67