Downloads · 30 days
0
SquareStar/llm-jp-3-13b-finetune_SS19
llm-jp-3-13b-finetune_SS19 is a machine learning model from SquareStar. 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.
本モデルは、このファイル(README.md)と同フォルダの「suiron.py」のコードを実行することで推論が可能です(ただし、HF TOKENや、問題(入力データ)のJSON Fileを用意する必要あり)。
Downloads · 30 days
0
Access
Public
Updated Dec 25, 2024
Repo size
501 MB
Likes
0
Public
Click a slice to open those files.
.safetensors501 MB · 99%
From the Hugging Face model README
本モデルは、このファイル(README.md)と同フォルダの「suiron.py」のコードを実行することで推論が可能です(ただし、HF TOKENや、問題(入力データ)のJSON Fileを用意する必要あり)。
また、本モデルは、このファイル(README.md)と同フォルダにある「提出用lora_template_19_20241127.py」のコードをOmnicampusの演習環境で実行することで得られています。 同コードは、前半はファインチューニング用のコードですが、後半にある「回答」の部分のコードを参考にして、本モデルを用いて推論するコードを作成できます。
次の「1前提条件」を満たし、「2 実行するコード」に沿ってコードを実行することで、Hugging Face上のモデル('SquareStar/llm-jp-3-13b-finetune_SS19)を用いて、 入力ファイル(elyza-tasks-100-TV_0.jsonl)に記載されている指示文書を入力データとして推論し、その結果を{model_name}-outputs.jsonl`という名前のファイルに出力できます。
なお、入力ファイルは、フォーマットが同じであれば、任意の内容で推論可能です。
前提条件として次を用意していください。
必要なライブラリのインストールを行います。
!pip install -U bitsandbytes
!pip install -U transformers
!pip install -U accelerate
!pip install -U datasets
Hugging Faceのトークンを取得していることを確認して、設定してください。 次のコードは、JupyterNotebook環境を使う場合です(実行環境に合わせて適宜変更してください)。
HF_TOKEN = "PLEASE-WIRTE-YOUR-HF-TOKEN"
モデルとトークナイザーを読み込みます。
import torch
from tqdm import tqdm
import json
model_name = "SquareStar/llm-jp-3-13b-finetune_SS19"
from transformers import (
AutoModelForCausalLM,
AutoTokenizer,
BitsAndBytesConfig,
)
# QLoRA用の設定
bnb_config = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_quant_type="nf4",
bnb_4bit_compute_dtype=torch.bfloat16,
bnb_4bit_use_double_quant=False,
)
# モデル読み込み
model = AutoModelForCausalLM.from_pretrained(
model_name,
quantization_config=bnb_config,
device_map="auto",
token = HF_TOKEN
)
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True, token = HF_TOKEN)
elyza-tasks-100-tv.jsonlと同じ形式であれば、任意のファイルを入力することができます。
ここでは./elyza-tasks-100-TV_0.jsonlというファイルを入力データセットとする場合のコードを示しています。
datasets = []
with open("./elyza-tasks-100-TV_0.jsonl", "r") as f: #PLEASE WRITE YOUR JSON FILE NAME!!
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)
with torch.no_grad():
outputs = model.generate(
tokenized_input,
max_new_tokens=512,
do_sample=False,
repetition_penalty=1.2
)[0]
output = tokenizer.decode(outputs[tokenized_input.size(1):], skip_special_tokens=True)
results.append({"task_id": data["task_id"], "input": input, "output": output})
最後に、model_nameをベースにしたファイル名でJSONL形式の出力ファイルに、推論の実行結果を保存します。
import re
model_name = re.sub(".*/", "", model_name)
with open(f"./{model_name}-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')
以上のコードを実行することで、{model_name}-outputs.jsonlというファイルに推論結果が書き出されます。
This is the model card of a 🤗 transformers model that has been pushed on the Hub. This model card has been automatically generated.
[More Information Needed]
[More Information Needed]
[More Information Needed]
[More Information Needed]
Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
Use the code below to get started with the model.
[More Information Needed]
[Fine tuningに使用したデータ] https://liat-aip.sakura.ne.jp/wp/llmのための日本語インストラクションデータ作成/llmのための日本語インストラクションデータ-公開/ 関根聡, 安藤まや, 後藤美知子, 鈴木久美, 河原大輔, 井之上直也, 乾健太郎. ichikara-instruction: LLMのための日本語インストラクションデータの構築. 言語処理学会第30回年次大会(2024)
https://huggingface.co/datasets/elyza/ELYZA-tasks-100 ELYZA-tasks-100: 日本語instructionモデル評価データセット
[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]