Views
No views yet
MultiVectorEncoder:pip install "sentence-transformers>=6.0.0"1from sentence_transformers import MultiVectorEncoder
2
3model = MultiVectorEncoder("antoinelouis/colbert-xm")
4
5query = "Which planet is known as the Red Planet?"
6documents = [
7 "Venus wird oft als Zwilling der Erde bezeichnet, wegen ihrer ähnlichen Größe.",
8 "Mars, connue pour son apparence rougeâtre, est souvent appelée la planète rouge.",
9 "Júpiter es el planeta más grande del sistema solar.",
10 "Saturno è famoso per i suoi bellissimi anelli.",
11]
12
13query_embeddings = model.encode_query(query)
14document_embeddings = model.encode_document(documents)
15print(query_embeddings.shape, document_embeddings[0].shape)
16# (32, 128) (21, 128)
17
18# MaxSim late-interaction scoring (higher is more relevant)
19scores = model.similarity(query_embeddings, document_embeddings)
20print(scores)
21# tensor([[11.1658, 18.7137, 12.6985, 8.1900]])pip install git+https://github.com/stanford-futuredata/ColBERT.git@main torchtorch==2.1.2 faiss-gpu==1.7.2 langdetect==1.0.91# Use of custom modules that automatically detect the language of the passages to index and activate the language-specific adapters accordingly
2from .custom import CustomIndexer, CustomSearcher
3from colbert.infra import Run, RunConfig
4
5n_gpu: int = 1 # Set your number of available GPUs
6experiment: str = "colbert" # Name of the folder where the logs and created indices will be stored
7index_name: str = "my_index" # The name of your index, i.e. the name of your vector database
8documents: list = ["Ceci est un premier document.", "Voici un second document.", "etc."] # Corpus
9
10# Step 1: Indexing. This step encodes all passages into matrices, stores them on disk, and builds data structures for efficient search.
11with Run().context(RunConfig(nranks=n_gpu,experiment=experiment)):
12 indexer = CustomIndexer(checkpoint="antoinelouis/colbert-xm")
13 indexer.index(name=index_name, collection=documents)
14
15# Step 2: Searching. Given the model and index, you can issue queries over the collection to retrieve the top-k passages for each query.
16with Run().context(RunConfig(nranks=n_gpu,experiment=experiment)):
17 searcher = CustomSearcher(index=index_name) # You don't need to specify checkpoint again, the model name is stored in the index.
18 results = searcher.search(query="Comment effectuer une recherche avec ColBERT ?", k=10)
19 # results: tuple of tuples of length k containing ((passage_id, passage_rank, passage_score), ...)| model | Type | #Samples | #Params | en | es | fr | it | pt | id | de | ru | zh | ja | nl | vi | hi | ar | Avg. | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | BM25 (Pyserini) | lexical | - | - | 18.4 | 15.8 | 15.5 | 15.3 | 15.2 | 14.9 | 13.6 | 12.4 | 11.6 | 14.1 | 14.0 | 13.6 | 13.4 | 11.1 | 14.2 |
| 2 | mono-mT5 (Bonfacio et al., 2021) | cross-encoder | 12.8M | 390M | 36.6 | 31.4 | 30.2 | 30.3 | 30.2 | 29.8 | 28.9 | 26.3 | 24.9 | 26.7 | 29.2 | 25.6 | 26.6 | 23.5 | 28.6 |
| 3 | mono-mMiniLM (Bonfacio et al., 2021) | cross-encoder | 80.0M | 107M | 36.6 | 30.9 | 29.6 | 29.1 | 28.9 | 29.3 | 27.8 | 25.1 | 24.9 | 26.3 | 27.6 | 24.7 | 26.2 | 21.9 | 27.8 |
| 4 | DPR-X (Yang et al., 2022) | single-vector | 25.6M | 550M | 24.5 | 19.6 | 18.9 | 18.3 | 19.0 | 16.9 | 18.2 | 17.7 | 14.8 | 15.4 | 18.5 | 15.1 | 15.4 | 12.9 | 17.5 |
| 5 | mE5-base (Wang et al., 2024) | single-vector | 5.1B | 278M | 35.0 | 28.9 | 30.3 | 28.0 | 27.5 | 26.1 | 27.1 | 24.5 | 22.9 | 25.0 | 27.3 | 23.9 | 24.2 | 20.5 | 26.5 |
| 6 | mColBERT (Bonfacio et al., 2021) | multi-vector | 25.6M | 180M | 35.2 | 30.1 | 28.9 | 29.2 | 29.2 | 27.5 | 28.1 | 25.0 | 24.6 | 23.6 | 27.3 | 18.0 | 23.2 | 20.9 | 26.5 |
| 7 | DPR-XM (ours) | single-vector | 25.6M | 277M | 32.7 | 23.6 | 23.5 | 22.3 | 22.7 | 22.0 | 22.1 | 19.9 | 18.1 | 18.7 | 22.9 | 18.0 | 16.0 | 15.1 | 21.3 |
| 8 | ColBERT-XM (ours) | multi-vector | 6.4M | 277M | 37.2 | 28.5 | 26.9 | 26.5 | 27.6 | 26.3 | 27.0 | 25.1 | 24.6 | 24.1 | 27.5 | 22.6 | 23.8 | 19.5 | 26.2 |
| model | Type | #Samples | #Params | ar | bn | en | fi | id | ja | ko | ru | sw | te | Avg. | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| MRR@100 | |||||||||||||||
| 1 | BM25 (Pyserini) | lexical | - | - | 36.8 | 41.8 | 14.0 | 28.4 | 37.6 | 21.1 | 28.5 | 31.3 | 38.9 | 34.3 | 31.3 |
| 2 | mono-mT5 (Bonfacio et al., 2021) | cross-encoder | 12.8M | 390M | 62.2 | 65.1 | 35.7 | 49.5 | 61.1 | 48.1 | 47.4 | 52.6 | 62.9 | 66.6 | 55.1 |
| 3 | mColBERT (Bonfacio et al., 2021) | multi-vector | 25.6M | 180M | 55.3 | 48.8 | 32.9 | 41.3 | 55.5 | 36.6 | 36.7 | 48.2 | 44.8 | 61.6 | 46.1 |
| 4 | ColBERT-XM (ours) | multi-vector | 6.4M | 277M | 55.2 | 56.6 | 36.0 | 41.8 | 57.1 | 42.1 | 41.3 | 52.2 | 56.8 | 50.6 | 49.0 |
| R@100 | |||||||||||||||
| 5 | BM25 (Pyserini) | lexical | - | - | 79.3 | 86.9 | 53.7 | 71.9 | 84.3 | 64.5 | 61.9 | 64.8 | 76.4 | 75.8 | 72.0 |
| 6 | mono-mT5 (Bonfacio et al., 2021) | cross-encoder | 12.8M | 390M | 88.4 | 92.3 | 72.4 | 85.1 | 92.8 | 83.2 | 76.5 | 76.3 | 83.8 | 85.0 | 83.5 |
| 7 | mColBERT (Bonfacio et al., 2021) | multi-vector | 25.6M | 180M | 85.9 | 91.8 | 78.6 | 82.6 | 91.1 | 70.9 | 72.9 | 86.1 | 80.8 | 96.9 | 83.7 |
| 8 | ColBERT-XM (ours) | multi-vector | 6.4M | 277M | 89.6 | 91.4 | 83.7 | 84.4 | 93.8 | 84.9 | 77.6 | 89.1 | 87.1 | 93.3 | 87.5 |
1@article{louis2024modular,
2 author = {Louis, Antoine and Saxena, Vageesh and van Dijck, Gijs and Spanakis, Gerasimos},
3 title = {ColBERT-XM: A Modular Multi-Vector Representation Model for Zero-Shot Multilingual Information Retrieval},
4 journal = {CoRR},
5 volume = {abs/2402.15059},
6 year = {2024},
7 url = {https://arxiv.org/abs/2402.15059},
8 doi = {10.48550/arXiv.2402.15059},
9 eprinttype = {arXiv},
10 eprint = {2402.15059},
11}