Spaces:
Runtime error
Runtime error
DSXiangLi
commited on
Commit
•
769e5d5
1
Parent(s):
1cabc1d
- app.py +2 -2
- self/generate.py +5 -6
app.py
CHANGED
@@ -91,7 +91,7 @@ with gr.Blocks(title="Automatic Prompt Engineer", theme=gr.themes.Glass()) as de
|
|
91 |
gr.Markdown('--------')
|
92 |
gr.Markdown('\n\n')
|
93 |
gr.Markdown("# SELF INSTRUCT")
|
94 |
-
gr.Markdown('##
|
95 |
with gr.Row():
|
96 |
with gr.Column():
|
97 |
n_human = gr.Slider(label="人工指令数", minimum=1, maximum=5, step=1, value=2)
|
@@ -107,7 +107,7 @@ with gr.Blocks(title="Automatic Prompt Engineer", theme=gr.themes.Glass()) as de
|
|
107 |
self_instance = gr.State()
|
108 |
|
109 |
gr.Markdown('\n\n')
|
110 |
-
gr.Markdown('##
|
111 |
with gr.Row():
|
112 |
with gr.Column(scale=1):
|
113 |
fewshot = gr.Textbox(label='采样few-shot')
|
|
|
91 |
gr.Markdown('--------')
|
92 |
gr.Markdown('\n\n')
|
93 |
gr.Markdown("# SELF INSTRUCT")
|
94 |
+
gr.Markdown('## 第一步:确认参数并上传种子指令')
|
95 |
with gr.Row():
|
96 |
with gr.Column():
|
97 |
n_human = gr.Slider(label="人工指令数", minimum=1, maximum=5, step=1, value=2)
|
|
|
107 |
self_instance = gr.State()
|
108 |
|
109 |
gr.Markdown('\n\n')
|
110 |
+
gr.Markdown('## 第二步:采样并生成新指令,每点一次会重采样并生成,生成结果会累计')
|
111 |
with gr.Row():
|
112 |
with gr.Column(scale=1):
|
113 |
fewshot = gr.Textbox(label='采样few-shot')
|
self/generate.py
CHANGED
@@ -47,7 +47,7 @@ class SELF(object):
|
|
47 |
self.scorer = None # rougeL用于文本相似度计算
|
48 |
self.all_instruction_tokens = [] # 全部指令,用于新指令消重
|
49 |
self.all_instruction = [] # 全部指令,用于新指令消重
|
50 |
-
self.sample_few_shot = None
|
51 |
self.load_seed_task(seed_file)
|
52 |
self.init(prompt)
|
53 |
|
@@ -87,12 +87,11 @@ class SELF(object):
|
|
87 |
seed_sample = random.sample(self.human_instruction_data, self.n_human)
|
88 |
machine_sample = random.sample(self.machine_instruction_data,
|
89 |
min(self.n_machine, len(self.machine_instruction_data)))
|
90 |
-
self.sample_few_shot = seed_sample + machine_sample
|
91 |
# build few-shot
|
92 |
-
|
93 |
-
few_shot += SELF.prefix.format(id=self.first_id) # 新生成的指令
|
94 |
# generate
|
95 |
-
result = self.chain({'few_shot':
|
|
|
96 |
return result
|
97 |
|
98 |
def decode_response(self, response):
|
@@ -184,6 +183,6 @@ def init_instance(seed_file, openai_key, n_human, n_machine, n_instruct, prompt)
|
|
184 |
def generate_instruction(self_instance):
|
185 |
keep_instruct_data = self_instance.step()
|
186 |
|
187 |
-
return (
|
188 |
json.dumps(keep_instruct_data, ensure_ascii=False),
|
189 |
f'已生成{self_instance.n_gen} 可用{self_instance.n_keep}')
|
|
|
47 |
self.scorer = None # rougeL用于文本相似度计算
|
48 |
self.all_instruction_tokens = [] # 全部指令,用于新指令消重
|
49 |
self.all_instruction = [] # 全部指令,用于新指令消重
|
50 |
+
self.sample_few_shot = None #每轮few-shot采样填充成prompt,for gradio
|
51 |
self.load_seed_task(seed_file)
|
52 |
self.init(prompt)
|
53 |
|
|
|
87 |
seed_sample = random.sample(self.human_instruction_data, self.n_human)
|
88 |
machine_sample = random.sample(self.machine_instruction_data,
|
89 |
min(self.n_machine, len(self.machine_instruction_data)))
|
|
|
90 |
# build few-shot
|
91 |
+
self.sample_few_shot = gen_few_shot_prompt(seed_sample + machine_sample)
|
|
|
92 |
# generate
|
93 |
+
result = self.chain({'few_shot': self.sample_few_shot + SELF.prefix.format(id=self.first_id), # 待生成指令id
|
94 |
+
'n_instruct': self.n_instruct})
|
95 |
return result
|
96 |
|
97 |
def decode_response(self, response):
|
|
|
183 |
def generate_instruction(self_instance):
|
184 |
keep_instruct_data = self_instance.step()
|
185 |
|
186 |
+
return (self_instance.sample_few_shot,
|
187 |
json.dumps(keep_instruct_data, ensure_ascii=False),
|
188 |
f'已生成{self_instance.n_gen} 可用{self_instance.n_keep}')
|