Views
No views yet
1import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer
3
4model_name = "nayohan/llama3-8b-it-translation-sharegpt-en-ko"
5tokenizer = AutoTokenizer.from_pretrained(model_name)
6model = AutoModelForCausalLM.from_pretrained(
7 model_name,
8 device_map="auto",
9 torch_dtype=torch.bfloat16
10)1system_prompt="당신은 번역기 입니다. 영어를 한국어로 번역하세요."
2sentence = "The aerospace industry is a flower in the field of technology and science."
3conversation = [{'role': 'system', 'content': system_prompt},
4 {'role': 'user', 'content': sentence}]
5
6inputs = tokenizer.apply_chat_template(
7 conversation,
8 tokenize=True,
9 add_generation_prompt=True,
10 return_tensors='pt'
11).to("cuda")
12
13outputs = model.generate(inputs, max_new_tokens=256)
14print(tokenizer.decode(outputs[0][len(inputs[0]):]))# Result
# INPUT: <|begin_of_text|><|start_header_id|>system<|end_header_id|>\n\nActs as a translator. Translate en sentences into ko sentences in colloquial style.<|eot_id|><|start_header_id|>user<|end_header_id|>\n\nThe aerospace industry is a flower in the field of technology and science.<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\n
# OUTPUT: 항공우주 산업은 기술과 과학 분야의 꽃입니다.<|eot_id|>
# INPUT:
<|begin_of_text|><|start_header_id|>system<|end_header_id|>\n\n당신은 번역기 입니다. 영어를 한국어로 번역하세요.<|eot_id|><|start_header_id|>user<|end_header_id|>\n\n
Technical and basic sciences are very important in terms of research. It has a significant impact on the industrial development of a country. Government policies control the research budget.<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\n
# OUTPUT: 기술 및 기초 과학은 연구 측면에서 매우 중요합니다. 이는 한 국가의 산업 발전에 큰 영향을 미칩니다. 정부 정책에 따라 연구 예산이 결정됩니다.<|eot_id|>
1@article{llama3modelcard,
2 title={Llama 3 Model Card},
3 author={AI@Meta},
4 year={2024},
5 url={https://github.com/meta-llama/llama3/blob/main/MODEL_CARD.md}
6}