FilBona's picture
EmbeddingGemma 2 (text) in Core ML, 8-bit, fixed 512 tokens, for the Apple Neural Engine
cecc10e verified
Raw History Blame Contribute Delete
615 Bytes
import torch, numpy as np, json
from sentence_transformers import SentenceTransformer
m = SentenceTransformer("google/embeddinggemma-2", device="cpu")
print(m)
texts = ["task: search result | query: quando finisce la posizione dei QA?",
"title: none | text: Marco: allora il contratto del tester scade il primo gennaio 2027, poi vediamo.",
"title: none | text: Giulia porta il vino alla cena di domenica, Maria Grazia il dolce.",
"task: search result | query: chi porta il dolce?"]
e = m.encode(texts, normalize_embeddings=True)
np.save("ref.npy", e)
print(e.shape, np.round(e @ e.T, 3))