Views
No views yet
Transformer → Pooling → Dense(768→3072) → Dense(3072→768) → Normalize, all in one graph.
Output sentence_embedding is the final L2-normalized 768-d sentence vector — no external
pooling or projection needed (unlike transformer-only exports, which produce different vectors).torch.onnx.export (opset 17) from the official weights and verified against the
torch pipeline: worst-case cosine similarity = 1.000000 across batch sizes and sequence lengths
(short + long, batched + single). Vectors are interchangeable with the original model — existing
indexes need no re-embedding.src/scripts/export_embed_onnx.py| File | SHA-256 |
|---|---|
model.onnx (graph) | 39a1f3039ed66e39c5174469dc5ce0417ef57993590170164b18beb8254de2d0 |
model.onnx.data (fp32 weights, external data) | 1d5fb11500ae836f3a42efc3c7123076416d9e527ae479d19d940a3c784f0035 |
tokenizer.json | 3f797e7e336523ba3845bf09a648fd87c14bf357f26beb091d8284dff48ea27c |
meta.json (dim, max_seq_length, pad id) | b149d450b0bd383a207b3328cb9dd093082077c84eb4e178418a2db0f4f2dccf |
model.onnx and model.onnx.data must sit in the same directory (ONNX external-data format).1import json, numpy as np, onnxruntime as ort
2from tokenizers import Tokenizer
3
4meta = json.load(open("meta.json"))
5tok = Tokenizer.from_file("tokenizer.json")
6tok.enable_truncation(max_length=meta["max_seq_length"])
7tok.enable_padding(pad_id=meta["pad_token_id"], pad_token="<pad>")
8sess = ort.InferenceSession("model.onnx", providers=["CPUExecutionProvider"])
9
10# embeddinggemma is ASYMMETRIC — use the matching prompt prefixes:
11docs = ["title: none | text: The user's name is Ravi."]
12enc = tok.encode_batch(docs)
13vecs = sess.run(["sentence_embedding"], {
14 "input_ids": np.array([e.ids for e in enc], dtype=np.int64),
15 "attention_mask": np.array([e.attention_mask for e in enc], dtype=np.int64),
16})[0] # (batch, 768), already L2-normalizedtask: search result | query: .GEMMA_TERMS_OF_USE.md, GEMMA_PROHIBITED_USE_POLICY.md, NOTICE) — by using these
weights you agree to those terms.