Skip to content

Commit 3c64f57

Browse files
stevhliuzucchini-nlp
authored andcommitted
[docs] Fix image link (huggingface#36869)
* fix image link * fix * update * fix
1 parent d8ecc7b commit 3c64f57

File tree

4 files changed

+66
-32
lines changed

4 files changed

+66
-32
lines changed

docs/source/en/processors.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ import requests
2929

3030
processor = AutoProcessor.from_pretrained("google/paligemma-3b-pt-224")
3131

32-
prompt = "answer en Where is the cow standing?"
33-
url = "https://huggingface.co/gv-hf/PaliGemma-test-224px-hf/resolve/main/cow_beach_1.png"
32+
prompt = "answer en Where is the cat standing?"
33+
url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/pipeline-cat-chonk.jpeg"
3434
image = Image.open(requests.get(url, stream=True).raw)
3535

3636
inputs = processor(text=prompt, images=image, return_tensors="pt")

src/transformers/models/gemma3/modeling_gemma3.py

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,20 +1272,37 @@ def forward(
12721272
>>> import requests
12731273
>>> from transformers import AutoProcessor, Gemma3ForConditionalGeneration
12741274
1275-
>>> model = Gemma3ForConditionalGeneration.from_pretrained("google/Gemma3-test-224px-hf")
1276-
>>> processor = AutoProcessor.from_pretrained("google/Gemma3-test-224px-hf")
1277-
1278-
>>> prompt = "answer en Where is the cow standing?"
1279-
>>> url = "https://huggingface.co/gv-hf/Gemma3-test-224px-hf/resolve/main/cow_beach_1.png"
1280-
>>> image = Image.open(requests.get(url, stream=True).raw)
1281-
1282-
>>> inputs = processor(images=image, text=prompt, return_tensors="pt")
1283-
1275+
>>> model = Gemma3ForConditionalGeneration.from_pretrained("google/gemma-3-4b-it")
1276+
>>> processor = AutoProcessor.from_pretrained("google/gemma-3-4b-it")
1277+
1278+
>>> messages = [
1279+
... {
1280+
... "role": "system",
1281+
... "content": [
1282+
... {"type": "text", "text": "You are a helpful assistant."}
1283+
... ]
1284+
... },
1285+
... {
1286+
... "role": "user", "content": [
1287+
... {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/pipeline-cat-chonk.jpeg"},
1288+
... {"type": "text", "text": "Where is the cat standing?"},
1289+
... ]
1290+
... },
1291+
... ]
1292+
1293+
>>> inputs = processor.apply_chat_template(
1294+
... messages,
1295+
... tokenizer=True,
1296+
... return_dict=True,
1297+
... return_tensors="pt",
1298+
... add_generation_prompt=True
1299+
... )
12841300
>>> # Generate
1285-
>>> generate_ids = model.generate(**inputs, max_length=30)
1301+
>>> generate_ids = model.generate(**inputs)
12861302
>>> processor.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
1287-
"answer en Where is the cow standing?\nbeach"
1288-
```"""
1303+
"user\nYou are a helpful assistant.\n\n\n\n\n\nWhere is the cat standing?\nmodel\nBased on the image, the cat is standing in a snowy area, likely outdoors. It appears to"
1304+
```
1305+
"""
12891306

12901307
if (input_ids is None) ^ (inputs_embeds is not None):
12911308
raise ValueError("You must specify exactly one of input_ids or inputs_embeds")

src/transformers/models/gemma3/modular_gemma3.py

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -883,20 +883,37 @@ def forward(
883883
>>> import requests
884884
>>> from transformers import AutoProcessor, Gemma3ForConditionalGeneration
885885
886-
>>> model = Gemma3ForConditionalGeneration.from_pretrained("google/Gemma3-test-224px-hf")
887-
>>> processor = AutoProcessor.from_pretrained("google/Gemma3-test-224px-hf")
888-
889-
>>> prompt = "answer en Where is the cow standing?"
890-
>>> url = "https://huggingface.co/gv-hf/Gemma3-test-224px-hf/resolve/main/cow_beach_1.png"
891-
>>> image = Image.open(requests.get(url, stream=True).raw)
892-
893-
>>> inputs = processor(images=image, text=prompt, return_tensors="pt")
894-
886+
>>> model = Gemma3ForConditionalGeneration.from_pretrained("google/gemma-3-4b-it")
887+
>>> processor = AutoProcessor.from_pretrained("google/gemma-3-4b-it")
888+
889+
>>> messages = [
890+
... {
891+
... "role": "system",
892+
... "content": [
893+
... {"type": "text", "text": "You are a helpful assistant."}
894+
... ]
895+
... },
896+
... {
897+
... "role": "user", "content": [
898+
... {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/pipeline-cat-chonk.jpeg"},
899+
... {"type": "text", "text": "Where is the cat standing?"},
900+
... ]
901+
... },
902+
... ]
903+
904+
>>> inputs = processor.apply_chat_template(
905+
... messages,
906+
... tokenizer=True,
907+
... return_dict=True,
908+
... return_tensors="pt",
909+
... add_generation_prompt=True
910+
... )
895911
>>> # Generate
896-
>>> generate_ids = model.generate(**inputs, max_length=30)
912+
>>> generate_ids = model.generate(**inputs)
897913
>>> processor.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
898-
"answer en Where is the cow standing?\nbeach"
899-
```"""
914+
"user\nYou are a helpful assistant.\n\n\n\n\n\nWhere is the cat standing?\nmodel\nBased on the image, the cat is standing in a snowy area, likely outdoors. It appears to"
915+
```
916+
"""
900917

901918
if (input_ids is None) ^ (inputs_embeds is not None):
902919
raise ValueError("You must specify exactly one of input_ids or inputs_embeds")

src/transformers/models/paligemma/modeling_paligemma.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -464,19 +464,19 @@ def forward(
464464
>>> import requests
465465
>>> from transformers import AutoProcessor, PaliGemmaForConditionalGeneration
466466
467-
>>> model = PaliGemmaForConditionalGeneration.from_pretrained("google/PaliGemma-test-224px-hf")
468-
>>> processor = AutoProcessor.from_pretrained("google/PaliGemma-test-224px-hf")
467+
>>> model = PaliGemmaForConditionalGeneration.from_pretrained("google/paligemma2-3b-mix-224")
468+
>>> processor = AutoProcessor.from_pretrained("google/paligemma2-3b-mix-224")
469469
470-
>>> prompt = "answer en Where is the cow standing?"
471-
>>> url = "https://huggingface.co/gv-hf/PaliGemma-test-224px-hf/resolve/main/cow_beach_1.png"
470+
>>> prompt = "Where is the cat standing?"
471+
>>> url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/pipeline-cat-chonk.jpeg"
472472
>>> image = Image.open(requests.get(url, stream=True).raw)
473473
474474
>>> inputs = processor(images=image, text=prompt, return_tensors="pt")
475475
476476
>>> # Generate
477-
>>> generate_ids = model.generate(**inputs, max_length=30)
477+
>>> generate_ids = model.generate(**inputs,)
478478
>>> processor.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
479-
"answer en Where is the cow standing?\nbeach"
479+
"Where is the cat standing?\nsnow"
480480
```"""
481481

482482
if (input_ids is None) ^ (inputs_embeds is not None):

0 commit comments

Comments
 (0)