File size: 2,738 Bytes
b5b20b9
 
 
c8b111b
656f295
 
 
 
 
 
c8b111b
656f295
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ad680d9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5b5fb06
 
ad680d9
 
 
 
 
 
 
 
 
 
 
 
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
---
license: apache-2.0
---

````
from transformers import AutoTokenizer, AutoModelForCausalLM

tokenizer = AutoTokenizer.from_pretrained("RootYuan/opt-350m-alpaca")
model = AutoModelForCausalLM.from_pretrained("RootYuan/opt-350m-alpaca")
````
usage:
````
instruction = "Classify the following into animals, plants, and minerals"
input = "Oak tree, copper ore, elephant"

prompts_no_input = f"### Instruction:\n{instruction}\n\n### Response:"
prompts_with_input = f"### Instruction:\n{instruction}\n\n### Input:\n{input}\n\n### Response:"
prompts = prompts_no_input if input is None else prompts_with_input

inputs = tokenizer.encode(prompts, return_tensors="pt")
outputs = model.generate(inputs, max_new_tokens=64)
ans = tokenizer.decode(outputs[0]).strip('</s>')[len(prompts):]
if input is None:
    print(f"Human: {instruction}")
else:
    print(f"Human: {instruction}\nInput: {input}")
print(f"Assistant: {ans}")
````
outputs:
````
Human: Classify the following into animals, plants, and minerals
Input: Oak tree, copper ore, elephant
Assistant: Oak tree: Plant
           Copper ore: Mineral
           Elephant: Animal
````

Other Examples:  
**Human:** Say 'Hi'  
**Assistant:** Hi! How can I help you today?

**Human:** Give me three helpful tips about health  
**Assistant:** 1. Eat a balanced diet.
2. Get enough sleep.
3. Exercise regularly.

**Human:** Generate a list of ten items a person might need for a camping trip  
**Assistant:** 1. Tent
2. Sleeping bag
3. Flashlight
4. Matches
5. First Aid Kit
6. Matches
7. Flashlight
8. Matches
9. Water Bottle
10. Matche

**Human:** Evaluate this sentence for spelling and grammar mistakes  
**Input:** He finnished his meal and left the resturant    
**Assistant:** He finished his meal and left the restaurant.

**Human:** Solve the following problem in python.  
**Input:** Given variable a and variable b, return then sum of the a and b.    
**Assistant:** sum = a + b  
               print(sum)

**Human:** Classify the following into animals, plants, and minerals  
**Input:** Oak tree, copper ore, elephant  
**Assistant:** Oak tree: Plant
 Copper ore: Mineral
 Elephant: Animal

**Human:** Do you know TikTok?  
**Assistant:** Yes, TikTok is an online video platform that is popular with users around the world. It is a platform that allows users to create and share short videos, and it has over 1 billion users worldwide.

**Human:** Discuss the causes of the Great Depression  
**Assistant:** The Great Depression was caused by a combination of factors, including a lack of economic growth, a decrease in consumer spending, and a decrease in the availability of credit. These factors combined to create a severe economic downturn that lasted for more than two decades.