ベースモデル

llm-jp-3-13b

ファインチューニングに利用したデータセット

以下のデータセットを利用して、ファインチューニングを行っております。
関根聡, 安藤まや, 後藤美知子, 鈴木久美, 河原大輔, 井之上直也, 乾健太郎. ichikara-instruction: LLMのための日本語インストラクションデータの構築. 言語処理学会第30回年次大会(2024)
データセット名:LLMのための日本語インストラクションデータ
提供者:理化学研究所
リンク:llmのための日本語インストラクションデータ-公開

使用方法(推論)

以下1~4の順序に従って、モデルによる推論が可能となります。

1. 必要なライブラリのインストール

!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

2. 必要なライブラリの読み込み

from unsloth import FastLanguageModel
from peft import PeftModel
import torch
import json
from tqdm import tqdm
import re

3. ベースとなるモデルとアダプタの統合

""" ベースとなるモデルと学習した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)

4. ベースモデルとアダプタの統合

""" 今回のタスクである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')

License

Apache-2.0

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model is not currently available via any of the supported Inference Providers.
The model cannot be deployed to the HF Inference API: The model has no pipeline_tag.

Model tree for hiroshi1991/llm-jp-3-13b-it

Finetuned
(1122)
this model