JapanRailWayLLMシリーズ:JapanRailwayGuideWatcherに鉄道法令などを追加・更新/JapanRailWayLLM Series: Added Railway Regulations and Updates to JapanRailwayGuideWatcher

JapanRailWayLLMシリーズ:JapanRailwayGuideWatcherに鉄道法令などを追加・更新

日本の鉄道技術、鉄道工学、構造物、保安装置などの専門知識を学習させたGemma 4ベースの特化型LoRAモデル「JapanRailwayGuideWatcher」をHugging Faceにて公開しました。今回のアップデートでは、これまで不足していた鉄道法令やモデル自身の自己紹介(アイデンティティ)などの追加学習・修正を実施しています。

本記事では、開発のきっかけとなった背景やモデルの概要、データセット作成から学習完了までの経緯をまとめます。

開発の背景:なぜ鉄道特化LLMを作ったのか?

もともと日本の鉄道専門知識に特化したLLMが存在しなかったことに加え、「BVE5の路線制作が、サーバー構築の10倍は面倒くさい」という現実を目の当たりにしたことが開発の大きな原動力です。

鉄道シミュレーターの路線やデータを制作するにあたって必要となる日本の鉄道の基礎知識・法令・規格などを手軽に調べられるAIエージェントを目指し、国土交通省鉄道局などの公開資料を参考に学習を行いました。

また、この開発は自分ひとりの力だけではなく、Copilot・ChatGPT・ローカルLLM(LM Studio)と相談・連携しながらプロンプト調整やデータ整備を進めて構築しています。

JapanRailwayLLMのgemma4ベースのJapanRailwayguidewatcherは法令や自己紹介が欠けていたので若干学習しています。
日本の鉄道のLLMない上、BVE5路線制作するのにサーバー構築の10倍面倒くさいのを目の当たりにしたので、基礎知識・法令・規格などを学習した。
これは国交省鉄道局等からの資料を参考

— がーらけにあ【GalaKenya】 (@galakenya)

モデルの概要:JapanRailwayGuideWatcher

JapanRailwayGuideWatcher は、日本の鉄道技術資料・鉄道工学資料・構造物資料・保安装置資料・国交省鉄道局等の法令関連資料など、約11,500件の専門データを学習した特化型モデルです。

姉妹モデルである「JapanRailwayLLM(鉄道運用・技術全般)」に対し、本モデルはより技術・工学・設備・法令面の専門性に焦点を当てています。

主な学習分野

  • 鉄道土木・鉄道構造物・鉄道建築
  • 軌道工学
  • 信号保安装置
  • 電車線設備
  • 鉄道車両技術
  • 鉄道システム・鉄道保守技術・関連法令・規格

モデル仕様

  • ベースモデル: Google Gemma 4 E4B IT (google/gemma-4-E4B-it)
  • 学習方式: QLoRA / Unsloth / Hugging Face Transformers
  • 公開チェックポイント: checkpoint-7000 / checkpoint-7250(※一般利用には知識の定着率が最も高い checkpoint-7250 を推奨)
  • 推奨言語: 日本語(英語、繁体字中国語、韓国語、フランス語、スペイン語、ポルトガル語、ドイツ語にも対応していますが、日本語でのプロンプトで最も高い精度を発揮します)

想定される用途

  • BVE5などの鉄道シミュレーターゲーム制作の知識サポート・調査
  • 鉄道技術に関する質問応答・技術教育
  • 鉄道専門RAG(検索拡張生成)システムの構築
  • 鉄道研究支援・鉄道系アプリケーションの開発

開発の舞台裏:データセット作成と学習の記録

今回のモデル開発では、専門資料(PDF)から学習用のQAデータセット(JapanRailwayQA.jsonl)を自動生成し、ファインチューニングを行いました。

1. PDFからのQA生成と「チャンクサイズ」の壁

ローカルLLM環境(LM Studio)とPythonスクリプトを連携させ、技術資料のPDFからQAデータを生成するパイプラインを構築しましたが、初期段階では処理が「PDF Chunk: 0」で停止するトラブルに直面しました。

切り分けのためデバッグログを追加して調査したところ、LM Studioへのリクエスト送信までは成功しているものの、応答待ちでタイムアウトしていることが判明しました。

print(f"Chunkサイズ: {len(chunk)}")
print("LM Studio送信開始")

response = requests.post(
    LM_STUDIO_URL,
    json=payload,
    timeout=600
)

print("HTTP:", response.status_code)

