Text Generation
Transformers
Japanese
Inference Endpoints
Edit model card

cyberagent/open-calm-7bに対してkunishou/databricks-dolly-15k-jaをpeftを用いて(というよりtloen/alpaca-loraを改変して)チューニングしたものの差分です。
lora-alpacaから学習時のパラメータは特に変えていません。

import torch
from peft import PeftModel
from transformers import AutoModelForCausalLM, AutoTokenizer

LOAD_8BIT = False
BASE_MODEL = "cyberagent/open-calm-7b"
LORA_WEIGHTS = "nakayama/lora-db-dolly-15k-ja-for-open-calm-7b"

tokenizer = AutoTokenizer.from_pretrained(BASE_MODEL)

model = AutoModelForCausalLM.from_pretrained(
    BASE_MODEL,
    load_in_8bit=LOAD_8BIT,
    torch_dtype=torch.float16,
    device_map="auto",
)
model = PeftModel.from_pretrained(
    model,
    LORA_WEIGHTS,
    torch_dtype=torch.float16,
    adapter_name=LORA_WEIGHTS
)

def generate_prompt(instruction, input=None):
    if input:
        return f"""以下は、タスクを説明する命令と、さらなるコンテキストを提供する入力の組み合わせです。要求を適切に満たすような応答を書きなさい。

### Instruction:
{instruction}

### Input:
{input}

### Response:"""
    else:
        return f"""以下は、ある作業を記述した指示です。依頼を適切に完了させる回答を書きなさい。

### Instruction:
{instruction}

### Response:"""

if not LOAD_8BIT:
    model.half()

instruction="次の日本の観光地について説明してください。"

input="富士山"

prompt = generate_prompt(instruction, input)
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)

with torch.no_grad():
    generation_output = model.generate(
        **inputs,
        do_sample=True,
        temperature=0.1,
        top_p=0.75,
        top_k=20,
        return_dict_in_generate=True,
        output_scores=True,
        max_new_tokens=128,
        repetition_penalty=1.5,
        no_repeat_ngram_size=5,
        pad_token_id=tokenizer.pad_token_id,
    )
s = generation_output.sequences[0]
output = tokenizer.decode(s)
print(output.split("### Response:")[1].strip())

#富士山は静岡県の駿河湾沿いに位置する活火山である[1]。標高3,776メートル(1338フィート)で、[2]世界最高峰の山であり [4]、世
界で最も高い山と考えられている。[5][7](ただし、「世界で一番美しい」という評価は誤りであることが証明されている)。また「日本のマッターホルン」、「世界の七不思議」(ユネスコ世界遺産委員会によって認定)、そして西半球で最も有名な自然の観光名所の一つである。「Mount Fuji is the world's most beautiful mountain in Japan. It has been said that it was a national park of historical faith and well-
Downloads last month
0

Datasets used to train nakayama/lora-db-dolly-15k-ja-for-open-calm-7b