Install the python client

First, install the Python client.

$ pip install basilica

Embed some sentences

Let's embed some sentences to make sure the client is working.

import basilica
sentences = [
    "This is a sentence!",
    "This is a similar sentence!",
    "I don't think this sentence is very similar at all...",

with basilica.Connection('SLOW_DEMO_KEY') as c:

    embeddings = list(c.embed_sentences(sentences))
[[0.8556405305862427, ...], ...]

Let's also make sure these embeddings make sense, by checking that the cosine distance between the two similar sentences is smaller:

from scipy import spatial
print(spatial.distance.cosine(embeddings[0], embeddings[1]))
print(spatial.distance.cosine(embeddings[0], embeddings[2]))


Great! You can see that the two very similar strings are much closer in this feature space. This same feature extraction can be use in a lot of different ways, including training regressions, classifiers, and clustering.