all-MiniLM-L6-v2 / examples /quickstart.py
changh95's picture
tt-model push all-minilm-l6-v2 (container)
1e8fbed verified
Raw History Blame Contribute Delete
710 Bytes
# SPDX-License-Identifier: Apache-2.0
"""Quickstart: semantic search with all-MiniLM-L6-v2 on a Tenstorrent p150 (python examples/quickstart.py)."""
from tt_minilm.api import MiniLM
docs = ["Paris is the capital and most populous city of France.",
"Photovoltaic cells convert sunlight directly into electricity.",
"Build mileage gradually and include one long run per week before a marathon."]
queries = ["What is the capital of France?", "how do solar panels work", "marathon training tips"]
with MiniLM.from_pretrained() as m:
d = m.encode(docs)
q = m.encode(queries)
for i, s in enumerate(q @ d.T):
print(f"{queries[i]!r} -> {docs[int(s.argmax())]!r} ({s.max():.3f})")