forked from daveshap/AlignmentConsequences
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_nlpcloud.py
More file actions
23 lines (17 loc) · 1.12 KB
/
test_nlpcloud.py
File metadata and controls
23 lines (17 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import nlpcloud
from time import time
def open_file(filepath):
with open(filepath, 'r', encoding='utf-8') as infile:
return infile.read()
def save_file(filepath, content):
with open(filepath, 'w', encoding='utf-8') as outfile:
outfile.write(content)
if __name__ == '__main__':
client = nlpcloud.Client("finetuned-gpt-neox-20b", "TOKEN HERE", gpu=True, lang="en") # dont forget to update your token
functions = open_file('objective_functions.txt').splitlines()
for f in functions:
prompt = open_file('prompt_consequences.txt').replace('<<FUNCTION>>', f)
result = client.generation(prompt,min_length=10,max_length=500,length_no_input=True,remove_input=False,end_sequence=None,top_p=1,temperature=0.7,top_k=50,repetition_penalty=1,length_penalty=1,do_sample=True,early_stopping=False,num_beams=1,no_repeat_ngram_size=0,num_return_sequences=1,bad_words=None,remove_end_sequence=False)
print('\n\n',result['generated_text'])
filename = 'neox_%s_%s.txt' % (f.replace('To','').replace(' ','')[0:16], time())
save_file('results/%s' % filename, result['generated_text'])