File size: 710 Bytes
1e8fbed
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# 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})")