Views
No views yet
1from transformers import AutoModelForCausalLM, AutoTokenizer
2
3
4model = AutoModelForCausalLM.from_pretrained('chincyk/PyCodeGen')
5tokenizer = AutoTokenizer.from_pretrained('chincyk/PyCodeGen')
6
7instruction = "Write a python class that represents a calculator, then use it to add two numbers."
8input = "a = 5, b = 2"
9
10prompt = f"""
11 ### Instruction:
12 Use the Task below and the Input given to write the Response, which is a programming code that can solve the Task.
13
14 ### Task:
15 {instruction}
16
17 ### Input:
18 {input}
19
20 ### Response:
21 """
22
23input_ids = tokenizer(prompt, truncation=True, return_tensors="pt")['input_ids']
24output = model.generate(input_ids=input_ids, max_length=200)
25
26print(tokenizer.decode(output[0], skip_special_tokens=True))
27