SigLIP2's tokenizer performs no case-normalization, unlike SigLIP v1's SiglipTokenizer
System info
transformers4.57.6,tokenizers0.22.2- Model:
google/siglip2-base-patch16-224
Description
Loading the SigLIP2 checkpoint via AutoProcessor/AutoModel resolves to a plain GemmaTokenizerFast with no case-normalization step. This means capitalized single-word text queries (e.g. "Lion", "Hippo", "Giraffe") produce text embeddings that are nearly identical to each other (cosine similarity ~0.996-0.998) regardless of which word it is - effectively collapsing all of them onto one generic point in embedding space, far more similar to each other than their lowercase counterparts are (~0.90, which correctly reflects that lion/hippo/giraffe are different but related concepts). In practice this means capitalized single-word queries retrieve close to random images from an unrelated corpus in a text-to-image retrieval setup.
This is inconsistent with SigLIP v1 in the same library: transformers/models/siglip/tokenization_siglip.py's SiglipTokenizer has do_lower_case=True by default and an explicit canonicalize_text() method that it runs before every tokenization call (around line 323, text = self.canonicalize_text(text, ...)). SigLIP2's shipped tokenizer_config.json has no equivalent - do_lower_case and canonicalize_text are simply absent from the resolved tokenizer.
Reproduction
"""
Repro: SigLIP2's shipped tokenizer performs no case-normalization, so
capitalized single-word text queries collapse onto nearly-identical
embeddings regardless of meaning -- unlike SigLIP v1, whose own
SiglipTokenizer canonicalizes (lowercases) text by default.
"""
import torch
import torch.nn.functional as F
from transformers import AutoModel, AutoProcessor
MODEL_ID = "google/siglip2-base-patch16-224"
processor = AutoProcessor.from_pretrained(MODEL_ID)
model = AutoModel.from_pretrained(MODEL_ID).eval()
tokenizer = processor.tokenizer
print(f"tokenizer class: {type(tokenizer).__name__}")
print(f"has do_lower_case attr: {hasattr(tokenizer, 'do_lower_case')}")
print(f"has canonicalize_text method: {hasattr(tokenizer, 'canonicalize_text')}")
print()
words = ["lion", "Lion", "hippo", "Hippo", "giraffe", "Giraffe"]
print("--- tokenization ---")
for w in words:
ids = tokenizer(w, add_special_tokens=False)["input_ids"]
pieces = tokenizer.convert_ids_to_tokens(ids)
print(f"{w!r:10s} -> ids={ids} pieces={pieces}")
print()
inputs = processor(text=words, padding="max_length", return_tensors="pt")
with torch.no_grad():
features = F.normalize(model.get_text_features(**inputs), dim=-1)
sim = features @ features.T
print("--- pairwise cosine similarity of text embeddings ---")
header = " " + " ".join(f"{w:>8s}" for w in words)
print(header)
for i, w in enumerate(words):
row = " ".join(f"{sim[i, j].item():8.3f}" for j in range(len(words)))
print(f"{w:>8s} {row}")
print()
lower_avg = (sim[0, 2] + sim[0, 4] + sim[2, 4]).item() / 3 # lion, hippo, giraffe
upper_avg = (sim[1, 3] + sim[1, 5] + sim[3, 5]).item() / 3 # Lion, Hippo, Giraffe
print(f"avg similarity among {{lion, hippo, giraffe}}: {lower_avg:.3f} (distinct concepts)")
print(f"avg similarity among {{Lion, Hippo, Giraffe}}: {upper_avg:.3f} (should NOT be this close)")Output:
tokenizer class: GemmaTokenizerFast
has do_lower_case attr: False
has canonicalize_text method: False
--- tokenization ---
'lion' -> ids=[14340] pieces=['lion']
'Lion' -> ids=[54113] pieces=['Lion']
'hippo' -> ids=[173690] pieces=['hippo']
'Hippo' -> ids=[143241] pieces=['Hippo']
'giraffe' -> ids=[126258, 10303] pieces=['gira', 'ffe']
'Giraffe' -> ids=[233208] pieces=['Giraffe']
--- pairwise cosine similarity of text embeddings ---
lion Lion hippo Hippo giraffe Giraffe
lion 1.000 0.833 0.897 0.835 0.905 0.831
Lion 0.833 1.000 0.802 0.997 0.821 0.998
hippo 0.897 0.802 1.000 0.805 0.903 0.801
Hippo 0.835 0.997 0.805 1.000 0.823 0.996
giraffe 0.905 0.821 0.903 0.823 1.000 0.821
Giraffe 0.831 0.998 0.801 0.996 0.821 1.000
avg similarity among {lion, hippo, giraffe}: 0.902 (distinct concepts)
avg similarity among {Lion, Hippo, Giraffe}: 0.997 (should NOT be this close)Expected behavior
Either:
- SigLIP2's tokenizer/processor should canonicalize (lowercase) text before tokenization, matching SigLIP v1's
SiglipTokenizerbehavior, or - If this is intentional (e.g. because SigLIP2 was trained without lowercasing, unlike v1), it should be documented prominently on the model card, since it's a significant, easy-to-hit footgun for anyone doing zero-shot classification or text-to-image retrieval with capitalized or title-case input.
Source: huggingface/transformers