Views
No views yet
model.half() before moving to device)1import torch
2from transformers import AutoTokenizer, AutoModelForCausalLM
3
4model_path = "MerlynMind/merlyn-education-teacher-assistant"
5device = torch.device("cuda:0") # change device id as necessary
6model = AutoModelForCausalLM.from_pretrained(model_path)
7tokenizer = AutoTokenizer.from_pretrained(model_path, fast_tokenizer=True)
8model.to(device) # move to device1conversation = ''''user1':\tHow do some gases help keep the Earth warm?
2'user2':\tSome gases, called greenhouse gases, act like a blanket around Earth by trapping heat from the sun in the atmosphere, which keeps our planet warm. This process is known as the greenhouse effect.
3'user1':\tHow can we reduce greenhouse gas emissions?
4'user2':\tWe can reduce greenhouse gas emissions by using renewable energy sources, increasing energy efficiency, and reducing waste.'''
5
6prompt = tokenizer.bos_token
7prompt += '''Instruction:\tYou are teaching high school students.
8Instruction:\tYou are observing the following conversation between two users.
9Instruction:\tGenerate 3 research activities based on the conversation.
10Instruction:\tThe research activities should be doable by high school students.
11Instruction:\tYour response should be a well-formed JSON array of 3 objects, each with a 'title' property and an 'activity' property.
12
13Conversation:''' + f"\n{conversation}" + " Response:"1inputs = tokenizer(prompt, return_tensors="pt").to(device)
2generate_ids = model.generate(
3 **inputs,
4 max_new_tokens=1024,
5 temperature=0.0,
6 num_beams=2
7)
8response = tokenizer.decode(generate_ids[0],
9 skip_special_tokens=True,
10 clean_up_tokenization_spaces=True)1[
2{"title": "Understanding the Greenhouse Effect", "activity": "Research the greenhouse effect and the role of greenhouse gases in keeping Earth warm. Create a presentation or poster explaining the greenhouse effect and how greenhouse gases act as a blanket around Earth."},
3{"title": "Renewable Energy Sources", "activity": "Identify different renewable energy sources, such as solar, wind, and geothermal energy, and explain how they can help reduce greenhouse gas emissions."},
4{"title": "Energy Efficiency and Waste Reduction", "activity": "Research energy efficiency and waste reduction practices, and develop a plan to implement these practices in your school or community to reduce greenhouse gas emissions."}
5]@online{MerlynEducationModels,
author = {Merlyn Mind AI Team},
title = {Merlyn Mind's education-domain language models},
year = {2023},
url = {https://www.merlyn.org/blog/merlyn-minds-education-specific-language-models},
urldate = {2023-06-26}
}