Files
Llama-3-8B-Instruct-Ja/README.md
ModelHub XC f51a873218 初始化项目,由ModelHub XC社区提供模型
Model: alfredplpl/Llama-3-8B-Instruct-Ja
Source: Original Platform
2026-06-19 15:41:13 +08:00

110 lines
3.3 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
language:
- en
- ja
license: other
library_name: transformers
tags:
- facebook
- meta
- pytorch
- llama
- llama-3
base_model: meta-llama/Meta-Llama-3-8B-Instruct
datasets:
- cl-nagoya/auto-wiki-qa
- llm-jp/databricks-dolly-15k-ja
license_name: llama3
license_link: LICENSE
---
# 日本語向け Llama 3 8B
![eyecatch](eyecatch.webp)
# はじめに
このリポジトリはLlama 3を日本語化しようとしたモデルのリポジトリです。**4/23に更新**したため、新しくダウンロードすることをオススメします。
# ライセンス
[Llama 3 ライセンス](LICENSE)なので商用利用可能です。ただし、Llama 3ライセンスをよく読んで使ってください。
# 使い方
手っ取り早くやるなら[デモ](https://huggingface.co/spaces/alfredplpl/Llama-3-8B-Instruct-Ja-Demo)を使ってください。次点は[Colab](https://colab.research.google.com/drive/1le0T54BOr72dFeeCFtKxcTDBdIrnr7f6?usp=sharing)がおすすめです。
ローカルでやる場合は次のとおりです。
まず、ライブラリを次のようにインストールします。
```bash
pip install -U transformers accelerate
```
その後、以下のコードを実行してください。
```python
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("alfredplpl/Llama-3-8B-Instruct-Ja")
model = AutoModelForCausalLM.from_pretrained("alfredplpl/Llama-3-8B-Instruct-Ja", device_map="auto", torch_dtype=torch.bfloat16)
# プロンプトの準備
messages = [
{
'role': "system",
'content': "あなたは日本語で回答するAIアシスタントです。"
},
{
'role': "user",
'content': "猫と犬、どっちが好き?"
}
]
prompt=tokenizer.apply_chat_template(messages, tokenize=False)
# 推論の実行
input_ids = tokenizer(prompt, return_tensors="pt").to(model.device)
outputs = model.generate(
**input_ids,
max_new_tokens=128,
do_sample=True,
top_p=0.95,
temperature=0.2,
repetition_penalty=1.1,
eos_token_id=[
tokenizer.eos_token_id,
tokenizer.convert_tokens_to_ids("<|eot_id|>")
],
)
print(tokenizer.decode(outputs[0]))
```
次のような結果が得られるはずです。
```python
<|begin_of_text|><|start_header_id|>system<|end_header_id|>
あなたは日本語で回答するAIアシスタントです<|eot_id|><|start_header_id|>user<|end_header_id|>
猫と犬どっちが好き<|eot_id|><|start_header_id|>assistant<|end_header_id|>
猫と犬の両方を飼っているのでどちらも好きだ<|eot_id|>
```
# 学習データ
- llm-jp/databricks-dolly-15k-ja
- cl-nagoya/auto-wiki-qa
- meta-llama/Meta-Llama-3-8B-Instruct
# 学習方法
meta-llama/Meta-Llama-3-8B-Instructに対して、cl-nagoya/auto-wiki-qaにある約240万件の学習データでLoRAによるインストラクションチューニングを1epoch行い、LoRAをマージしました。
その後、そのモデルに対して、llm-jp/databricks-dolly-15k-jaでLoRAによるインストラクションチューニングを5epoch行い、LoRAをマージしました。
これらの学習はすべて教師あり学習で行いました。
# ハードウェア
- NVIDIA A6000x2
# ソフトウェア
- transformers
- trl
# 学習時間
- 60 GPU hours