Files changed (1) hide show
  1. app.py +10 -17
app.py CHANGED
@@ -4,7 +4,6 @@ import requests
4
  import json
5
  import os
6
 
7
-
8
  APIKEY = os.environ.get("APIKEY")
9
  APISECRET = os.environ.get("APISECRET")
10
 
@@ -17,12 +16,12 @@ def predict(text, seed, out_seq_length, min_gen_length, sampling_strategy,
17
  if text == '':
18
  return 'Input should not be empty!'
19
 
20
- url = 'https://tianqi.aminer.cn/api/v2/completions_130B'
21
 
22
  payload = json.dumps({
23
  "apikey": APIKEY,
24
  "apisecret": APISECRET ,
25
- "model_name": "glm-130b-v1",
26
  "prompt": text,
27
  "length_penalty": length_penalty,
28
  "temperature": temperature,
@@ -33,7 +32,6 @@ def predict(text, seed, out_seq_length, min_gen_length, sampling_strategy,
33
  "num_beams": num_beams,
34
  "max_tokens": out_seq_length,
35
  "no_repeat_ngram": no_repeat_ngram_size,
36
- "quantization": "int4",
37
  "seed": seed
38
  })
39
 
@@ -61,9 +59,9 @@ def predict(text, seed, out_seq_length, min_gen_length, sampling_strategy,
61
  if __name__ == "__main__":
62
 
63
  en_fil = ['The Starry Night is an oil-on-canvas painting by [MASK] in June 1889.']
64
- en_gen = ['Question: What\'s the best winter resort city? User: A 10-year professional traveler. Answer: [gMASK]'] #['Eight planets in solar system are [gMASK]']
65
  ch_fil = ['凯旋门位于意大利米兰市古城堡旁。1807年为纪念[MASK]而建,门高25米,顶上矗立两武士青铜古兵车铸像。']
66
- ch_gen = ['三亚位于海南岛的最南端,是[gMASK]']
67
  en_to_ch = ['Pencil in Chinese is [MASK].']
68
  ch_to_en = ['"我思故我在"的英文是"[MASK]"。']
69
 
@@ -72,13 +70,8 @@ if __name__ == "__main__":
72
  with gr.Blocks() as demo:
73
  gr.Markdown(
74
  """
75
- Dear friends,
76
-
77
- Nice to meet you here! This is a toy demo of GLM-130B, an open bilingual pre-trained model from Tsinghua Univeristy. GLM-130B uses two different mask tokens: `[MASK]` for short blank filling and `[gMASK]` for left-to-right long text generation. When the input does not contain any MASK token, `[gMASK]` will be automatically appended to the end of the text. We recommend that you use `[MASK]` to try text fill-in-the-blank to reduce wait time (ideally within seconds without queuing).
78
-
79
- This demo is a raw language model **without** instruction fine-tuning (which is applied to FLAN-* series) and RLHF (which is applied to ChatGPT); its ability is roughly between OpenAI `davinci` and `text-davinci-001`. Thus, it is currently worse than ChatGPT and other instruction fine-tuned models :(
80
-
81
- However, we are sparing no effort to improve it, and its updated versions will meet you soon! If you find the open-source effort useful, please star our [GitHub repo](https://github.com/THUDM/GLM-130B) to encourage our following development :)
82
  """)
83
 
84
  with gr.Row():
@@ -100,7 +93,7 @@ if __name__ == "__main__":
100
  out_seq_length = gr.Slider(maximum=256, value=128, minimum=32, step=1, label='Output Sequence Length')
101
  with gr.Column():
102
  min_gen_length = gr.Slider(maximum=64, value=0, step=1, label='Min Generate Length')
103
- sampling_strategy = gr.Radio(choices=['BeamSearchStrategy', 'BaseStrategy'], value='BaseStrategy', label='Search Strategy')
104
 
105
  with gr.Row():
106
  with gr.Column():
@@ -118,9 +111,9 @@ if __name__ == "__main__":
118
  """
119
  BaseStrategy
120
  """)
121
- temperature = gr.Slider(maximum=1, value=1.0, minimum=0, label='Temperature')
122
- topk = gr.Slider(maximum=40, value=0, minimum=0, step=1, label='Top K')
123
- topp = gr.Slider(maximum=1, value=0.7, minimum=0, label='Top P')
124
 
125
  inputs = [model_input, seed, out_seq_length, min_gen_length, sampling_strategy, num_beams, length_penalty, no_repeat_ngram_size, temperature, topk, topp]
126
  gen.click(fn=predict, inputs=inputs, outputs=outputs)
4
  import json
5
  import os
6
 
 
7
  APIKEY = os.environ.get("APIKEY")
8
  APISECRET = os.environ.get("APISECRET")
9
 
16
  if text == '':
17
  return 'Input should not be empty!'
18
 
19
+ url = 'https://wudao.aminer.cn/os/api/api/v2/completions_130B'
20
 
21
  payload = json.dumps({
22
  "apikey": APIKEY,
23
  "apisecret": APISECRET ,
24
+ "language": "zh-CN",
25
  "prompt": text,
26
  "length_penalty": length_penalty,
27
  "temperature": temperature,
32
  "num_beams": num_beams,
33
  "max_tokens": out_seq_length,
34
  "no_repeat_ngram": no_repeat_ngram_size,
 
35
  "seed": seed
36
  })
37
 
59
  if __name__ == "__main__":
60
 
61
  en_fil = ['The Starry Night is an oil-on-canvas painting by [MASK] in June 1889.']
62
+ en_gen = ['Eight planets in solar system are [gMASK]']
63
  ch_fil = ['凯旋门位于意大利米兰市古城堡旁。1807年为纪念[MASK]而建,门高25米,顶上矗立两武士青铜古兵车铸像。']
64
+ ch_gen = ['三亚位于海南岛的最南端,是中国最南部的热带滨海旅游城市 [gMASK]']
65
  en_to_ch = ['Pencil in Chinese is [MASK].']
66
  ch_to_en = ['"我思故我在"的英文是"[MASK]"。']
67
 
70
  with gr.Blocks() as demo:
71
  gr.Markdown(
72
  """
73
+ An Open Bilingual Pre-Trained Model. [Visit our github repo](https://github.com/THUDM/GLM-130B)
74
+ GLM-130B uses two different mask tokens: `[MASK]` for short blank filling and `[gMASK]` for left-to-right long text generation. When the input does not contain any MASK token, `[gMASK]` will be automatically appended to the end of the text. We recommend that you use `[MASK]` to try text fill-in-the-blank to reduce wait time (ideally within seconds without queuing).
 
 
 
 
 
75
  """)
76
 
77
  with gr.Row():
93
  out_seq_length = gr.Slider(maximum=256, value=128, minimum=32, step=1, label='Output Sequence Length')
94
  with gr.Column():
95
  min_gen_length = gr.Slider(maximum=64, value=0, step=1, label='Min Generate Length')
96
+ sampling_strategy = gr.Radio(choices=['BeamSearchStrategy', 'BaseStrategy'], value='BeamSearchStrategy', label='Search Strategy')
97
 
98
  with gr.Row():
99
  with gr.Column():
111
  """
112
  BaseStrategy
113
  """)
114
+ temperature = gr.Slider(maximum=1, value=0.7, minimum=0, label='Temperature')
115
+ topk = gr.Slider(maximum=40, value=1, minimum=0, step=1, label='Top K')
116
+ topp = gr.Slider(maximum=1, value=0, minimum=0, label='Top P')
117
 
118
  inputs = [model_input, seed, out_seq_length, min_gen_length, sampling_strategy, num_beams, length_penalty, no_repeat_ngram_size, temperature, topk, topp]
119
  gen.click(fn=predict, inputs=inputs, outputs=outputs)