Views
No views yet

prompt = "<s> Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.\n\n### Instruction:\nTranslate the following text from {direction}.\n\n### Input:\n{sample}\n\n### Response:\n"
where {direction} is one of "English to Macedonian" or "Macedonian to English" and {sample} is the text you want translated.1from transformers import AutoTokenizer, AutoModelForCausalLM
2import torch
3
4tokenizer = AutoTokenizer.from_pretrained("trajkovnikola/MKLLM-7B-Translate")
5model = AutoModelForCausalLM.from_pretrained("trajkovnikola/MKLLM-7B-Translate", torch_dtype=torch.bfloat16, device_map="auto")
6
7sample = "Hi there, how's it going?"
8query = f"<s> Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.\n\n### Instruction:\nTranslate the following text from English to Macedonian.\n\n### Input:\n{sample}\n\n### Response:\n"
9
10model_input = tokenizer(query, return_tensors="pt").to("cuda")
11with torch.no_grad():
12 generated_ids = model.generate(**model_input,
13 max_new_tokens=100,
14 do_sample=False,
15 repetition_penalty=1.1,
16 )
17print(tokenizer.decode(generated_ids[0][model_input["input_ids"].shape[1]:], skip_special_tokens=True))