MakeInstruction / main.py
DSXiangLi
add self
66786b8
raw history blame
No virus
953 Bytes
# -*-coding:utf-8 -*-
"""
Run SELF
"""
import numpy as np
from self.generate import SELF
threshold = 0.7 # 当最近几个指令相似度都很高的时候停止
def main(seed_file, output_file, openai_key, n_human, n_machine, n_instruct, max_iter, max_gen):
instance = SELF(seed_file, openai_key, n_human, n_machine, n_instruct, None)
n_iter = 0
while n_iter < max_iter and instance.n_keep < max_gen:
instance.step()
n_iter +=1
print(f'已生成{instance.n_gen} 可用{instance.n_keep}')
if n_iter >3 and np.average([i['avg_similarity_score'] for i in instance.machine_instruction_data[-5:]] )> threshold:
break
# dump file
instance.dump_file(output_file)
if __name__ == '__main__':
seed_file = './ape/data/seed_task.json'
openai_key ='a'
n_human=2
n_machine=1
n_instruct=5
instance = SELF(seed_file, openai_key, n_human, n_machine, n_instruct, None)