--- base_model: llm-jp/llm-jp-3-13b library_name: transformers tags: - unsloth license: apache-2.0 --- # ベースモデル [llm-jp-3-13b](https://huggingface.co/llm-jp/llm-jp-3-13b) # ファインチューニングに利用したデータセット 以下のデータセットを利用して、ファインチューニングを行っております。
関根聡, 安藤まや, 後藤美知子, 鈴木久美, 河原大輔, 井之上直也, 乾健太郎. ichikara-instruction: LLMのための日本語インストラクションデータの構築. 言語処理学会第30回年次大会(2024)
データセット名:LLMのための日本語インストラクションデータ
提供者:理化学研究所
リンク:[llmのための日本語インストラクションデータ-公開](https://liat-aip.sakura.ne.jp/wp/llm%E3%81%AE%E3%81%9F%E3%82%81%E3%81%AE%E6%97%A5%E6%9C%AC%E8%AA%9E%E3%82%A4%E3%83%B3%E3%82%B9%E3%83%88%E3%83%A9%E3%82%AF%E3%82%B7%E3%83%A7%E3%83%B3%E3%83%87%E3%83%BC%E3%82%BF%E4%BD%9C%E6%88%90/llm%E3%81%AE%E3%81%9F%E3%82%81%E3%81%AE%E6%97%A5%E6%9C%AC%E8%AA%9E%E3%82%A4%E3%83%B3%E3%82%B9%E3%83%88%E3%83%A9%E3%82%AF%E3%82%B7%E3%83%A7%E3%83%B3%E3%83%87%E3%83%BC%E3%82%BF-%E5%85%AC%E9%96%8B/)
# 使用方法(推論) 以下1~4の順序に従って、モデルによる推論が可能となります。 ## 1. 必要なライブラリのインストール ```python !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. 必要なライブラリの読み込み ```python from unsloth import FastLanguageModel from peft import PeftModel import torch import json from tqdm import tqdm import re ``` ## 3. ベースとなるモデルとアダプタの統合 ```python """ ベースとなるモデルと学習した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. ベースモデルとアダプタの統合 ```python """ 今回のタスクである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](https://www.apache.org/licenses/LICENSE-2.0)