Add Sentence Transformers usage

#1
by tomaarsen HF Staff - opened

Hello!

Starting with the next Sentence Transformers release (v6.0.0, planned for around the 18th), this checkpoint loads directly as a multi-vector (ColBERT-style late interaction) retriever through the new MultiVectorEncoder, alongside its existing PyLate usage. This PR adds a Sentence Transformers usage section to the model card and a multi-vector tag. The weights and the existing PyLate usage are untouched.

I'd love to feature this model in that release's blog post and documentation, especially once it loads without the revision pin (that is, once this PR is merged).

pip install "sentence-transformers @ git+https://github.com/huggingface/sentence-transformers.git"
from sentence_transformers import MultiVectorEncoder

model = MultiVectorEncoder("VAGOsolutions/SauerkrautLM-Multi-ModernColBERT", revision="refs/pr/1")

query = "Welcher Planet ist als der Rote Planet bekannt?"
documents = [
    "Venus wird wegen ihrer ähnlichen Größe und Nähe oft als Erdzwilling bezeichnet.",
    "Mars, bekannt für sein rötliches Aussehen, wird oft als der Rote Planet bezeichnet.",
    "Jupiter, der größte Planet in unserem Sonnensystem, hat einen markanten roten Fleck.",
    "Saturn, berühmt für seine Ringe, wird manchmal für den Roten Planeten gehalten.",
]

query_embeddings = model.encode_query(query)
document_embeddings = model.encode_document(documents)
print(query_embeddings.shape, document_embeddings[0].shape)
# (32, 128) (29, 128)

# MaxSim late-interaction scoring (higher is more relevant)
scores = model.similarity(query_embeddings, document_embeddings)
print(scores)
# tensor([[28.7305, 29.5820, 29.0117, 29.1172]])
  • Tom Aarsen
tomaarsen changed pull request status to open
DavidGF changed pull request status to merged

Sign up or log in to comment