Instructions to use colbert-ir/colbertv2.0 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use colbert-ir/colbertv2.0 with Transformers:
# Load model directly from transformers import AutoTokenizer, HF_ColBERT tokenizer = AutoTokenizer.from_pretrained("colbert-ir/colbertv2.0") model = HF_ColBERT.from_pretrained("colbert-ir/colbertv2.0", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Add Sentence Transformers usage
#16
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. This PR adds a Sentence Transformers usage section to the model card and the multi-vector and sentence-transformers tags. The weights and the existing 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("colbert-ir/colbertv2.0", revision="refs/pr/16")
query = "Which planet is known as the Red Planet?"
documents = [
"Venus is often called Earth's twin because of its similar size and proximity.",
"Mars, known for its reddish appearance, is often referred to as the Red Planet.",
"Jupiter, the largest planet in our solar system, has a prominent red spot.",
"Saturn, famous for its rings, is sometimes mistaken for the Red Planet.",
]
query_embeddings = model.encode_query(query)
document_embeddings = model.encode_document(documents)
print(query_embeddings.shape, document_embeddings[0].shape)
# (32, 128) (17, 128)
# MaxSim late-interaction scoring (higher is more relevant)
scores = model.similarity(query_embeddings, document_embeddings)
print(scores)
# tensor([[12.7970, 27.1945, 23.8495, 24.5656]])
- Tom Aarsen
tomaarsen changed pull request status to open