--- license: apache-2.0 language: - ja datasets: - elyza/ELYZA-tasks-100 base_model: - llm-jp/llm-jp-3-13b --- # Model Card for Model ID ## Model Details ### Model Description This is the model card of a 🤗 transformers model that has been pushed on the Hub. This model card has been automatically generated. - **Developed by:** [More Information Needed] - **Funded by [optional]:** [More Information Needed] - **Shared by [optional]:** [More Information Needed] - **Model type:** [More Information Needed] - **Language(s) (NLP):** [More Information Needed] - **License:** [More Information Needed] - **Finetuned from model [optional]:** [More Information Needed] ### Model Sources [optional] - **Repository:** [More Information Needed] - **Paper [optional]:** [More Information Needed] - **Demo [optional]:** [More Information Needed] ## Uses ```python !pip install -U bitsandbytes !pip install -U transformers !pip install -U accelerate !pip install -U datasets !pip install -U peft from transformers import ( AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig, ) from peft import PeftModel import torch from tqdm import tqdm import json # 必要なライブラリを読み込み from peft import PeftModel import torch import json from tqdm import tqdm import re ## ベースとなるモデルと学習したLoRAのアダプタ model_id = "llm-jp/llm-jp-3-13b" adapter_id = "onhrs/ono-llm-jp-3-13b-finetune" ## Hugging Face Token を指定 HF_TOKEN = "..." # QLoRA config bnb_config = BitsAndBytesConfig( load_in_4bit=True, bnb_4bit_quant_type="nf4", bnb_4bit_compute_dtype=torch.bfloat16, ) # Load model model = AutoModelForCausalLM.from_pretrained( model_id, quantization_config=bnb_config, device_map="auto", token = HF_TOKEN ) # Load tokenizer tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True, token = HF_TOKEN) # 元のモデルにLoRAのアダプタを統合。 model = PeftModel.from_pretrained(model, adapter_id, token = HF_TOKEN) # データセットの読み込み。 # omnicampusの開発環境では、左にタスクの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 = "" # llmjp results = [] for data in tqdm(datasets): input = data["input"] prompt = f"""### 指示 {input} ### 回答 """ # トークナイズ処理を修正 inputs = tokenizer( prompt, return_tensors="pt", add_special_tokens=False ).to(model.device) # generateの呼び出し with torch.no_grad(): outputs = model.generate( input_ids=inputs.input_ids, # input_idsを明示的に指定 attention_mask=inputs.attention_mask, # tokenizerから取得したattention_maskを使用 max_new_tokens=100, do_sample=False, repetition_penalty=1.2, pad_token_id=tokenizer.eos_token_id )[0] # 出力のデコード output = tokenizer.decode(outputs[inputs.input_ids.size(1):], skip_special_tokens=True) # 結果の保存 results.append({ "task_id": data["task_id"], "input": input, "output": output }) #結果の出力 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') ``` ### 学習データセット | Language | Dataset | 詳細 | | ---- | ---- | ---- | | Japanese | elyza/ELYZA-tasks-100 | https://huggingface.co/datasets/elyza/ELYZA-tasks-100 | | Japanese | ELYZA-tasks-100からTanuki-8x8Bで合成データ生成 | https://zenn.dev/karaage0703/articles/e79a1db743b8e4 | | Japanese | ichikara-instruction | https://liat-aip.sakura.ne.jp/wp/llmのための日本語インストラクションデータ作成/llmのための日本語インストラクションデータ-公開/ | | Japanese | ichikara-instructionからTanuki-8x8Bで合成データ生成 | |