llm-jp-1b-sft-15k / README.md
ryota39's picture
Update README.md
f749387 verified
|
raw
history blame
1.37 kB
metadata
license: apache-2.0
datasets:
  - llm-jp/databricks-dolly-15k-ja
language:
  - ja
library_name: transformers

モデル

サンプル

import torch
from transformers import AutoTokenizer, AutoModelForCausalLM


tokenizer = AutoTokenizer.from_pretrained(
    "ryota39/llm-jp-1b-sft-15k"
    )
pad_token_id = tokenizer.pad_token_id

model = AutoModelForCausalLM.from_pretrained(
    "ryota39/llm-jp-1b-sft-15k",
    device_map="auto",
    torch_dtype=torch.float16,
    )

text = "###Input: 東京の観光名所を教えてください。\n###Output: "
tokenized_input = tokenizer.encode(
    text,
    add_special_tokens=False,
    return_tensors="pt"
    ).to(model.device)

attention_mask = torch.ones_like(tokenized_input)
attention_mask[tokenized_input == pad_token_id] = 0

with torch.no_grad():
    output = model.generate(
        tokenized_input,
        attention_mask=attention_mask,
        max_new_tokens=128,
        do_sample=False,
        # top_p=0.8,
        # temperature=0.8,
        repetition_penalty=1.0
    )[0]

print(tokenizer.decode(output))