Add no repeat n gram

#1
by ybelkada - opened
Files changed (1) hide show
  1. app.py +15 -6
app.py CHANGED
@@ -14,9 +14,9 @@ hf_writer = gr.HuggingFaceDatasetSaver(HF_API_TOKEN, "huggingface/bloom_internal
14
 
15
 
16
  examples = [
17
- ['A "whatpu" is a small, furry animal native to Tanzania. An example of a sentence that uses the word whatpu is: We were traveling in Africa and we saw these very cute whatpus. To do a "farduddle" means to jump up and down really fast. An example of a sentence that uses the word farduddle is:', 8, 0.1, 0, 0.9, False],
18
- ['def quicksort(l):', 8, 0.1, 0, 0.9, False],
19
- ['Q: ¿Cómo te llamas? A: What is your name? Q: ¿Qué edad tienes? A: How old are you? Q: ¿Dónde vives?', 8, 0.1, 0, 0.9, False]
20
  ]
21
 
22
  def safe_text(text):
@@ -35,11 +35,18 @@ def query(payload):
35
  print(response)
36
  return json.loads(response.content.decode("utf-8"))
37
 
38
- def inference(input_sentence, max_length, temperature,top_k, top_p, greedy_decoding, seed=42):
39
  top_k = None if top_k == 0 else top_k
 
 
 
 
 
 
 
40
  payload = {"inputs": input_sentence,
41
  "parameters": {"max_new_tokens": max_length, "top_k": top_k, "top_p": top_p, "temperature": temperature,
42
- "do_sample": not greedy_decoding, "seed": seed}}
43
  data = query(
44
  payload
45
  )
@@ -51,7 +58,9 @@ gr.Interface(
51
  inference,
52
  [
53
  gr.inputs.Textbox(label="Input"),
54
- gr.inputs.Slider(1, 64, default=8, label="Tokens to generate"),
 
 
55
  gr.inputs.Slider(0.0, 1.0, default=0.1, step=0.05, label="Temperature"),
56
  gr.inputs.Slider(0, 64, default=0, step=1, label="Top K"),
57
  gr.inputs.Slider(0.0, 10, default=0.9, step=0.05, label="Top P"),
 
14
 
15
 
16
  examples = [
17
+ ['A "whatpu" is a small, furry animal native to Tanzania. An example of a sentence that uses the word whatpu is: We were traveling in Africa and we saw these very cute whatpus. To do a "farduddle" means to jump up and down really fast. An example of a sentence that uses the word farduddle is:', 8, 0, 0, 0.1, 0, 0.9, False],
18
+ ['def quicksort(l):', 8, 0, 0, 0.1, 0, 0.9, False],
19
+ ['Q: ¿Cómo te llamas? A: What is your name? Q: ¿Qué edad tienes? A: How old are you? Q: ¿Dónde vives?', 8, 0, 0, 0.1, 0, 0.9, False]
20
  ]
21
 
22
  def safe_text(text):
 
35
  print(response)
36
  return json.loads(response.content.decode("utf-8"))
37
 
38
+ def inference(input_sentence, max_length, no_repeat_ngram_size, num_beams, temperature,top_k, top_p, greedy_decoding, seed=42):
39
  top_k = None if top_k == 0 else top_k
40
+ do_sample = False if num_beams > 0 else not greedy_decoding
41
+ num_beams = None if (greedy_decoding or num_beams == 0) else num_beams
42
+ no_repeat_ngram_size = None if num_beams is None else no_repeat_ngram_size
43
+ top_p = None if num_beams else top_p
44
+
45
+ early_stopping = None if num_beams is None else num_beams > 0
46
+
47
  payload = {"inputs": input_sentence,
48
  "parameters": {"max_new_tokens": max_length, "top_k": top_k, "top_p": top_p, "temperature": temperature,
49
+ "do_sample": do_sample, "seed": seed, "early_stopping":early_stopping, "no_repeat_ngram_size":no_repeat_ngram_size, "num_beams":num_beams}}
50
  data = query(
51
  payload
52
  )
 
58
  inference,
59
  [
60
  gr.inputs.Textbox(label="Input"),
61
+ gr.inputs.Slider(1, 64, default=8, step=1, label="Tokens to generate"),
62
+ gr.inputs.Slider(1, 10, default=2, step=1, label="No repeat N gram"),
63
+ gr.inputs.Slider(0, 10, default=5, step=1, label="Num beams"),
64
  gr.inputs.Slider(0.0, 1.0, default=0.1, step=0.05, label="Temperature"),
65
  gr.inputs.Slider(0, 64, default=0, step=1, label="Top K"),
66
  gr.inputs.Slider(0.0, 10, default=0.9, step=0.05, label="Top P"),