Views
No views yet
1from datasets import load_dataset
2
3# データセットの読み込み
4processor = DatasetProcessor()
5processor.load_and_process_dataset(
6 dataset_name="GENIAC-Team-Ozaki/Evol-Alpaca-gen3-500_cleaned",
7 instruction_column="instruction",
8 output_column="output",
9 input_column="input",
10 transform_type="basic"
11)
12
13# 処理済みデータをJSONとして保存
14processor.save_combined_dataset("evol_alpaca_dataset.json")1import os
2import torch
3import json
4from tqdm import tqdm
5from unsloth import FastLanguageModel, is_bfloat16_supported
6
7# 必要なパッケージのインストール
8!pip uninstall unsloth -y
9!pip install --upgrade --no-cache-dir "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git"
10!pip install --upgrade torch xformers1# GPU設定の確認
2device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
3print(f"Using device: {device}")
4
5# モデルとトークナイザーの読み込み
6max_seq_length = 512
7model, tokenizer = FastLanguageModel.from_pretrained(
8 model_name="[YOUR_USERNAME]/llm-jp-3-13b-it-b01_lora",
9 dtype=None,
10 load_in_4bit=True,
11 trust_remote_code=True,
12)
13
14# 推論モードに設定
15FastLanguageModel.for_inference(model)
16model = model.to(device)1# 評価用データの読み込み
2datasets = []
3with open("elyza-tasks-100-TV_0.jsonl", "r") as f:
4 item = ""
5 for line in f:
6 line = line.strip()
7 item += line
8 if item.endswith("}"):
9 datasets.append(json.loads(item))
10 item = ""
11
12# モデルを推論モードに設定し、推論を実行
13FastLanguageModel.for_inference(model)
14
15results = []
16for dt in tqdm(datasets):
17 input = dt["input"]
18 prompt = f"""### 指示\n{input}\n### 回答\n"""
19
20 inputs = tokenizer([prompt], return_tensors="pt").to(device)
21 outputs = model.generate(
22 **inputs,
23 max_new_tokens=512,
24 use_cache=True,
25 do_sample=False,
26 repetition_penalty=1.2
27 )
28 prediction = tokenizer.decode(outputs[0], skip_special_tokens=True).split('\n### 回答')[-1]
29
30 results.append({
31 "task_id": dt["task_id"],
32 "input": input,
33 "output": prediction
34 })
35
36# 結果をjsonl形式で保存
37output_file = "llm-jp-3-13b-it-b01_output.jsonl"
38with open(output_file, 'w', encoding='utf-8') as f:
39 for result in results:
40 json.dump(result, f, ensure_ascii=False)
41 f.write('\n')
42
43print(f"Output saved to {output_file}")1@misc{llm-jp-3-13b-it-b01,
2 author = {[YOUR_NAME]},
3 title = {llm-jp-3-13b-it-b01: Instruction-tuned LLM-JP-3-13B with QLoRA},
4 year = {2024},
5 publisher = {Hugging Face},
6 journal = {Hugging Face Hub},
7 howpublished = {\url{https://huggingface.co/[YOUR_USERNAME]/llm-jp-3-13b-it-b01_lora}},
8}