Sponsored by
Vmake Labs Video Enhancer
-Vmake Labs Video Enhancer uses AI to improve video quality, restore details, reduce blur, and upscale videos to 8K.
ColBERT is a
fast
and
accurate
retrieval model, enabling scalable BERT-based search over large text collections in tens of milliseconds.
Figure 1:
ColBERT's late interaction, efficiently scoring the fine-grained similarity between a queries and a passage.
As Figure 1 illustrates, ColBERT relies on fine-grained
contextual late interaction
: it encodes each passage into a
matrix
of token-level embeddings (shown above in blue). Then at search time, it embeds every query into another matrix (shown in green) and efficiently finds passages that contextually match the query using scalable vector-similarity (
MaxSim
) operators.
These rich interactions allow ColBERT to surpass the quality of
single-vector
representation models, while scaling efficiently to large corpora. You can read more in our papers:
(1/29/23) We have merged a new index updater feature and support for additional Hugging Face models! These are in beta so please give us feedback as you try them out.
We strongly recommend creating a conda environment using the commands below. (If you don't have conda, follow the official
conda installation guide
.)
We have also included a new environment file specifically for CPU-only environments (
conda_env_cpu.yml
), but note that if you are testing CPU execution on a machine that includes GPUs you might need to specify
CUDA_VISIBLE_DEVICES=""
as part of your command. Note that a GPU is required for training and indexing.
If you face any problems, please
open a new issue
and we'll help you promptly!
Overview
Using ColBERT on a dataset typically involves the following steps.
Step 0: Preprocess your collection.
At its simplest, ColBERT works with tab-separated (TSV) files: a file (e.g.,
collection.tsv
) will contain all passages and another (e.g.,
queries.tsv
) will contain a set of queries for searching the collection.
Step 2: Index your collection.
Once you have a trained ColBERT model, you need to
index your collection
to permit fast retrieval. This step encodes all passages into matrices, stores them on disk, and builds data structures for efficient search.
Step 3: Search the collection with your queries.
Given the model and index, you can
issue queries over the collection
to retrieve the top-k passages for each query.
Below, we illustrate these steps via an example run on the MS MARCO Passage Ranking task.
API Usage Notebook
NEW
: We have an experimental notebook on
Google Colab
that you can use with free GPUs. Indexing 10,000 on the free Colab T4 GPU takes six minutes.
This Jupyter notebook
docs/intro.ipynb notebook
illustrates using the key features of ColBERT with the new Python API.
It includes how to download the ColBERTv2 model checkpoint trained on MS MARCO Passage Ranking and how to download our new LoTTE benchmark.
Data
This repository works directly with a simple
tab-separated file
format to store queries, passages, and top-k ranked lists.
Queries: each line is
qid \t query text
.
Collection: each line is
pid \t passage text
.
Top-k Ranking: each line is
qid \t pid \t rank
.
This works directly with the data format of the
MS MARCO Passage Ranking
dataset. You will need the training triples (
triples.train.small.tar.gz
), the official top-1000 ranked lists for the dev set queries (
top1000.dev
), and the dev set relevant passages (
qrels.dev.small.tsv
). For indexing the full collection, you will also need the list of passages (
collection.tar.gz
).
Indexing
For fast retrieval, indexing precomputes the ColBERT representations of passages.
Example usage:
from colbert.infra import Run, RunConfig, ColBERTConfig
from colbert import Indexer
if __name__=='__main__':
with Run().context(RunConfig(nranks=1, experiment="msmarco")):
config = ColBERTConfig(
nbits=2,
root="/path/to/experiments",
)
indexer = Indexer(checkpoint="/path/to/checkpoint", config=config)
indexer.index(name="msmarco.nbits=2", collection="/path/to/MSMARCO/collection.tsv")
Retrieval
We typically recommend that you use ColBERT for
end-to-end
retrieval, where it directly finds its top-k passages from the full collection:
from colbert.data import Queries
from colbert.infra import Run, RunConfig, ColBERTConfig
from colbert import Searcher
if __name__=='__main__':
with Run().context(RunConfig(nranks=1, experiment="msmarco")):
config = ColBERTConfig(
root="/path/to/experiments",
)
searcher = Searcher(index="msmarco.nbits=2", config=config)
queries = Queries("/path/to/MSMARCO/queries.dev.small.tsv")
ranking = searcher.search_all(queries, k=100)
ranking.save("msmarco.nbits=2.ranking.tsv")
You can optionally specify the
ncells
,
centroid_score_threshold
, and
ndocs
search hyperparameters to trade off between speed and result quality. Defaults for different values of
k
are listed in colbert/searcher.py.
We can evaluate the MSMARCO rankings using the following command:
We provide a
pre-trained model checkpoint
, but we also detail how to train from scratch here.
Note that this example demonstrates the ColBERTv1 style of training, but the provided checkpoint was trained with ColBERTv2.
Training requires a JSONL triples file with a
[qid, pid+, pid-]
list per line. The query IDs and passage IDs correspond to the specified
queries.tsv
and
collection.tsv
files respectively.
Example usage (training on 4 GPUs):
from colbert.infra import Run, RunConfig, ColBERTConfig
from colbert import Trainer
if __name__=='__main__':
with Run().context(RunConfig(nranks=4, experiment="msmarco")):
config = ColBERTConfig(
bsize=32,
root="/path/to/experiments",
)
trainer = Trainer(
triples="/path/to/MSMARCO/triples.train.small.tsv",
queries="/path/to/MSMARCO/queries.train.small.tsv",
collection="/path/to/MSMARCO/collection.tsv",
config=config,
)
checkpoint_path = trainer.train()
print(f"Saved checkpoint to {checkpoint_path}...")
Running a lightweight ColBERTv2 server
We provide a script to run a lightweight server which serves k (upto 100) results in ranked order for a given search query, in JSON format. This script can be used to power DSP programs.
To run the server, update the environment variables
INDEX_ROOT
and
INDEX_NAME
in the
.env
file to point to the appropriate ColBERT index. The run the following command:
python server.py
A sample query:
http://localhost:8893/api/search?query=Who won the 2022 FIFA world cup&k=25
binarization
: ColBERT with a baseline binarization-based compression strategy (as opposed to ColBERTv2's residual compression, which we found to be more robust).
Acknowledgments
ColBERT logo designed by Chuyi Zhang.
Runs of colbert-ir colbertv2.0 on huggingface.co
1.4M
Total runs
-185.4K
24-hour runs
-236.7K
3-day runs
-182.2K
7-day runs
-185.9K
30-day runs
More Information About colbertv2.0 huggingface.co Model
colbertv2.0 huggingface.co is an AI model on huggingface.co that provides colbertv2.0's model effect (), which can be used instantly with this colbert-ir colbertv2.0 model. huggingface.co supports a free trial of the colbertv2.0 model, and also provides paid use of the colbertv2.0. Support call colbertv2.0 model through api, including Node.js, Python, http.
colbertv2.0 huggingface.co is an online trial and call api platform, which integrates colbertv2.0's modeling effects, including api services, and provides a free online trial of colbertv2.0, you can try colbertv2.0 online for free by clicking the link below.
colbert-ir colbertv2.0 online free url in huggingface.co:
colbertv2.0 is an open source model from GitHub that offers a free installation service, and any user can find colbertv2.0 on GitHub to install. At the same time, huggingface.co provides the effect of colbertv2.0 install, users can directly use colbertv2.0 installed effect in huggingface.co for debugging and trial. It also supports api for free installation.