DSXiangLi commited on
Commit
54f0839
1 Parent(s): 99291c5
Files changed (3) hide show
  1. app.py +3 -4
  2. requirements.txt +2 -1
  3. self/generate.py +2 -2
app.py CHANGED
@@ -95,16 +95,15 @@ with gr.Blocks(title="Automatic Prompt Engineer", theme=gr.themes.Glass()) as de
95
  with gr.Row():
96
  with gr.Column():
97
  openai_key2 = gr.Textbox(type='password', label='输入 API key')
98
- n_human = gr.Slider(label="人工指令数", minimum=1, maximum=5, step=1, value=1)
99
  n_machine = gr.Slider(label="机器指令数", minimum=1, maximum=5, step=1, value=1)
100
- n_instruct = gr.Slider(label="生成指令数", minimum=1, maximum=100, step=5, value=1, help="生成指令数>人工+机器")
101
  seed_file = gr.File(label='上传json文件, 格式参考./self/data/seed_task.json')
102
 
103
  with gr.Column():
104
  self_prompt_input = gr.Textbox(max_lines=100, lines=20, interative=True,
105
  placeholder=self_prompt,
106
  value='', label="Prompt for self-instruct")
107
- init_self = gr.Button("初始化")
108
  self_instance = gr.State()
109
 
110
  gr.Markdown('\n\n')
@@ -152,7 +151,7 @@ with gr.Blocks(title="Automatic Prompt Engineer", theme=gr.themes.Glass()) as de
152
  SELF Callback
153
  """
154
  # 1. 加载种子文件
155
- init_self.click(init_instance, inputs=[seed_file, openai_key2, n_human, n_machine, n_instruct, self_prompt_input],
156
  outputs=[self_instance])
157
 
158
  # 2. 生成
 
95
  with gr.Row():
96
  with gr.Column():
97
  openai_key2 = gr.Textbox(type='password', label='输入 API key')
98
+ n_human = gr.Slider(label="人工指令数", minimum=1, maximum=5, step=1, value=2)
99
  n_machine = gr.Slider(label="机器指令数", minimum=1, maximum=5, step=1, value=1)
100
+ n_instruct = gr.Slider(label="生成指令数", minimum=1, maximum=100, step=1, value=4, help="生成指令数>人工+机器")
101
  seed_file = gr.File(label='上传json文件, 格式参考./self/data/seed_task.json')
102
 
103
  with gr.Column():
104
  self_prompt_input = gr.Textbox(max_lines=100, lines=20, interative=True,
105
  placeholder=self_prompt,
106
  value='', label="Prompt for self-instruct")
 
107
  self_instance = gr.State()
108
 
109
  gr.Markdown('\n\n')
 
151
  SELF Callback
152
  """
153
  # 1. 加载种子文件
154
+ seed_file.submit(init_instance, inputs=[seed_file, openai_key2, n_human, n_machine, n_instruct, self_prompt_input],
155
  outputs=[self_instance])
156
 
157
  # 2. 生成
requirements.txt CHANGED
@@ -4,4 +4,5 @@ openai
4
  langchain
5
  pandas
6
  rouge_score
7
- transformers
 
 
4
  langchain
5
  pandas
6
  rouge_score
7
+ transformers
8
+ pytorch
self/generate.py CHANGED
@@ -89,10 +89,8 @@ class SELF(object):
89
  # build few-shot
90
  few_shot = gen_few_shot_prompt(self.sample_few_shot)
91
  few_shot += SELF.prefix.format(id=self.first_id) # 新生成的指令
92
- print(few_shot)
93
  # generate
94
  result = self.chain({'few_shot': few_shot, 'n_instruct': self.n_instruct})
95
- print(result)
96
  return result
97
 
98
  def decode_response(self, response):
@@ -142,6 +140,8 @@ class SELF(object):
142
  with Pool(os.cpu_count()) as p:
143
  rouge_scores = p.map(partial(rouge_scorer._score_lcs, self.all_instruction_tokens), inst_tokens)
144
  rouge_l = [score.fmeasure for score in rouge_scores]
 
 
145
  top10_sim_inst = {
146
  self.all_instruction[i]: rouge_l[i] for i in np.argsort(rouge_l)[-10:][::-1]
147
  }
 
89
  # build few-shot
90
  few_shot = gen_few_shot_prompt(self.sample_few_shot)
91
  few_shot += SELF.prefix.format(id=self.first_id) # 新生成的指令
 
92
  # generate
93
  result = self.chain({'few_shot': few_shot, 'n_instruct': self.n_instruct})
 
94
  return result
95
 
96
  def decode_response(self, response):
 
140
  with Pool(os.cpu_count()) as p:
141
  rouge_scores = p.map(partial(rouge_scorer._score_lcs, self.all_instruction_tokens), inst_tokens)
142
  rouge_l = [score.fmeasure for score in rouge_scores]
143
+ print(rouge_scores)
144
+ print(rouge_l)
145
  top10_sim_inst = {
146
  self.all_instruction[i]: rouge_l[i] for i in np.argsort(rouge_l)[-10:][::-1]
147
  }