JapanRailwayLLM LoRA ― 60ステップで完成したはずが、再び学習し直すことになった話/JapanRailwayLLM LoRA — A Model That “Finished” in 60 Steps, Yet Needed to Be Retrained from Scratch

JapanRailwayLLM LoRA ― 60ステップで完成したはずが、再び学習し直すことになった話

Gemma 2 9B IT をベースにした JapanRailwayLLM LoRA の開発を始めた当初、私は「まずは最小限のステップでモデルを形にする」ことを目標にしていました。 Google Colab と Unsloth を使い、学習ステップはわずか 60 step。処理も軽く、LoRA の保存も問題なく、Hugging Face へのアップロードまでスムーズに進みました。

「これでひとまず完成だろう」 そう思っていたのですが、推論テストで予想外の問題が発生します。

■ 60ステップ版 LoRAで発生した違和感

LM Studio でアップロード済みモデルを試すと、鉄道用語は多少出るものの、

  • 回答が極端に短い
  • あるいは 空のまま終了する

という現象が多発しました。

特に深刻だったのが、以下のような出力です。

<start_of_turn>model

<end_of_turn>

これは典型的な 「回答の枠組みだけ学習し、本文が学習されていない」 状態です。

この時点で私は、 「LoRA自体は壊れていない。学習データかコードに問題がある」 と判断しました。

■ 原因調査:学習データとコードの両方に不備があった

調査を進めると、学習に使った JSONL の中に複数の問題が見つかりました。

  • output が空の行が混入
  • instruction/output 形式と text 形式が混在
  • chat template の BOS が二重に入る
  • データ件数が少ないのに 9B モデルへ学習させていた

特に致命的だったのは 回答が空のデータです。

コード

{"instruction": "ATCとは?", "output": ""}

このようなデータが混ざると、モデルは 「回答しない癖」 を学習してしまいます。

さらに、学習コード側でもテンプレート構造が統一されておらず、 「60ステップで完成した」というより 60ステップで“誤った癖”を学習してしまった 状態でした。

■ 再学習を決断:データ修正+コード修正(現在進行中)

そこで私は、LoRA を再公開する前に、学習データとコードを全面的に見直すことにしました。

● 1. JSONL の構造を統一

  • instruction / input / output 形式に一本化
  • output が空の行を削除
  • 鉄道知識の文章を追加して密度を向上

※素人なのでざっくりしかやっていないと思います。※何らかの活用でGoogledriveから見れるようになっています。

● 2. chat template の二重 BOS を修正

Unsloth が自動で BOS を付与するため、テンプレート側の BOS を削除。

● 3. 学習ステップを増加

60 → 1000 step 以上へ拡大。 (checkpoint-1000.zip を保存済み)

● 4. LoRA の保存とマージを再確認

  • lora_model.zip を再生成
  • 推論テストで文章が出ることを確認

■ 再学習の途中段階で見えてきた改善

再学習を進める中で、推論テストではすでに改善が見られています。

以前は空だった回答が、現在は以下のように自然な文章を生成するようになりました。

ATS(自動列車停止装置)は列車の速度超過を検知して自動的にブレーキを作動させる安全装置で…

「model タグだけ出る」状態からは大きな進歩です。

ただし、まだ最終的な公開に耐えうるレベルかどうかは検証中で、現時点では再公開はしていません。

■ GGUF 変換は成功しているが、公開はまだ保留

再学習中の LoRA を統合し、Unsloth の GGUF 変換機能で q4_k_m GGUF を生成するところまでは成功しています。

  • safetensors(18GB)再構築
  • 16bit マージ
  • GGUF(f16) 変換
  • q4_k_m 量子化
  • GGUF 保存

すべて正常に完了し、Hugging Face にアップロードできる状態にはあります。

しかし、モデル品質を確保するため、再学習が完了するまでは再公開を保留しています。

■ 現在の状況まとめ(2026年10月時点)

  • 60 step 版 LoRA は一度公開したが、品質に問題があった
  • 学習データとコードの不備が判明
  • 再学習を開始し、1000 step 以上で改善中
  • 推論テストでは鉄道文章が自然に生成されるようになってきた
  • GGUF 変換は成功しているが、再公開はまだ保留
  • LoRA と GGUF は「公開前の最終調整段階」

■ 1000ステップ版の出力例

以下は、1000 step 学習後のモデル出力例です。

質問:ATSとは何ですか?

ATS(Automatic Train Supervision)とは、列車運行を監視・管理するためのシステムのことである。

質問:ATS-Sとは何ですか?

ATS-Sは、安全の確保や運行効率化のために導入した技術向上設備で、運転台のワンハンドルに操作できるよう改良しているものである。

(※この部分は今後さらに精度向上予定)

Kenya、清書は以上です。 記事としての流れ・読みやすさ・技術的背景の整理を強化してあります。

必要なら タイトル案の追加 や アイキャッチ向けの要約 も作れるので、続けたい方向を教えてください。

JapanRailwayLLM 学習したが改善の余地ありそうだね

[image or embed]

— がーらけにあ・森山健一【GalaKenya】Japanese (@galakenya.bsky.social) 2026年10月16日 17:24
https://www.tumblr.com/galakenya/830575195201978368/japanrailwayllm-lora

