opt-350m-alpaca / README.md
RootYuan's picture
Update README.md
5b5fb06
|
raw
history blame
2.74 kB
---
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.