Views
No views yet

1import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
3from peft.peft_model import PeftModel
4
5device = "cuda" if torch.cuda.is_available() else "cpu"
6dtype = torch.bfloat16
7
8model = AutoModelForCausalLM.from_pretrained(
9 "CohereForAI/aya-expanse-8b",
10 torch_dtype=dtype,
11 device_map=device
12)
13tokenizer = AutoTokenizer.from_pretrained("CohereForAI/aya-expanse-8b")
14
15model = PeftModel.from_pretrained(model = model,model_id = "gaokerena/gaokerena-v1.0")
16model = model.merge_and_unload()
17
18pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)
19pipe_output = pipe([{"role": "user", "content": "چگونه استرس میتواند باعث ایجاد آفت دهان شود؟"}],
20 max_new_tokens=1024,
21 eos_token_id=[tokenizer.eos_token_id],
22 do_sample=False,
23)
24
25output = pipe_output[0]["generated_text"][-1]["content"]
26print(output)1from transformers import AutoProcessor, AutoModelForImageTextToText
2import torch
3from peft.peft_model import PeftModel
4
5model_id = "CohereForAI/aya-vision-8b"
6
7processor = AutoProcessor.from_pretrained(model_id)
8model = AutoModelForImageTextToText.from_pretrained(
9 model_id, device_map="auto", torch_dtype=torch.float16
10)
11model = PeftModel.from_pretrained(model=model,model_id="gaokerena/gaokerena-v1.0")
12model = model.merge_and_unload()
13
14messages = [
15 {"role": "user",
16 "content": [
17 {"type": "image", "url": "./chest-pic.jpeg"},
18 {"type": "text", "text": "در مورد این تصویر توضیح بده"},
19 ]},
20 ]
21
22inputs = processor.apply_chat_template(
23 messages, padding=True, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt"
24).to(model.device)
25
26gen_tokens = model.generate(
27 **inputs,
28 max_new_tokens=1024,
29 do_sample=True,
30 temperature=0.3,
31)
32print(processor.tokenizer.decode(gen_tokens[0][inputs.input_ids.shape[1]:], skip_special_tokens=True))
33@misc{Gaokerena-v1.0,
title={Leveraging Online Data to Enhance Medical Knowledge in a Small Persian Language Model},
author={Ghassabi, Mehrdad and Rostami, Pedram and Baradaran Kashani, Hamidreza and Poursina, Amirhossein and Kazemi, Zahra and Tavakoli, Milad},
year={2025}
eprint={2505.16000},
archivePrefix={arXiv},
primaryClass={cs.CL}
}