File size: 1,866 Bytes
ad65b57
 
1a55dd0
 
ad65b57
1a55dd0
 
 
dd737ed
1a55dd0
dd737ed
1a55dd0
 
dd737ed
 
1a55dd0
 
 
 
a86a677
1a55dd0
 
a86a677
1a55dd0
 
a86a677
1a55dd0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dd737ed
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
---
license: apache-2.0
language:
- ja
---

## モデルについて
与えられたテーマに関する算数・数学の問題を作成するモデルです。

算数・数学系のデータセット作成にお役立てください。

生成された問題が破綻している可能性もありますので、出力のチェックは必須です。

詳細については[こちら](https://zenn.dev/kendama/articles/85ed50d31207bf)をご覧ください。

## 使い方

```python
from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel
model_path = "Rakuten/RakutenAI-7B-instruct"
tokenizer = AutoTokenizer.from_pretrained(model_path)
model = AutoModelForCausalLM.from_pretrained(model_path, torch_dtype=torch.bfloat16, device_map="auto")
model = PeftModel.from_pretrained(
    model,
    "Kendamarron/math-problem-generator_RakutenAI-7B-instruct_lora"
)
model.eval()

theme = "整数の四則演算"
system_message = """A chat between a curious user and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user's questions. USER: 次の要素を使った算数の文章問題を作成してください。
要素: {user_input} ASSISTANT: """

inputs = tokenizer(system_message.format(user_input=theme), return_tensors="pt").to(device=model.device)

with torch.no_grad():
    outputs = model.generate(
        **inputs,
        max_new_tokens=256,
        do_sample=True,
        temperature=0.8,
        eos_token_id=tokenizer.eos_token_id
)

print(tokenizer.decode(outputs[0],skip_special_tokens=True))
```

## 備考
Discordサーバー「ローカルLLMに向き合う会」とメタデータラボ株式会社が共同開催された「[LOCAL AI HACKATHON #000](https://prtimes.jp/main/html/rd/p/000000007.000056944.html)」にて作成した成果物になります。