File size: 1,861 Bytes
4cf4355
 
0583491
 
4cf4355
0583491
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b9f6b59
0583491
 
 
 
 
 
 
 
 
 
 
 
 
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
---
license: apache-2.0
language:
- ja
---
## モデルについて
与えられたテキストに関連するinstructionを生成するモデルです。

instructionデータセット作成にお役立てください。

不適切なinstructionが生成される可能性がありますので、出力のチェックは必須です。

詳細については[こちら](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/jimba-instruction-generator_RakutenAI-7B-instruct_lora"
)
model.eval()
input_text = "サンプルテキスト"
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=input_text), 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)」にて作成した成果物になります。