Uploaded model

  • Developed by: izumiharu
  • License: apache-2.0
  • Finetuned from model : llm-jp/llm-jp-3-13b

This llama model was trained 2x faster with Unsloth and Huggingface's TRL library.

llm-jp-13b-ver1.2

 llm-jp/llm-jp-3-13b(https://huggingface.co/llm-jp/llm-jp-3-13b)をSFTしたモデルです。

松尾研大規模言語モデル講座2024(https://weblab.t.u-tokyo.ac.jp/lecture/course-list/large-language-model/)のコンペ用の提出モデル作成の一環として作成・公開しています。

推論方法

入力における必須フィールド: {"input": "処理するテキスト"} 出力形式:jsonl形式 {"task_id":タスク番号,"input":処理するテキスト,"output":出力されたテキスト}

from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
from unsloth import FastLanguageModel
import torch
from huggingface_hub import login

max_seq_length = 512 
dtype = None 
load_in_4bit = True 

token = ""  #huggingfaceトークンを入力
if token:
    login(token=token)
else:
    raise ValueError("環境変数 'HUGGINGFACE_TOKEN' にアクセストークンを設定してください。")

model_id = "izumiharu/llm-jp-3-3.7b-ver1.1"

# FastLanguageModel インスタンスを作成
model, tokenizer = FastLanguageModel.from_pretrained(
    model_name=model_id,
    dtype=dtype,
    load_in_4bit=load_in_4bit,
    trust_remote_code=True,
)
#プロンプトの設定
prompt = """### 指示
{}
### 回答
{}"""

import json
datasets = []
#任意のデータセットを指定
with open("", "r") as f:
    item = ""
    for line in f:
      line = line.strip()
      item += line
      if item.endswith("}"):
        datasets.append(json.loads(item))
        item = ""

# 学習したモデルを用いてタスクを実行
from tqdm import tqdm

# 推論するためにモデルのモードを変更
FastLanguageModel.for_inference(model)

results = []
count=0
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]

  results.append({"task_id": count, "input": input, "output": prediction})

output_file = "output.jsonl"

# JSONLファイルに書き込み
with open(output_file, 'w', encoding='utf-8') as f:
    for item in results:
        # 各辞書をJSON文字列に変換し、ファイルに書き込む
        json_line = json.dumps(item, ensure_ascii=False)
        f.write(json_line + "\n")

print(f"データが'{output_file}'に保存されました。")
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 izumiharu/llm-jp-13b-ver1.2

Finetuned
(1120)
this model