原因は、1回あたりに送信するテキスト量(chunk_size)を 8000 に設定していたことでした。専門用語や図表の解説が密集する鉄道技術資料において、8000文字のチャンクはローカル環境での処理負荷が大きすぎたため、chunk_size = 1000 に引き下げ、モデル名指定(MODEL_NAME)をLM Studio側のロード名と厳密に一致させることで、安定したQA生成が可能になりました。

2. 法令関係と自己紹介データの補強・手作業による修正

LM Studioを用いて出力データの修正を進めましたが、特に鉄道法令関係のQAデータにおいてタイトルが「無題」ばかりになってしまう現象が発生していました。また、初期学習段階ではモデル自身の「自己紹介(JapanRailwayGuideWatcherとしての振る舞い)」や法令知識が不足していました。

そのまま学習させるとモデルの応答品質に影響するため、該当箇所は手作業で一つひとつ確認・修正を行い、法令関連データや自己紹介データを加えて追加学習を実施しています。

3. 7250ステップでの学習完了とマージ・GGUF形式について

整備した約11,500件のデータセットを用いて学習を進め、Loss(損失)の推移も良好だったことから、7250ステップにて本学習を完了としました。

公開形式についての注意点として、現時点ではLoRAアダプター形式のみを公開しており、GGUF形式へ変換したモデルは公開していません(やはりGGUF形式に処理しておかないと、なかなか手軽にはダウンロードしてもらえない実感もあります…!)。

ご利用の際は、Pythonスクリプト等を用いてベースモデル(google/gemma-4-E4B-it)とマージ(結合)していただくことで、ローカル環境や各種ツールでの活用の幅が大きく広がります。

マージ(結合:ベースはgemma4-E4B-IT)すれば活用は広がると思います。
マージはパイソン活用でやってるからね。

— がーらけにあ【GalaKenya】 (@galakenya)

JapanRailwayLLM
GGUFに処理しないとダウンロードしてくれないね。

— がーらけにあ【GalaKenya】 (@galakenya)

ご利用にあたっての注意事項(免責事項)

本モデルは、教育、研究、歴史的参照、鉄道ファンの活動、シミュレーター制作および鉄道工学の学習支援を目的として開発されています。

出力される回答には誤りが含まれる可能性があるため、実際の業務・運用や設計等に使用する際は、必ず鉄道事業者の公式発表、技術基準、法令、および安全規定と照らし合わせて検証してください。 本モデルは公式な工学判断や鉄道の安全手続きに代わるものではありません。

関連リンク



JapanRailwayLLMは日本の鉄道の知識を取り入れたAIエージェントになる。 日本の規格や法令を学んだやつになる。 鉄道シミュレーターゲームの制作の活用をしていただければ buff.ly/5M7EBUi

— がーらけにあ・森山健一【GalaKenya】Japanese (@galakenya.bsky.social) 2026年11月16日 18:24

マージ(結合:ベースはgemma4-E4B-IT)すれば活用は広がると思います。 マージはパイソン活用でやってるからね。

— がーらけにあ・森山健一【GalaKenya】Japanese (@galakenya.bsky.social) 2026年11月16日 18:24

自分自身単体でやってるわけではなくCopilot・chatGPT・ローカルLLM(LMスタジオ)と相談・活用しながら構築しました。

— がーらけにあ・森山健一【GalaKenya】Japanese (@galakenya.bsky.social) 2026年11月16日 18:24

JapanRailwayLLMのgemma4ベースのJapanRailwayguidewatcherは法令や自己紹介が欠けていたので若干学習しています。 日本の鉄道のLLMない上、BVE5路線制作するのにサーバー構築の10倍面倒くさいのを目の当たりにしたので、基礎知識・法令・規格などを学習した。 これは国交省鉄道局等からの資料を参考にしました。

— がーらけにあ・森山健一【GalaKenya】Japanese (@galakenya.bsky.social) 2026年11月16日 0:52

[English] JapanRailWayLLM Series: Added Railway Regulations and Updates to JapanRailwayGuideWatcher

I have released "JapanRailwayGuideWatcher" on Hugging Face—a specialized Gemma 4-based LoRA model trained on Japanese railway technology, railway engineering, civil structures, and signaling/safety systems. In this update, I performed additional training and manual refinements to strengthen its knowledge of Japanese railway laws, regulations, and model self-introduction.

In this post, I will share the motivation behind the project, an overview of the model, and the development log from dataset creation to training completion.

Background: Why Build a Specialized Japanese Railway LLM?

There were practically no LLMs specialized in Japanese railway engineering, and more importantly, I experienced firsthand that "building routes for BVE5 (a Japanese train simulator) is 10 times more tedious than configuring a server."

