Views
No views yet
1# Import library
2import torch
3from transformers import AutoTokenizer, AutoModelForCausalLM
4
5# Load model
6model_name = "HachiML/Swallow-MS-7b-v0.1-MathSkill-OpenMath"
7tokenizer = AutoTokenizer.from_pretrained(model_name)
8model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.bfloat16, device_map="auto")
9
10# Inference 1
11prompt = "Natalia sold clips to 48 of her friends in April, and then she sold half as many clips in May. How many clips did Natalia sell altogether in April and May?\n"
12input_ids = tokenizer.encode(prompt, add_special_tokens=False, return_tensors="pt")
13tokens = model.generate(input_ids.to(device=model.device), max_new_tokens=256, temperature=0.99, top_p=0.95, do_sample=True)
14out = tokenizer.decode(tokens[0], skip_special_tokens=True)
15print(out)
16
17# Inference 2
18prompt = "ナタリアは4月に48人の友人にクリップを売り、5月にはその半分の数のクリップを売った。ナタリアが4月と5月に売ったクリップの数は?:\n"
19input_ids = tokenizer.encode(prompt, add_special_tokens=False, return_tensors="pt")
20tokens = model.generate(input_ids.to(device=model.device), max_new_tokens=256, temperature=0.99, top_p=0.95, do_sample=True)
21out = tokenizer.decode(tokens[0], skip_special_tokens=True)
22print(out)Natalia sold clips to 48 of her friends in April, and then she sold half as many clips in May. How many clips did Natalia sell altogether in April and May?\nLet's solve this problem using Python code.
<llm-code>
friends_sold_in_April = 48
friends_sold_in_May = friends_sold_in_April / 2
clips_sold_in_April_and_May = friends_sold_in_April + friends_sold_in_May
clips_sold_in_April_and_May
</llm-code>
<llm-code-output>
72.0
</llm-code-output>
Thus, in April and May, Natalia sold \boxed{72} clips in total.ナタリアは4月に48人の友人にクリップを売り、5月にはその半分の数のクリップを売った。ナタリアが4月と5月に売ったクリップの数は?:\nLet's solve this problem using Python code.
<llm-code>
clip_count = 48
clip_count_sold_4th_month = clip_count
clip_count_sold_5th_month = clip_count_sold_4th_month / 2
clip_count_sold_in_both_months = clip_count_sold_4th_month + clip_count_sold_5th_month
clip_count_sold_in_both_months
</llm-code>
<llm-code-output>
72.0
</llm-code-output>
So, the total number of clip sales is \textbf{72}.