-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathOPT.py
More file actions
32 lines (23 loc) · 927 Bytes
/
OPT.py
File metadata and controls
32 lines (23 loc) · 927 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from transformers import pipeline, set_seed
import sys
models = ["opt-125m", "opt-350m", "opt-1.3b", "opt-2.7b", "opt-6.7b", "opt-13b", "opt-30b", "opt-66b"]
current_model_name = "facebook/" + models[0]
def process_bot_answer(input_text, seed=None):
if seed is None:
generator = pipeline('text-generation', model=current_model_name)
else:
set_seed(seed)
generator = pipeline('text-generation', model=current_model_name, do_sample=True)
return generator(input_text)[0]["generated_text"]
def main():
if len(sys.argv) < 2:
print("Please provide a text prompt as the first argument or a text prompt and a seed.")
return
if len(sys.argv) == 2:
answer = process_bot_answer(sys.argv[1])
elif len(sys.argv) == 3:
answer = process_bot_answer(sys.argv[1], int(sys.argv[2]))
print(answer)
return answer
if __name__ == '__main__':
main()