To create an AI assistant capable of helping with railway simulator route creation and technical research, I trained the model using public documentation from sources such as the Railway Bureau of the Ministry of Land, Infrastructure, Transport and Tourism (MLIT).

Rather than building everything alone, I developed this pipeline iteratively by consulting and collaborating with Copilot, ChatGPT, and local LLMs (via LM Studio).

Model Overview: JapanRailwayGuideWatcher

JapanRailwayGuideWatcher is a domain-specific model trained on approximately 11,500 entries of specialized data, including Japanese railway technical documents, engineering manuals, structural specifications, safety equipment documentation, and MLIT railway regulations.

While its sister model, "JapanRailwayLLM," covers general railway operations and technology, this model focuses more deeply on technical, engineering, infrastructure, and regulatory expertise.

Primary Training Domains

  • Railway Civil Engineering, Structures, and Architecture
  • Track Engineering
  • Signaling and Safety Systems
  • Overhead Contact Line (Catenary) Equipment
  • Rolling Stock Technology
  • Railway Systems, Maintenance Technology, Regulations, and Standards

Model Specifications

  • Base Model: Google Gemma 4 E4B IT (google/gemma-4-E4B-it)
  • Training Method: QLoRA / Unsloth / Hugging Face Transformers
  • Available Checkpoints: checkpoint-7000 / checkpoint-7250 (checkpoint-7250 is recommended for general use as it demonstrates the highest retention of railway engineering knowledge)
  • Recommended Language: Japanese (While the model supports English, Traditional Chinese, Korean, French, Spanish, Brazilian Portuguese, and German, Japanese prompts yield the highest accuracy and most detailed technical explanations.)

Intended Use Cases

  • Knowledge support for creating railway simulator games (such as BVE5)
  • Railway engineering Q&A and technical education
  • Building specialized Railway RAG (Retrieval-Augmented Generation) systems
  • Academic and technical railway research support

Behind the Scenes: Dataset Creation and Training Log

For this project, I built a pipeline to automatically generate a QA dataset (JapanRailwayQA.jsonl) from technical PDF documents for fine-tuning.

1. Generating Q&A from PDFs and Hitting the "Chunk Size" Wall

I connected a Python script to a local LLM environment (LM Studio) to generate QA pairs from technical PDFs. However, the script initially froze right at PDF Chunk: 0.

By adding debug logs to isolate the issue, I found that the request was successfully reaching LM Studio, but the script was timing out while waiting for a response.

print(f"Chunk size: {len(chunk)}")
print("Starting LM Studio request")

response = requests.post(
    LM_STUDIO_URL,
    json=payload,
    timeout=600
)

print("HTTP:", response.status_code)

The culprit was setting chunk_size to 8000. Because railway engineering documents are densely packed with technical terminology and diagram explanations, an 8,000-character chunk overloaded the local inference setup. Lowering this to chunk_size = 1000 and ensuring MODEL_NAME strictly matched the model identifier loaded in LM Studio resolved the bottleneck and stabilized QA generation.

2. Reinforcing Regulations, Self-Introduction, and Manual Fixes

While refining the generated data using LM Studio, I noticed that many railway law and regulation QA entries were defaulting to "Untitled" (無題). Additionally, the earlier training lacked sufficient data on regulations and the model's own self-introduction.

To prevent this from degrading response quality, I manually reviewed and corrected those entries one by one, and conducted additional training with the enriched regulatory and identity data.

3. Completing Training at 7,250 Steps, Merging, and GGUF Format

Training progressed smoothly across the curated dataset of ~11,500 items with a steady, healthy Loss curve, leading to the decision to conclude the main training run at 7,250 steps.

Regarding the release format: currently, the model is released solely as a LoRA adapter—a GGUF-converted version has not been published (as I've noticed, models tend not to get downloaded as easily unless they are converted to GGUF!). However, by merging the adapter with the base model (google/gemma-4-E4B-it) using Python, you can greatly expand how you deploy and use it locally.

Disclaimer

This model is intended for education, research, historical reference, railway enthusiast activities, simulator development, and railway engineering support.

Because generated responses may contain inaccuracies, outputs should always be verified against official railway company publications, engineering standards, regulations, and safety documentation before any operational use. This model is not intended to replace official engineering judgment or railway safety procedures.

Related Links

コメント

このブログの人気の投稿

名鉄の存廃問題と廃線の決まった路線(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?

日本の鉄道知識に特化したAI「JapanRailwayLLM」を作った/I Built “JapanRailwayLLM,” an AI Specialized in Japanese Railway Knowledge