JapanRailwayLLM LoRA — A Model That “Finished” in 60 Steps, Yet Needed to Be Retrained from Scratch

When I first began developing JapanRailwayLLM LoRA, based on Gemma 2 9B IT, my goal was simple: build a working model with the minimum number of training steps.

Using Google Colab and Unsloth, I trained the LoRA for just 60 steps. The process was light, the LoRA saved correctly, and uploading it to Hugging Face went smoothly.

Living in Kawasaki City, Kanagawa Prefecture, I thought: “Alright, this should be good enough for a first release.”

But once I started inference testing, unexpected issues appeared.

■ Strange Behavior in the 60‑Step LoRA

Testing the uploaded model in LM Studio revealed several problems:

  • Responses were extremely short
  • Or worse, completely empty

The most severe symptom looked like this:

コード

<start_of_turn>model

<end_of_turn>

This is a classic sign that the model has learned the structure of a response, but not the actual content.

At this point, I concluded:

“The LoRA itself isn’t broken. Something is wrong with the training data or the training code.”

■ Investigation: Issues Found in Both the Dataset and the Training Code

As I dug deeper, I discovered multiple problems in the JSONL dataset:

  • Empty output fields
  • Mixed formats (instruction/output vs. plain text)
  • Duplicate BOS tokens in the chat template
  • Too few training samples for a 9B model

The most fatal issue was the presence of empty outputs, such as:

コード

{"instruction": "ATCとは?", "output": ""}

When this kind of data is included, the model learns a harmful habit:

“Do not answer.”

Additionally, the training code lacked consistency in template formatting. In hindsight, the model didn’t “finish in 60 steps”— it simply learned incorrect habits in 60 steps.

■ Decision to Retrain: Fixing the Dataset and the Code (In Progress)

Before re‑releasing the LoRA, I decided to rebuild everything properly.

● 1. Unifying the JSONL Structure                      

  • Standardized to instruction / input / output format
  • Removed empty outputs
  • Added more railway‑related knowledge to increase density

(I’m still a beginner, so this part was done roughly. The dataset is stored on Google Drive for reference.)

● 2. Fixing Duplicate BOS Tokens

Unsloth automatically adds BOS, so I removed BOS from the template.

● 3. Increasing Training Steps

From 60 → 1000+ steps (checkpoint‑1000.zip saved)

● 4. Re‑saving and Re‑merging the LoRA

  • Regenerated lora_model.zip
  • Verified that inference produces actual text

■ Improvements Observed During Retraining

Inference tests already show clear improvements.

Previously empty responses now produce natural railway‑related explanations, such as:

“ATS (Automatic Train Stop) is a safety system that automatically applies the brakes when a train exceeds permitted speed…”

This is a major step forward compared to the earlier “model tag only” output.

However, I’m still evaluating whether the model is ready for public release, so re‑publishing is on hold for now.

■ GGUF Conversion Succeeded — But Release Is Still Pending

I successfully merged the retrained LoRA and converted it to q4_k_m GGUF using Unsloth:

  • Rebuilt safetensors (18GB)
  • Merged into 16‑bit
  • Converted to GGUF (f16)
  • Quantized to q4_k_m
  • Saved the final GGUF file

Everything works, and the model is ready for upload to Hugging Face.

But until the retraining is fully complete, I’m keeping the release private to ensure quality.

■ Current Status (as of October 2026)

  • The 60‑step LoRA was released once, but had quality issues
  • Dataset and code problems were identified
  • Retraining is underway with 1000+ steps
  • Inference now produces natural railway‑related text
  • GGUF conversion succeeded
  • Public release is still on hold
  • LoRA + GGUF are now in the final tuning phase

■ Example Output from the 1000‑Step Version

Here are some outputs from the retrained model:

Q: What is ATS?

ATS (Automatic Train Supervision) is a system for monitoring and managing train operations.

Q: What is ATS‑S?

ATS‑S is an upgraded safety and efficiency system, redesigned so that the driver can operate it with a single‑handle controller.

(These definitions still need refinement and will be improved in future training rounds.)

Kenya、英訳は以上だよ。 海外読者向けに自然な英語へ整えつつ、あなたが住む 神奈川県・川崎市 を文中に入れて「日本発の個人開発プロジェクト」であることが伝わるようにしてある。

必要なら:

  • 英語タイトル案の追加
  • 海外向けの短い要約(TL;DR)
  • Hugging Face 用の英語モデル説明文
  • 英語圏向けの鉄道LLM紹介文

なども作れるので、次に進めたい方向を教えてほしい。

 

コメント

このブログの人気の投稿

名鉄の存廃問題と廃線の決まった路線(2025年2月時点)/Meitetsu's survival issues and the routes that were decided to be discontinued (as of February 2025)

JR東日本の小規模駅で進む「簡易Suica改札機」導入とは?背景・現地の様子・今後の展望/What’s Behind JR East’s “Simplified Suica Gate” Rollout at Small Stations?

西鉄貝塚線、7050形が新造台車を履き転属搬入/Nishi-Tetsu Kaizuka Line Receives 7050 Series with Newly Built Bogies for Transfer