Views
No views yet

{token_config.unk_token}{token_config.bos_token}{token_config.eos_token}{token_config.pad_token}{token_config.cls_token}{token_config.sep_token}{token_config.mask_token}{token_config.system_token} and {token_config.system_end_token}{token_config.user_token} and {token_config.user_end_token}{token_config.assistant_token} and {token_config.assistant_end_token}{token_config.reasoning_token} and {token_config.reasoning_end_token}{token_config.solution_token} and {token_config.solution_end_token}{token_config.response_token} and {token_config.response_end_token}{token_config.hint_token} and {token_config.hint_end_token}{token_config.note_token} and {token_config.note_end_token}{token_config.context_token} and {token_config.context_end_token}{token_config.reference_token} and {token_config.reference_end_token}{token_config.example_token} and {token_config.example_end_token}{token_config.important_token} and {token_config.important_end_token}{token_config.warning_token} and {token_config.warning_end_token}{token_config.error_token} and {token_config.error_end_token}1from transformers import AutoModelForCausalLM, AutoTokenizer
2
3model = AutoModelForCausalLM.from_pretrained("{model_name}")
4tokenizer = AutoTokenizer.from_pretrained("{model_name}")
5
6# チャット形式での使用例
7messages = [
8 {
9 "role": "system",
10 "content": "あなたは親切で有能なAIアシスタントです。"
11 },
12 {
13 "role": "user",
14 "content": "次の数学の問題を解いてください:2x + 3 = 7"
15 },
16 {
17 "role": "hint",
18 "content": "方程式を解くときは、まず両辺から数を移項することを考えてみましょう。"
19 },
20 {
21 "role": "reasoning",
22 "content": "この方程式を解くために以下のステップで考えます:\\n1. 3を両辺から引く\\n2. 両辺を2で割る"
23 },
24 {
25 "role": "assistant",
26 "content": "x = 2 が方程式の解です。"
27 }
28]
29
30# チャットテンプレートを使用してメッセージを整形
31prompt = tokenizer.apply_chat_template(messages, tokenize=False)
32print("\\nGenerated prompt:\\n", prompt)
33
34# トークン化と推論
35inputs = tokenizer(prompt, return_tensors="pt", max_length=2048, truncation=True)
36outputs = model.generate(**inputs, max_length=2048, temperature=0.7)
37response = tokenizer.decode(outputs[0])
38print("\\nModel response:\\n", response)
## Chat Template Specification
モデルのチャットテンプレートは以下の要素を含みます:
- 5つの異なるロール(system, user, hint, reasoning, assistant)
- 各ロールに対応する特殊トークン
- デフォルトのシステムメッセージ
- 柔軟なテンプレート構造
特徴:
- メッセージの順序は保持されます
- 各ロールは明確に区別されます
- システムメッセージは任意です
- ヒントと推論は必要に応じて追加できます
## Additional Notes
### トークナイザーの拡張について
- 元のトークナイザーの全機能を保持
- 新しい特殊トークンの追加による機能拡張
- チャットテンプレートによる構造化された会話のサポート
### 使用上の注意
- 特殊トークンは必要な場合にのみ使用してください
- 特殊トークのスキップをTrueにしないでください.
- チャットテンプレートは柔軟に調整可能です
- システムメッセージは対話の文脈に応じてカスタマイズできます