Jin0's picture
Update README.md
2161672 verified
metadata
license: llama3
language:
  - ko
  - en
library_name: transformers
pipeline_tag: text-generation

Python code with Pipeline

import transformers
import torch

model_id = "VIRNECT/llama-3-Korean-8B-V3"

pipeline = transformers.pipeline(
    "text-generation",
    model=model_id,
    model_kwargs={"torch_dtype": torch.bfloat16},
    device_map="auto",
)

pipeline.model.eval()

PROMPT = '''๋‹น์‹ ์€ ์ธ๊ฐ„๊ณผ ๋Œ€ํ™”ํ•˜๋Š” ์นœ์ ˆํ•œ ์ฑ—๋ด‡์ž…๋‹ˆ๋‹ค. ์งˆ๋ฌธ์— ๋Œ€ํ•œ ์ •๋ณด๋ฅผ ์ƒํ™ฉ์— ๋งž๊ฒŒ ์ž์„ธํžˆ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. ๋‹น์‹ ์ด ์งˆ๋ฌธ์— ๋Œ€ํ•œ ๋‹ต์„ ๋ชจ๋ฅธ๋‹ค๋ฉด, ์‚ฌ์‹ค์€ ๋ชจ๋ฅธ๋‹ค๊ณ  ๋งํ•ฉ๋‹ˆ๋‹ค.'''
instruction = "๋ณต์žก๋„ ์ด๋ก ์—์„œ PH๋Š” ๋ฌด์—‡์ธ๊ฐ€์š”?"

messages = [
    {"role": "system", "content": f"{PROMPT}"},
    {"role": "user", "content": f"{instruction}"}
]

prompt = pipeline.tokenizer.apply_chat_template(
        messages, 
        tokenize=False, 
        add_generation_prompt=True
)

terminators = [
    pipeline.tokenizer.eos_token_id,
    pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>")
]

outputs = pipeline(
    prompt,
    max_new_tokens=2048,
    eos_token_id=terminators,
    do_sample=True,
    temperature=0.6,
    top_p=0.9
)

print(outputs[0]["generated_text"][len(prompt):])