Views
No views yet
af, am, ar, ar-eg, as, azb, be, bg, bm, bn, bo, bs, ca, ceb, cs, cy, da, de, du, el, en, eo, es, et, eu, fa, fi, fr, ga, gd, gl, ha, hi, hr, ht, hu, id, ig, is, it, iw, ja, jv, ka, ki, kk, km, ko, la, lb, ln, lo, lt, lv, mi, mr, ms, mt, my, no, oc, pa, pl, pt, qu, ro, ru, sa, sc, sd, sg, sk, sl, sm, so, sq, sr, ss, sv, sw, ta, te, th, ti, tl, tn, tpi, tr, ts, tw, uk, ur, uz, vi, war, wo, xh, yo, zh, zu transformers library with our custom code.1from transformers import AutoModelForCausalLM, AutoProcessor
2import timm
3from PIL import Image
4import requests
5
6url = "https://upload.wikimedia.org/wikipedia/commons/b/bd/Golden_Retriever_Dukedestiny01_drvd.jpg"
7image = Image.open(requests.get(url, stream=True).raw)
8
9model_name = "WueNLP/centurio_aya"
10
11processor = AutoProcessor.from_pretrained(model_name, trust_remote_code=True)
12
13## Appearance of images in the prompt are indicates with '<image_placeholder>'!
14prompt = "<image_placeholder>\nBriefly describe the image in German."
15
16messages = [
17 {"role": "user", "content": prompt}
18]
19
20text = processor.apply_chat_template(
21 messages,
22 tokenize=False,
23 add_generation_prompt=True
24)
25
26model = AutoModelForCausalLM.from_pretrained(
27 model_name,
28 trust_remote_code=True
29)
30
31model_inputs = processor(text=[text], images=[image] return_tensors="pt").to(model.device)
32
33generated_ids = model.generate(
34 **model_inputs,
35 max_new_tokens=128
36)
37
38generated_ids = [
39 output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
40]
41
42response = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
43<image_placeholder> while 2) passing all images of the entire batch as a flat list:1[...]
2# Variables reused from above.
3
4image_multi_1, image_multi_2 = [...] # prepare additional images
5
6prompt_multi = "What is the difference between the following images?\n<image_placeholder><image_placeholder>\nAnswer in German."
7
8messages_multi = [
9 {"role": "user", "content": prompt_multi}
10]
11
12text_multi = processor.apply_chat_template(
13 messages,
14 tokenize=False,
15 add_generation_prompt=True
16)
17
18model_inputs = processor(text=[text, text_multi], images=[image, image_multi_1, image_multi_2] return_tensors="pt").to(model.device)
19
20generated_ids = model.generate(
21 **model_inputs,
22 max_new_tokens=128
23)
24
25[...]
26@article{centurio2025,
author = {Gregor Geigle and
Florian Schneider and
Carolin Holtermann and
Chris Biemann and
Radu Timofte and
Anne Lauscher and
Goran Glava\v{s}},
title = {Centurio: On Drivers of Multilingual Ability of Large Vision-Language Model},
journal = {arXiv},
volume = {abs/2501.05122},
year = {2025},
url = {https://arxiv.org/abs/2501.05122},
eprinttype = {arXiv},
eprint = {2501.05122},
}