|
--- |
|
library_name: transformers |
|
license: other |
|
datasets: |
|
- DeL-TaiseiOzaki/Tengentoppa-sft-v1.0 |
|
base_model: |
|
- llm-jp/llm-jp-3-13b |
|
--- |
|
|
|
# Model Card for llm-jp-3-13b-finetune-sonodd006 |
|
LoRAアダプターによる日本語チャットボット用のモデルです。ベースモデルである `llm-jp/llm-jp-3-13b` を、`Tengentoppa-sft-v1.0` データセットを用いてSFT(指示調整)しました。 |
|
|
|
## Model Details |
|
|
|
### Model Description |
|
このモデルは、松尾・岩澤研究室の大規模言語モデル講座([詳細はこちら](https://weblab.t.u-tokyo.ac.jp/lecture/course-list/large-language-model/))における演習で、個人(開発者: [sonodd](https://huggingface.co/sonodd))がLoRAのアダプターを使って作成した日本語特化のチャットボット用モデルです。主に日本語でのインストラクション応答・対話生成を目的としています。 |
|
|
|
- **Model Name / Model ID:** [llm-jp-3-13b-finetune-sonodd006](https://huggingface.co/sonodd/llm-jp-3-13b-finetune-sonodd-006) |
|
- **Developed by:** 個人(sonodd) |
|
- **Funded by [optional]:** 松尾・岩澤研究室の講座演習(大規模言語モデル講座) |
|
- **Shared by [optional]:** sonodd |
|
- **Model type:** Decoder-only Transformer (LoRAアダプター使用) |
|
- **Language(s) (NLP):** 日本語 |
|
- **License:** CC-BY-SA |
|
- ※ 演習での利用を想定しており、上記演習での参考以外への利用を禁止しています。 |
|
- **Finetuned from model:** [`llm-jp/llm-jp-3-13b`](https://huggingface.co/llm-jp/llm-jp-3-13b) |
|
|
|
### Model Sources [optional] |
|
|
|
- **Repository:** [llm-jp-3-13b-finetune-sonodd006](https://huggingface.co/sonodd/llm-jp-3-13b-finetune-sonodd-006) |
|
- **Paper [optional]:** [More Information Needed] |
|
- **Demo [optional]:** [More Information Needed] |
|
|
|
## Uses |
|
|
|
<!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. --> |
|
|
|
### Direct Use |
|
日本語チャットボット、対話型アプリケーションへの組み込みを想定しています。単純な質問応答や創作文章生成など、多目的に利用可能です。 |
|
|
|
### Downstream Use [optional] |
|
さらなるLoRA微調整や、他の日本語タスク(要約やQAなど)への転用は可能ですが、本モデルはチャットボット向けに最適化されている点をご留意ください。 |
|
|
|
### Out-of-Scope Use |
|
- 公序良俗に反する、あるいは不適切・有害な内容の生成を意図する利用 |
|
- 大規模サービス等への商用利用(講座演習の参考利用範囲を超える利用は禁止されています) |
|
|
|
## Bias, Risks, and Limitations |
|
- ChatGPT系統のLLMと同様、誤情報やバイアスを含む応答を生成する可能性があります。 |
|
- 生成された文章の内容を利用する場合は、専門家による検証やファクトチェックが必須です。 |
|
|
|
### Recommendations |
|
- 利用者は、モデルが誤った情報や不適切な表現を生成し得る点を理解した上で使用してください。 |
|
- 社会的にセンシティブなテーマに関しては特に慎重に取り扱ってください。 |
|
|
|
## How to Get Started with the Model |
|
|
|
|
|
以下のPythonコード例では、Hugging Face TransformersとPEFTライブラリを使ってLoRAアダプターを読み込んで推論します。 |
|
|
|
```python |
|
# ライブラリのimport, なければpipで取得 |
|
from transformers import ( |
|
AutoModelForCausalLM, |
|
AutoTokenizer, |
|
BitsAndBytesConfig, |
|
) |
|
from peft import PeftModel |
|
import torch |
|
from tqdm import tqdm |
|
import json |
|
|
|
# Hugging Faceにログイン |
|
import os |
|
from huggingface_hub import login |
|
|
|
# Hugging Faceで取得したTokenをこちらに貼る。 |
|
HF_TOKEN = "Hugging Face Token" |
|
|
|
login(HF_TOKEN) |
|
|
|
base_model_id = "llm-jp/llm-jp-3-13b"#Hugging FaceのID |
|
adapter_id = "sonodd/llm-jp-3-13b-finetune-sonodd006" #Hugging FaceのID |
|
|
|
# QLoRA config 量子化設定 |
|
bnb_config = BitsAndBytesConfig( |
|
load_in_4bit=True, # 4-bit量子化を有効化 |
|
bnb_4bit_compute_dtype=torch.float16, # 計算精度をFP16に設定 |
|
bnb_4bit_use_double_quant=True, # ダブル量子化を有効化 |
|
bnb_4bit_quant_type="nf4" # nf4量子化タイプを使用 |
|
) |
|
|
|
# ベースモデルのロード |
|
base_model = AutoModelForCausalLM.from_pretrained( |
|
base_model_id, |
|
quantization_config=bnb_config, # 量子化設定 |
|
device_map="auto", # 自動でGPUとCPUに割り当て |
|
use_auth_token=HF_TOKEN # Hugging Faceトークン |
|
) |
|
|
|
# トークナイザーのロード |
|
tokenizer = AutoTokenizer.from_pretrained( |
|
base_model_id, |
|
trust_remote_code=True, |
|
use_auth_token=HF_TOKEN |
|
) |
|
|
|
print("モデルが正常にロードされました") |
|
|
|
# LoRAアダプタを適用 |
|
model = PeftModel.from_pretrained( |
|
base_model, # ベースモデル |
|
adapter_id, # LoRAアダプタの ID |
|
use_auth_token=HF_TOKEN |
|
) |
|
|
|
print("LoRAアダプタが適用されました") |
|
|
|
# データセットの読み込み({{data_set_name}}に置いてあるファイルを指定) |
|
datasets = [] |
|
with open("./{{data_set_name}}", "r") as f: |
|
item = "" |
|
for line in f: |
|
line = line.strip() |
|
item += line |
|
if item.endswith("}"): |
|
datasets.append(json.loads(item)) |
|
item = "" |
|
|
|
results = [] |
|
for data in tqdm(datasets): |
|
|
|
input = data["input"] |
|
|
|
prompt = f"""### 指示 |
|
{input} |
|
### 回答 |
|
""" |
|
|
|
tokenized_input = tokenizer.encode(prompt, add_special_tokens=False, return_tensors="pt").to(model.device) |
|
attention_mask = torch.ones_like(tokenized_input) |
|
with torch.no_grad(): |
|
outputs = model.generate( |
|
tokenized_input, |
|
attention_mask=attention_mask, |
|
max_new_tokens=512, |
|
do_sample=False, |
|
repetition_penalty=1.2, |
|
pad_token_id=tokenizer.eos_token_id |
|
)[0] |
|
output = tokenizer.decode(outputs[tokenized_input.size(1):], skip_special_tokens=True) |
|
|
|
results.append({"task_id": data["task_id"], "input": input, "output": output}) |
|
``` |
|
|
|
[More Information Needed] |
|
|
|
## Training Details |
|
|
|
### Training Data |
|
|
|
<!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. --> |
|
|
|
[More Information Needed] |
|
|
|
### Training Procedure |
|
|
|
<!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. --> |
|
|
|
#### Preprocessing [optional] |
|
|
|
[More Information Needed] |
|
|
|
|
|
#### Training Hyperparameters |
|
|
|
- **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision --> |
|
|
|
#### Speeds, Sizes, Times [optional] |
|
|
|
<!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. --> |
|
|
|
[More Information Needed] |
|
|
|
## Evaluation |
|
|
|
<!-- This section describes the evaluation protocols and provides the results. --> |
|
|
|
### Testing Data, Factors & Metrics |
|
|
|
#### Testing Data |
|
|
|
<!-- This should link to a Dataset Card if possible. --> |
|
|
|
[More Information Needed] |
|
|
|
#### Factors |
|
|
|
<!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. --> |
|
|
|
[More Information Needed] |
|
|
|
#### Metrics |
|
|
|
<!-- These are the evaluation metrics being used, ideally with a description of why. --> |
|
|
|
[More Information Needed] |
|
|
|
### Results |
|
|
|
[More Information Needed] |
|
|
|
#### Summary |
|
|
|
|
|
|
|
## Model Examination [optional] |
|
|
|
<!-- Relevant interpretability work for the model goes here --> |
|
|
|
[More Information Needed] |
|
|
|
## Environmental Impact |
|
|
|
<!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly --> |
|
|
|
Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700). |
|
|
|
- **Hardware Type:** [More Information Needed] |
|
- **Hours used:** [More Information Needed] |
|
- **Cloud Provider:** [More Information Needed] |
|
- **Compute Region:** [More Information Needed] |
|
- **Carbon Emitted:** [More Information Needed] |
|
|
|
## Technical Specifications [optional] |
|
|
|
### Model Architecture and Objective |
|
|
|
[More Information Needed] |
|
|
|
### Compute Infrastructure |
|
|
|
[More Information Needed] |
|
|
|
#### Hardware |
|
|
|
[More Information Needed] |
|
|
|
#### Software |
|
|
|
[More Information Needed] |
|
|
|
## Citation [optional] |
|
|
|
<!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. --> |
|
|
|
**BibTeX:** |
|
|
|
[More Information Needed] |
|
|
|
**APA:** |
|
|
|
[More Information Needed] |
|
|
|
## Glossary [optional] |
|
|
|
<!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. --> |
|
|
|
[More Information Needed] |
|
|
|
## More Information [optional] |
|
|
|
[More Information Needed] |
|
|
|
## Model Card Authors [optional] |
|
|
|
[More Information Needed] |
|
|
|
## Model Card Contact |
|
|
|
[More Information Needed] |