Expand code snippet for easier use

#1
by tomaarsen HF Staff - opened

Hello @xiaoxiaoshadiao and team,

First of all, congratulations on the release! I'm a big fan of using the retrieve & rerank pipeline for finding the correct skills to use, so it's nice to see more progress here.
I wanted to make it even easier for users to understand how to use it, so I updated the README here. It also removes trust_remote_code=True, as that's actually not even necessary!

from sentence_transformers import SentenceTransformer

model = SentenceTransformer("tencent/R3-embedding-0.6b")
query_embedding = model.encode_query("I need to compose music")
document_embeddings = model.encode_document([  # The format is "name | description | skill_md"
    "music-composer | Composes original music | Creates music for various media formats ...",
    "music-lyricist | Writes lyrics for songs | Creates lyrics for various music genres ...",
    "music-editor | Edits and mixes music tracks | Provides audio editing and mixing services ...",
])
similarities = model.similarity(query_embedding, document_embeddings)
print(similarities)
# tensor([[0.7410, 0.5510, 0.5028]])

With the output similarity it's immediately clear that it works as expected.

  • Tom Aarsen
tomaarsen changed pull request status to open
xiaoxiaoshadiao changed pull request status to merged

Thank you for the pr, which has made our README clearer.

Sign up or log in to comment