Update README.md
Browse files
README.md
CHANGED
@@ -9,206 +9,10 @@ tags:
|
|
9 |
Essentially contains ColBert V2 Repo from Huggingface along with a .ragatouille folder containing the indexed form of [Guidelines](https://huggingface.co/datasets/epfl-llm/guidelines) dataset.
|
10 |
https://github.com/bclavie/RAGatouille
|
11 |
|
12 |
-
#
|
|
|
|
|
13 |
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
<p align="center">
|
20 |
-
<img align="center" src="docs/images/ColBERT-Framework-MaxSim-W370px.png" />
|
21 |
-
</p>
|
22 |
-
<p align="center">
|
23 |
-
<b>Figure 1:</b> ColBERT's late interaction, efficiently scoring the fine-grained similarity between a queries and a passage.
|
24 |
-
</p>
|
25 |
-
|
26 |
-
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.
|
27 |
-
|
28 |
-
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:
|
29 |
-
|
30 |
-
* [**ColBERT: Efficient and Effective Passage Search via Contextualized Late Interaction over BERT**](https://arxiv.org/abs/2004.12832) (SIGIR'20).
|
31 |
-
* [**Relevance-guided Supervision for OpenQA with ColBERT**](https://arxiv.org/abs/2007.00814) (TACL'21).
|
32 |
-
* [**Baleen: Robust Multi-Hop Reasoning at Scale via Condensed Retrieval**](https://arxiv.org/abs/2101.00436) (NeurIPS'21).
|
33 |
-
* [**ColBERTv2: Effective and Efficient Retrieval via Lightweight Late Interaction**](https://arxiv.org/abs/2112.01488) (NAACL'22).
|
34 |
-
* [**PLAID: An Efficient Engine for Late Interaction Retrieval**](https://arxiv.org/abs/2205.09707) (CIKM'22).
|
35 |
-
|
36 |
-
----
|
37 |
-
|
38 |
-
## 🚨 **Announcements**
|
39 |
-
|
40 |
-
* (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.
|
41 |
-
* (1/24/23) If you're looking for the **DSP** framework for composing ColBERTv2 and LLMs, it's at: https://github.com/stanfordnlp/dsp
|
42 |
-
|
43 |
-
----
|
44 |
-
|
45 |
-
## ColBERTv1
|
46 |
-
|
47 |
-
The ColBERTv1 code from the SIGIR'20 paper is in the [`colbertv1` branch](https://github.com/stanford-futuredata/ColBERT/tree/colbertv1). See [here](#branches) for more information on other branches.
|
48 |
-
|
49 |
-
|
50 |
-
## Installation
|
51 |
-
|
52 |
-
ColBERT requires Python 3.7+ and Pytorch 1.9+ and uses the [Hugging Face Transformers](https://github.com/huggingface/transformers) library.
|
53 |
-
|
54 |
-
We strongly recommend creating a conda environment using the commands below. (If you don't have conda, follow the official [conda installation guide](https://docs.anaconda.com/anaconda/install/linux/#installation).)
|
55 |
-
|
56 |
-
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.
|
57 |
-
|
58 |
-
```
|
59 |
-
conda env create -f conda_env[_cpu].yml
|
60 |
-
conda activate colbert
|
61 |
-
```
|
62 |
-
|
63 |
-
If you face any problems, please [open a new issue](https://github.com/stanford-futuredata/ColBERT/issues) and we'll help you promptly!
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
## Overview
|
68 |
-
|
69 |
-
Using ColBERT on a dataset typically involves the following steps.
|
70 |
-
|
71 |
-
**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.
|
72 |
-
|
73 |
-
**Step 1: Download the [pre-trained ColBERTv2 checkpoint](https://downloads.cs.stanford.edu/nlp/data/colbert/colbertv2/colbertv2.0.tar.gz).** This checkpoint has been trained on the MS MARCO Passage Ranking task. You can also _optionally_ [train your own ColBERT model](#training).
|
74 |
-
|
75 |
-
**Step 2: Index your collection.** Once you have a trained ColBERT model, you need to [index your collection](#indexing) to permit fast retrieval. This step encodes all passages into matrices, stores them on disk, and builds data structures for efficient search.
|
76 |
-
|
77 |
-
**Step 3: Search the collection with your queries.** Given the model and index, you can [issue queries over the collection](#retrieval) to retrieve the top-k passages for each query.
|
78 |
-
|
79 |
-
Below, we illustrate these steps via an example run on the MS MARCO Passage Ranking task.
|
80 |
-
|
81 |
-
|
82 |
-
## API Usage Notebook
|
83 |
-
|
84 |
-
**NEW**: We have an experimental notebook on [Google Colab](https://colab.research.google.com/github/stanford-futuredata/ColBERT/blob/main/docs/intro2new.ipynb) that you can use with free GPUs. Indexing 10,000 on the free Colab T4 GPU takes six minutes.
|
85 |
-
|
86 |
-
This Jupyter notebook **[docs/intro.ipynb notebook](docs/intro.ipynb)** illustrates using the key features of ColBERT with the new Python API.
|
87 |
-
|
88 |
-
It includes how to download the ColBERTv2 model checkpoint trained on MS MARCO Passage Ranking and how to download our new LoTTE benchmark.
|
89 |
-
|
90 |
-
|
91 |
-
## Data
|
92 |
-
|
93 |
-
This repository works directly with a simple **tab-separated file** format to store queries, passages, and top-k ranked lists.
|
94 |
-
|
95 |
-
|
96 |
-
* Queries: each line is `qid \t query text`.
|
97 |
-
* Collection: each line is `pid \t passage text`.
|
98 |
-
* Top-k Ranking: each line is `qid \t pid \t rank`.
|
99 |
-
|
100 |
-
This works directly with the data format of the [MS MARCO Passage Ranking](https://github.com/microsoft/MSMARCO-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`).
|
101 |
-
|
102 |
-
|
103 |
-
## Indexing
|
104 |
-
|
105 |
-
For fast retrieval, indexing precomputes the ColBERT representations of passages.
|
106 |
-
|
107 |
-
Example usage:
|
108 |
-
|
109 |
-
```
|
110 |
-
from colbert.infra import Run, RunConfig, ColBERTConfig
|
111 |
-
from colbert import Indexer
|
112 |
-
|
113 |
-
if __name__=='__main__':
|
114 |
-
with Run().context(RunConfig(nranks=1, experiment="msmarco")):
|
115 |
-
|
116 |
-
config = ColBERTConfig(
|
117 |
-
nbits=2,
|
118 |
-
root="/path/to/experiments",
|
119 |
-
)
|
120 |
-
indexer = Indexer(checkpoint="/path/to/checkpoint", config=config)
|
121 |
-
indexer.index(name="msmarco.nbits=2", collection="/path/to/MSMARCO/collection.tsv")
|
122 |
-
```
|
123 |
-
|
124 |
-
|
125 |
-
## Retrieval
|
126 |
-
|
127 |
-
We typically recommend that you use ColBERT for **end-to-end** retrieval, where it directly finds its top-k passages from the full collection:
|
128 |
-
|
129 |
-
```
|
130 |
-
from colbert.data import Queries
|
131 |
-
from colbert.infra import Run, RunConfig, ColBERTConfig
|
132 |
-
from colbert import Searcher
|
133 |
-
|
134 |
-
if __name__=='__main__':
|
135 |
-
with Run().context(RunConfig(nranks=1, experiment="msmarco")):
|
136 |
-
|
137 |
-
config = ColBERTConfig(
|
138 |
-
root="/path/to/experiments",
|
139 |
-
)
|
140 |
-
searcher = Searcher(index="msmarco.nbits=2", config=config)
|
141 |
-
queries = Queries("/path/to/MSMARCO/queries.dev.small.tsv")
|
142 |
-
ranking = searcher.search_all(queries, k=100)
|
143 |
-
ranking.save("msmarco.nbits=2.ranking.tsv")
|
144 |
-
```
|
145 |
-
|
146 |
-
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.
|
147 |
-
|
148 |
-
We can evaluate the MSMARCO rankings using the following command:
|
149 |
-
|
150 |
-
```
|
151 |
-
python -m utility.evaluate.msmarco_passages --ranking "/path/to/msmarco.nbits=2.ranking.tsv" --qrels "/path/to/MSMARCO/qrels.dev.small.tsv"
|
152 |
-
```
|
153 |
-
|
154 |
-
## Training
|
155 |
-
|
156 |
-
We provide a [pre-trained model checkpoint](https://downloads.cs.stanford.edu/nlp/data/colbert/colbertv2/colbertv2.0.tar.gz), but we also detail how to train from scratch here.
|
157 |
-
Note that this example demonstrates the ColBERTv1 style of training, but the provided checkpoint was trained with ColBERTv2.
|
158 |
-
|
159 |
-
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.
|
160 |
-
|
161 |
-
Example usage (training on 4 GPUs):
|
162 |
-
|
163 |
-
```
|
164 |
-
from colbert.infra import Run, RunConfig, ColBERTConfig
|
165 |
-
from colbert import Trainer
|
166 |
-
|
167 |
-
if __name__=='__main__':
|
168 |
-
with Run().context(RunConfig(nranks=4, experiment="msmarco")):
|
169 |
-
|
170 |
-
config = ColBERTConfig(
|
171 |
-
bsize=32,
|
172 |
-
root="/path/to/experiments",
|
173 |
-
)
|
174 |
-
trainer = Trainer(
|
175 |
-
triples="/path/to/MSMARCO/triples.train.small.tsv",
|
176 |
-
queries="/path/to/MSMARCO/queries.train.small.tsv",
|
177 |
-
collection="/path/to/MSMARCO/collection.tsv",
|
178 |
-
config=config,
|
179 |
-
)
|
180 |
-
|
181 |
-
checkpoint_path = trainer.train()
|
182 |
-
|
183 |
-
print(f"Saved checkpoint to {checkpoint_path}...")
|
184 |
-
```
|
185 |
-
|
186 |
-
## Running a lightweight ColBERTv2 server
|
187 |
-
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.
|
188 |
-
|
189 |
-
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:
|
190 |
-
```
|
191 |
-
python server.py
|
192 |
-
```
|
193 |
-
|
194 |
-
A sample query:
|
195 |
-
```
|
196 |
-
http://localhost:8893/api/search?query=Who won the 2022 FIFA world cup&k=25
|
197 |
-
```
|
198 |
-
|
199 |
-
## Branches
|
200 |
-
|
201 |
-
### Supported branches
|
202 |
-
|
203 |
-
* [`main`](https://github.com/stanford-futuredata/ColBERT/tree/main): Stable branch with ColBERTv2 + PLAID.
|
204 |
-
* [`colbertv1`](https://github.com/stanford-futuredata/ColBERT/tree/colbertv1): Legacy branch for ColBERTv1.
|
205 |
-
|
206 |
-
### Deprecated branches
|
207 |
-
* [`new_api`](https://github.com/stanford-futuredata/ColBERT/tree/new_api): Base ColBERTv2 implementation.
|
208 |
-
* [`cpu_inference`](https://github.com/stanford-futuredata/ColBERT/tree/cpu_inference): ColBERTv2 implementation with CPU search support.
|
209 |
-
* [`fast_search`](https://github.com/stanford-futuredata/ColBERT/tree/fast_search): ColBERTv2 implementation with PLAID.
|
210 |
-
* [`binarization`](https://github.com/stanford-futuredata/ColBERT/tree/binarization): ColBERT with a baseline binarization-based compression strategy (as opposed to ColBERTv2's residual compression, which we found to be more robust).
|
211 |
-
|
212 |
-
## Acknowledgments
|
213 |
-
|
214 |
-
ColBERT logo designed by Chuyi Zhang.
|
|
|
9 |
Essentially contains ColBert V2 Repo from Huggingface along with a .ragatouille folder containing the indexed form of [Guidelines](https://huggingface.co/datasets/epfl-llm/guidelines) dataset.
|
10 |
https://github.com/bclavie/RAGatouille
|
11 |
|
12 |
+
# Usage
|
13 |
+
```py
|
14 |
+
from ragatouille import RAGPretrainedModel
|
15 |
|
16 |
+
RAG = RAGPretrainedModel.from_pretrained("Technoculture/guidelines-search")
|
17 |
+
results = RAG.search("Hypertension, Male, 40yo", index_name="index")
|
18 |
+
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|