Description

  • [重要]こちらのモデルは、松尾研LLM講座2024最終コンペ用に作成したものです。(勿論、その他の用途での利用も可能です)
  • llm-jp/llm-jp-3-13bを、以下のDatasetで追加学習したモデルになります。
  • こちらはモデル本体ではなくLoraアダプタです。ベースモデルと統合してお使いください。(詳しくはUsageを参照ください)

Base Model

base_model: llm-jp/llm-jp-3-13b

DataSet

Language Dataset description
Japanese ichikara-instruction-003-001-1.json A manually constructed instruction dataset
Japanese ichikara-instruction-003-001-2.1.json A manually constructed instruction dataset
Japanese ichikara-instruction-003-001-2.2.json A manually constructed instruction dataset
Japanese ichikara-instruction-003-001-5.1json A manually constructed instruction dataset
Japanese ichikara-instruction-003-001-5.2.json A manually constructed instruction dataset
Japanese ichikara-instruction-003-002-1.json A manually constructed instruction dataset
Japanese ichikara-instruction-003-003-1.json A manually constructed instruction dataset

データセット提供元

関根聡, 安藤まや, 後藤美知子, 鈴木久美, 河原大輔, 井之上直也, 乾健太郎. ichikara-instruction: LLMのための日本語インストラクションデータの構築. 言語処理学会第30回年次大会(2024) (HP)

[データセット利用における注意点]

  • 今回のコンペのルールに則り、こちらのデータセットを学習に利用したためprivateでの公開としています。
  • (追記)最後に記載したライセンスを遵守した上で、非商用に限りモデル公開を行えるということでpublicとします。

Usage

以下のCodeを全て実行すると、elyza-tasks-100-TV_0.jsonlに対するoutputをまとめたjsonlが出力されます。

## install
!pip install -U bitsandbytes
!pip install -U transformers
!pip install -U accelerate
!pip install -U datasets
!pip install -U peft
## import
from transformers import (
    AutoModelForCausalLM,
    AutoTokenizer,
    BitsAndBytesConfig,
)
from peft import PeftModel
import torch
from tqdm import tqdm
import json
HF_TOKEN = "YOUR-HF-TOKEN" ##Huggingfaceのtokenを利用

model_id = "llm-jp/llm-jp-3-13b"
adapter_id = "Shu-inag/llm-jp-3-13b-finetune"
## QLoRA config
bnb_config = BitsAndBytesConfig(
    load_in_4bit=True,
    bnb_4bit_quant_type="nf4",
    bnb_4bit_compute_dtype=torch.bfloat16,
)
## Load model, tokenizer 
model = AutoModelForCausalLM.from_pretrained(
    model_id,
    quantization_config=bnb_config,
    device_map="auto",
    token = HF_TOKEN
)

tokenizer = AutoTokenizer.from_pretrained(model_id, 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:
    item = ""
    for line in f:
      line = line.strip()
      item += line
      if item.endswith("}"):
        datasets.append(json.loads(item))
        item = ""
## 推論の実行(10~20分ほどかかります)
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=150,
          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})
## 推論結果をjsonlに出力
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')

License

このリポジトリのコンテンツは以下のライセンスに従います:

  1. モデル本体: Apache-2.0
  2. トレーニングデータ: CC BY-NC-SA 4.0

詳細については各ライセンスのテキストを参照してください。


Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for Shu-inag/llm-jp-3-13b-finetune

Finetuned
(1117)
this model