🚀 llm-jp-modernbert-base
本模型基於 modernBERT-base 架構,並使用 llm-jp-tokenizer。它使用 llm-jp-corpus v4 的日語子集(3.4TB)進行訓練,支持的最大序列長度為 8192。
如需瞭解訓練方法、評估和分析結果的詳細信息,請訪問 llm-jp-modernbert: A ModernBERT Model Trained on a Large-Scale Japanese Corpus with Long Context Length。
🚀 快速開始
請安裝 transformers 庫。
pip install "transformers>=4.48.0"
如果你的 GPU 支持 flash-attn 2,建議安裝 flash-attn。
pip install flash-attn --no-build-isolation
💻 使用示例
基礎用法
from transformers import AutoTokenizer, AutoModelForMaskedLM
model_id = "llm-jp/llm-jp-modernbert-base"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForMaskedLM.from_pretrained(model_id)
text = "日本の首都は<MASK|LLM-jp>です。"
inputs = tokenizer(text, return_tensors="pt")
outputs = model(**inputs)
masked_index = inputs["input_ids"][0].tolist().index(tokenizer.mask_token_id)
predicted_token_id = outputs.logits[0, masked_index].argmax(axis=-1)
predicted_token = tokenizer.decode(predicted_token_id)
print("Predicted token:", predicted_token)
📚 詳細文檔
訓練
此模型在第一階段以最大序列長度 1024 進行訓練,然後在第二階段以最大序列長度 8192 進行訓練。
訓練代碼可在 https://github.com/llm-jp/llm-jp-modernbert 找到。
模型 |
階段 1 |
階段 2 |
最大序列長度 |
1024 |
8192 |
最大步數 |
500,000 |
200,000 |
總批量大小 |
3328 |
384 |
峰值學習率 |
5e-4 |
5e-5 |
預熱步數 |
24,000 |
|
學習率調度 |
線性衰減 |
|
Adam 係數 beta 1 |
0.9 |
|
Adam 係數 beta 2 |
0.98 |
|
Adam 係數 eps |
1e-6 |
|
掩碼語言模型概率 |
0.30 |
|
梯度裁剪 |
1.0 |
|
權重衰減 |
1e-5 |
|
逐行處理 |
True |
|
階段 2 中的空白表示與階段 1 的值相同。
評估
使用了來自 JGLUE 的 JSTS、JNLI 和 JCoLA 進行評估。
評估代碼可在 https://github.com/llm-jp/llm-jp-modernbert 找到。
模型 |
JSTS(皮爾遜相關係數) |
JNLI(準確率) |
JCoLA(準確率) |
平均值 |
tohoku-nlp/bert-base-japanese-v3 |
0.920 |
0.912 |
0.880 |
0.904 |
sbintuitions/modernbert-ja-130m |
0.916 |
0.927 |
0.868 |
0.904 |
sbintuitions/modernbert-ja-310m |
0.932 |
0.933 |
0.883 |
0.916 |
llm-jp/llm-jp-modernbert-base |
0.918 |
0.913 |
0.844 |
0.892 |
📄 許可證
Apache 許可證,版本 2.0
🔖 引用
@misc{sugiura2025llmjpmodernbertmodernbertmodeltrained,
title={llm-jp-modernbert: A ModernBERT Model Trained on a Large-Scale Japanese Corpus with Long Context Length},
author={Issa Sugiura and Kouta Nakayama and Yusuke Oda},
year={2025},
eprint={2504.15544},
archivePrefix={arXiv},
primaryClass={cs.CL},
url={https://arxiv.org/abs/2504.15544},
}