HuggingFace pipeline returns empty string with Gemini 1.5 Pro

HuggingFace pipeline returns empty string with Gemini 1.5 Pro

Last week a quick text‑generation pipeline came back blank every call.

from transformers import pipeline
gen = pipeline("text-generation", model="google/gemini-1.5-pro")
print(gen("hi"))

Result:

[{'generated_text': ''}]

Transformers 4.42.1, Python 3.10, macOS Sonoma. No errors. Network call to Google succeeded, payload returned text.

Problem: Gemini models require stop_sequences even if empty; transformers defaults to server‑side stops that strip all content.

Solved by:

gen = pipeline(
    "text-generation",
    model="google/gemini-1.5-pro",
    stop_sequences=None,
    do_sample=False
)

Also works to set return_full_text=True in the call kwargs.

If still blank inspect response JSON; if safetyAttributes flags trigger the content is removed.

comments powered by Disqus