ikedachin/llm-jp-4-8b-thinking-imabari-tragahana-v21

ikedachin/llm-jp-4-8b-thinking-imabari-tragahana-v21 is a Japanese dialogue model based on llm-jp/llm-jp-4-8b-base, trained with full-parameter supervised fine-tuning (SFT) (no LoRA/PEFT).
It supports four channels for Imabari dialect and standard Japanese, and three reasoning-effort levels (low/medium/high).
Japanese documentation follows below. / 日本語の説明は下にあります。
1. Key Features
1.1 Channels
The custom chat template supports four channels:
| Channel | Purpose | Language |
|---|---|---|
analysis_imabari | Reasoning | Imabari dialect |
final_imabari | Final response | Imabari dialect |
analysis | Reasoning | Standard Japanese |
final | Final response | Standard Japanese |
Available channels are specified using the valid_channels argument of tokenizer.apply_chat_template() (this does not strictly constrain generation).
Imabari dialect example:
valid_channels = ["analysis_imabari", "final_imabari", "commentary"]
Standard Japanese example:
valid_channels = ["analysis", "final", "commentary"]
1.2 Reasoning Effort
You can control the intended reasoning verbosity with reasoning_effort:
| Level | Value | Intended behavior |
|---|---|---|
| Low | low | Short reasoning |
| Medium | medium | Moderate reasoning |
| High | high | Detailed reasoning |
Example:
reasoning_effort="high"
Note: this is a conditioning signal and does not guarantee output length, correctness, or compliance.
2. Inference
Minimal example to switch language channels and reasoning effort:
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
MODEL_ID = "ikedachin/llm-jp-4-8b-thinking-imabari-tragahana-v21"
LANGUAGE = "imabari" # "imabari" or "standard"
REASONING_EFFORT = "medium" # "low", "medium", "high"
tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
model = AutoModelForCausalLM.from_pretrained(
MODEL_ID,
dtype=torch.bfloat16 if torch.cuda.is_available() else torch.float32,
device_map="auto",
).eval()
if LANGUAGE == "imabari":
analysis_channel, final_channel = "analysis_imabari", "final_imabari"
elif LANGUAGE == "standard":
analysis_channel, final_channel = "analysis", "final"
else:
raise ValueError("Invalid LANGUAGE")
messages = [{"role": "user", "content": "今治市について教えてください。"}]
prompt = tokenizer.apply_chat_template(
messages,
valid_channels=[analysis_channel, final_channel, "commentary"],
reasoning_effort=REASONING_EFFORT,
add_generation_prompt=True,
tokenize=False,
)
inputs = tokenizer(prompt, return_tensors="pt", add_special_tokens=False).to(model.device)
with torch.inference_mode():
outputs = model.generate(
**inputs,
max_new_tokens=2048,
do_sample=False,
eos_token_id=tokenizer.eos_token_id,
pad_token_id=tokenizer.pad_token_id,
)
generated = outputs[0][inputs["input_ids"].shape[-1]:]
print(tokenizer.decode(generated, skip_special_tokens=False))
Notes
- Always use the tokenizer shipped with this model (it includes the custom
chat_template). - Pass
valid_channelsandreasoning_effortasapply_chat_template()arguments (not insidemessages).
3. Training
3.1 Training Overview
- Full-Parameter SFT (no LoRA/PEFT)
- BF16
- Max sequence length: 8192
- Assistant-only loss (system/user tokens are context; loss targets assistant-side tokens only)
3.2 Training Datasets
| Dataset | Description |
|---|---|
| Imabari Wiki QA v4 | General QA in Imabari dialect |
| Standard Japanese Wiki QA v4 | General QA in standard Japanese |
| Imabari Wiki QA v5 Difficult | Difficult reasoning QA in Imabari dialect |
| Standard Japanese Wiki QA v5 Difficult | Difficult reasoning QA in standard Japanese |
| AnswerCarefully | Japanese safety / instruction-following data |
AnswerCarefully configs used: v3.0, borderline-v1.0, v2.2, v2.0, v1.0.
For AnswerCarefully, dev is used for training and test for validation.
3.3 Key Hyperparameters
| Parameter | Value |
|---|---|
| Base Model | llm-jp/llm-jp-4-8b-base |
| Training Method | Full Fine-Tuning (SFT) |
| Precision | BF16 |
| Learning Rate | 5e-5 |
| Epochs | 1 |
| Maximum Training Sequence Length | 8192 |
| Batch Size / GPU | 1 |
| Gradient Accumulation | 16 |
| Optimizer | AdamW |
| LR Scheduler | Cosine |
| Warmup | 5% of total optimizer steps |
| Gradient Checkpointing | Enabled |
| Seed | 42 |
4. Important: Initialization of Some Special-Token Input Embeddings
This model relies on the following special tokens used by the custom chat template:
<|start|><|end|><|message|><|channel|><|call|>
In the training script, the input embedding vectors for these tokens are explicitly initialized right after loading the base model.
This was necessary because training could become unstable / fail when these token embeddings remained in their original initial state.
Overview of the initialization procedure
- Randomly sample “normal token” input embeddings and build a new initial vector from their mean direction plus noise.
- Scale the initial norm to
CHAT_TOKEN_EMBEDDING_NORM = 0.1before training starts. - Check that these token IDs do not overlap with protected special IDs (BOS/EOS/PAD/UNK).
5. Limitations
- Channel selection: The model may mix channels or mix Imabari dialect and standard Japanese.
- Reasoning effort: The specified level does not guarantee output length or reasoning quality.
- Repetitive generation (Doom Loop): Repetition or missing EOS may occur; frequency in v21 is not yet evaluated.
- Accuracy: Generated reasoning and answers may contain errors.
6. Framework versions
- TRL: 1.13.0
- Transformers: 5.17.0
- PyTorch: 2.14.0
- Datasets: 5.0.1
- Tokenizers: 0.23.2
7. License / Terms
This model was trained using sources with different licenses and terms of use:
| Source | License / Terms |
|---|---|
| llm-jp/llm-jp-4-8b-base | CC BY-SA 4.0 |
| Imabari and standard Japanese QA datasets | CC BY-SA 4.0 |
| AnswerCarefully | AnswerCarefully Dataset Terms of Use |
AnswerCarefully has specific usage restrictions and redistribution constraints.
Please review upstream terms before using or redistributing this model. Dataset licenses do not automatically determine the license of trained model weights.
日本語説明
ikedachin/llm-jp-4-8b-thinking-imabari-tragahana-v21 は、llm-jp/llm-jp-4-8b-base をベースに、Full-Parameter SFT(LoRA/PEFTなし)で学習した日本語対話モデルです。
今治弁・標準語の4チャンネルと、**Reasoning Effort(low/medium/high)**の指定に対応します。
1. 主要機能
1.1 Channels(チャンネル)
独自のChat Templateにより、以下の4種類のチャンネルを扱います。
| Channel | 用途 | 言語 |
|---|---|---|
analysis_imabari | 推論(思考) | 今治弁 |
final_imabari | 最終回答 | 今治弁 |
analysis | 推論(思考) | 標準語 |
final | 最終回答 | 標準語 |
利用可能なチャンネルは tokenizer.apply_chat_template() の valid_channels で指定します(出力を厳密に強制するものではありません)。
今治弁の例:
valid_channels = ["analysis_imabari", "final_imabari", "commentary"]
標準語の例:
valid_channels = ["analysis", "final", "commentary"]
1.2 Reasoning Effort(推論量指定)
reasoning_effort により推論量の目安を指定できます。
| Level | 値 | 意図 |
|---|---|---|
| Low | low | 短め |
| Medium | medium | 標準 |
| High | high | 長め・丁寧 |
例:
reasoning_effort="high"
※これは条件付けであり、出力長や正確性を保証するものではありません。
2. 推論(Inference)
以下は、チャンネルと言語・Reasoning Effortを切り替えて推論する最小例です。
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
MODEL_ID = "ikedachin/llm-jp-4-8b-thinking-imabari-tragahana-v21"
LANGUAGE = "imabari" # "imabari" or "standard"
REASONING_EFFORT = "medium" # "low", "medium", "high"
tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
model = AutoModelForCausalLM.from_pretrained(
MODEL_ID,
dtype=torch.bfloat16 if torch.cuda.is_available() else torch.float32,
device_map="auto",
).eval()
if LANGUAGE == "imabari":
analysis_channel, final_channel = "analysis_imabari", "final_imabari"
elif LANGUAGE == "standard":
analysis_channel, final_channel = "analysis", "final"
else:
raise ValueError("Invalid LANGUAGE")
messages = [{"role": "user", "content": "今治市について教えてください。"}]
prompt = tokenizer.apply_chat_template(
messages,
valid_channels=[analysis_channel, final_channel, "commentary"],
reasoning_effort=REASONING_EFFORT,
add_generation_prompt=True,
tokenize=False,
)
inputs = tokenizer(prompt, return_tensors="pt", add_special_tokens=False).to(model.device)
with torch.inference_mode():
outputs = model.generate(
**inputs,
max_new_tokens=2048,
do_sample=False,
eos_token_id=tokenizer.eos_token_id,
pad_token_id=tokenizer.pad_token_id,
)
generated = outputs[0][inputs["input_ids"].shape[-1]:]
print(tokenizer.decode(generated, skip_special_tokens=False))
注意点
- 必ず本モデルに同梱されたtokenizer(chat_template)を使用してください。
valid_channelsとreasoning_effortはmessages内ではなくapply_chat_template()の引数として渡します。
3. 学習(Training)
3.1 学習方式の概要
- Full-Parameter SFT(LoRA/PEFTなし)
- BF16
- 最大系列長 8192
- Assistant-only Loss(system/user側は文脈として与え、損失はassistant側トークンのみを教師対象)
3.2 学習データ
| Dataset | 内容 |
|---|---|
| Imabari Wiki QA v4 | 今治弁の通常QA |
| Standard Japanese Wiki QA v4 | 標準語の通常QA |
| Imabari Wiki QA v5 Difficult | 今治弁の難問QA |
| Standard Japanese Wiki QA v5 Difficult | 標準語の難問QA |
| AnswerCarefully | 安全性関連の指示追従データ |
AnswerCarefullyは v3.0 / borderline-v1.0 / v2.2 / v2.0 / v1.0 を使用し、各構成の devを学習、testを検証に用いています。
3.3 主要ハイパーパラメータ
| 項目 | 設定 |
|---|---|
| Base Model | llm-jp/llm-jp-4-8b-base |
| Training | Full Fine-Tuning (SFT) |
| Precision | BF16 |
| Learning Rate | 5e-5 |
| Epochs | 1 |
| Max Training Sequence Length | 8192 |
| Batch Size / GPU | 1 |
| Gradient Accumulation | 16 |
| Optimizer | AdamW |
| LR Scheduler | Cosine |
| Warmup | 総更新ステップの5% |
| Gradient Checkpointing | 有効 |
| Seed | 42 |
4. 重要: 一部スペシャルトークンEmbeddingの初期化について(学習手順上の注意)
本モデルの学習では、独自Chat Templateで使用する以下のスペシャルトークンを前提とします。
<|start|><|end|><|message|><|channel|><|call|>
学習スクリプトでは、学習開始時(base modelロード直後)に、上記トークンの入力Embeddingベクトルを明示的に初期化しています。
これは、これらのトークンのEmbeddingが初期状態のままだと、学習が不安定化・失敗するケースがあったためです(スクリプト上の対処)。
一部のスペシャルトークンの初期化の概要
- 参照用に「通常トークン」のEmbeddingをランダムサンプルし、その平均方向+ノイズから初期ベクトルを作りなおしています。
- 初期ノルムは
CHAT_TOKEN_EMBEDDING_NORM = 0.1にスケーリングして設定してから学習を開始しています。 - BOS/EOS/PAD/UNKなど、保護対象の特殊IDと重複していないことをチェックしています。
5. 制限事項(Limitations)
- チャンネル混在: 指定した言語(今治弁/標準語)やチャンネルが混ざる場合があります。
- Reasoning Effort: 出力長や推論品質を保証するものではありません。
- 反復生成(Doom Loop): 系列によっては繰り返し生成やEOS未生成が起きる可能性があります(v21での頻度は未評価)。
- 正確性: 生成される推論・回答には誤りが含まれる可能性があります。
6. 実行環境(Framework versions)
- TRL: 1.13.0
- Transformers: 5.17.0
- PyTorch: 2.14.0
- Datasets: 5.0.1
- Tokenizers: 0.23.2
7. ライセンス・利用条件(License / Terms)
本モデルは複数ソースから学習しており、各ソースに異なるライセンス・利用条件が適用されます。
| 対象 | ライセンス・利用規約 |
|---|---|
| llm-jp/llm-jp-4-8b-base | CC BY-SA 4.0 |
| 今治弁・標準語QAデータセット | CC BY-SA 4.0 |
| AnswerCarefully | AnswerCarefully Dataset Terms of Use |
AnswerCarefullyには、LLMの安全性向上を目的とした利用への制限等、独自の条件があります。また元データセットの再配布は禁止されています。
本モデルの利用・再配布に際しては、上流の条件を確認してください。学習データのライセンスが学習済み重みに自動的に適用されると断定するものではありません。
Model: ikedachin/llm-jp-4-8b-thinking-imabari-tragahana-v21
Base Model: llm-jp/llm-jp-4-8b-base
Author: ikedachin