Downloads · 30 days
0
sonodd/llm-jp-3-13b-finetune-sonodd006
llm-jp-3-13b-finetune-sonodd006 is a machine learning model from sonodd. Use it for the machine learning task on the model card, and read the license before you ship it in a product. It is set up for transformers. The card lists the license as other.
LoRAアダプターによる日本語チャットボット用のモデルです。ベースモデルである llm-jp/llm-jp-3-13b を、Tengentoppa-sft-v1.0 データセットを用いてSFT(指示調整)しました。
Downloads · 30 days
0
Access
Public
Updated Dec 17, 2024
Repo size
501 MB
Likes
0
Public
Click a slice to open those files.
.safetensors501 MB · 99%
From the Hugging Face model README
LoRAアダプターによる日本語チャットボット用のモデルです。ベースモデルである llm-jp/llm-jp-3-13b を、Tengentoppa-sft-v1.0 データセットを用いてSFT(指示調整)しました。
このモデルは、松尾・岩澤研究室の大規模言語モデル講座(詳細はこちら)における演習で、個人(開発者: sonodd)がLoRAのアダプターを使って作成した日本語特化のチャットボット用モデルです。主に日本語でのインストラクション応答・対話生成を目的としています。
llm-jp/llm-jp-3-13b日本語チャットボット、対話型アプリケーションへの組み込みを想定しています。単純な質問応答や創作文章生成など、多目的に利用可能です。
さらなるLoRA微調整や、他の日本語タスク(要約やQAなど)への転用は可能ですが、本モデルはチャットボット向けに最適化されている点をご留意ください。
以下のPythonコード例では、Hugging Face TransformersとPEFTライブラリを使ってLoRAアダプターを読み込んで推論します。
# ライブラリの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})
# こちらで生成されたjsolをファイルに出力
import re
jsonl_id = re.sub(".*/", "", adapter_id)
with open(f"./{jsonl_id}-outputs.jsonl", 'w', encoding='utf-8') as f:
for result in results:
json.dump(result, f, ensure_ascii=False) # ensure_ascii=False for handling non-ASCII characters
f.write('\n')
[More Information Needed]
[More Information Needed]
[More Information Needed]
[More Information Needed]
[More Information Needed]
[More Information Needed]
[More Information Needed]
[More Information Needed]
[More Information Needed]
Carbon emissions can be estimated using the Machine Learning Impact calculator presented in Lacoste et al. (2019).
[More Information Needed]
[More Information Needed]
[More Information Needed]
[More Information Needed]
BibTeX:
[More Information Needed]
APA:
[More Information Needed]
[More Information Needed]
[More Information Needed]
[More Information Needed]
[More Information Needed]