Downloads · 30 days
0
hiroshi1991/llm-jp-3-13b-it
llm-jp-3-13b-it is a machine learning model from hiroshi1991. 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 apache-2.0.
Downloads · 30 days
0
Access
Public
Updated Dec 26, 2024
Repo size
1 GB
Likes
0
Public
Click a slice to open those files.
.safetensors501 MB · 99%
From the Hugging Face model README
以下のデータセットを利用して、ファインチューニングを行っております。<br> 関根聡, 安藤まや, 後藤美知子, 鈴木久美, 河原大輔, 井之上直也, 乾健太郎. ichikara-instruction: LLMのための日本語インストラクションデータの構築. 言語処理学会第30回年次大会(2024)<br> データセット名:LLMのための日本語インストラクションデータ<br> 提供者:理化学研究所<br> リンク:llmのための日本語インストラクションデータ-公開<br>
以下1~4の順序に従って、モデルによる推論が可能となります。
!pip install unsloth
!pip uninstall unsloth -y && pip install --upgrade --no-cache-dir "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git"
!pip install -U torch
!pip install -U peft
from unsloth import FastLanguageModel
from peft import PeftModel
import torch
import json
from tqdm import tqdm
import re
""" ベースとなるモデルと学習したLoRAのアダプタ """
model_id = "llm-jp/llm-jp-3-13b" # ベースモデル
adapter_id = "hiroshi1991/llm-jp-3-13b-it" # アダプタ
HF_TOKEN= "your_token" # あなたのtokenを入力:read権限でも可
""" UnslothのFastLanguageModelでベースモデルをロード """
dtype = None
load_in_4bit = True
model, tokenizer = FastLanguageModel.from_pretrained(
model_name=model_id,
dtype=dtype,
load_in_4bit=load_in_4bit,
trust_remote_code=True,
token=HF_TOKEN
)
""" ベースモデルにLoRAアダプタを統合 """
model = PeftModel.from_pretrained(model, adapter_id, token = HF_TOKEN)
""" 今回のタスクであるelyza-tasks-100-TV_0.jsonlの読込み """
datasets = []
with open("./elyza-tasks-100-TV_0.jsonl", "r") as f: # fileの場所に応じてpathを書き替えてください
item = ""
for line in f:
line = line.strip()
item += line
if item.endswith("}"):
datasets.append(json.loads(item))
item = ""
""" モデルのモードを推論用に変更 """
FastLanguageModel.for_inference(model)
results = []
for dt in tqdm(datasets):
input = dt["input"]
prompt = f"""### 指示\n{input}\n### 回答\n"""
inputs = tokenizer([prompt], return_tensors = "pt").to(model.device)
outputs = model.generate(**inputs, max_new_tokens = 512, use_cache = True, do_sample=False, repetition_penalty=1.2)
prediction = tokenizer.decode(outputs[0], skip_special_tokens=True).split('\n### 回答')[-1]
prediction = re.sub(r"[*#]", "", prediction)
results.append({"task_id": dt["task_id"], "input": input, "output": prediction})
""" 推論した結果をjsonlで保存 """
model_name = re.sub(".*/", "", adapter_id)
with open(f"./{model_name}-my-original-outputs.jsonl", 'w', encoding='utf-8') as f: # 保存したい場所・ファイル名に適宜変更してください
for result in results:
json.dump(result, f, ensure_ascii=False)
f.write('\n')