Views
No views yet
mt5 variants use SentencePiece. Class prompts can be non-English without a separate multilingual checkpoint.facebook/metaclip-2-worldwide-huge-378 for zeromodels. One implementation runs unmodified on TensorFlow / Torch / JAX.MetaClip2ZeroShotClassify). The quick start below scores the same concept in English / French / Spanish / German against one distractor.1import os
2os.environ["KERAS_BACKEND"] = "torch" # or "jax" / "tensorflow"
3
4import keras
5from zeromodels.models.metaclip2 import (
6 MetaClip2Processor,
7 MetaClip2ZeroShotClassify,
8)
9
10processor = MetaClip2Processor.from_weights("zeromodels/metaclip2_worldwide_huge_378")
11model = MetaClip2ZeroShotClassify.from_weights("zeromodels/metaclip2_worldwide_huge_378")
12
13# Same concept in four languages + one English distractor.
14# Unlike CLIP (English BPE) / SigLIP v1, MetaCLIP 2 is trained worldwide.
15labels = [
16 "a photo of teddy bears", # English
17 "une photo d'ours en peluche", # French
18 "una foto de ositos de peluche", # Spanish
19 "ein Foto von Teddybären", # German
20 "a photo of a truck", # distractor
21]
22inputs = processor(text=labels, image_paths="your_image.jpg")
23output = model(
24 {
25 "images": inputs["images"],
26 "token_ids": inputs["token_ids"],
27 "padding_mask": inputs["padding_mask"],
28 }
29)
30probs = keras.ops.convert_to_numpy(
31 keras.ops.softmax(output["image_logits"], axis=-1)
32).squeeze()
33for label, p in zip(labels, probs):
34 print(f"{p:.6f} {label}")from_weights("zeromodels/<variant>"):KERAS_BACKEND before importing Keras / zeromodels.Processor.from_weights(...) so image size and tokenizer match the variant.token_ids / padding_mask (not input_ids / attention_mask).Teddybären vs Teddybaren).hf: prefix, e.g. MetaClip2ZeroShotClassify.from_weights("hf:facebook/metaclip-2-worldwide-huge-378").