Skip to content

Commit

Permalink
Clean up of dense inverted indexing code (#2263)
Browse files Browse the repository at this point in the history
  • Loading branch information
lintool authored Nov 18, 2023
1 parent 6fb9169 commit 6369184
Show file tree
Hide file tree
Showing 60 changed files with 2,244 additions and 1,177 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,11 @@ See individual pages for details!
| SPLADE++ CoCondenser-SelfDistil | [](docs/regressions/regressions-msmarco-passage-splade-pp-sd.md) | [](docs/regressions/regressions-dl19-passage-splade-pp-sd.md) | [](docs/regressions/regressions-dl20-passage-splade-pp-sd.md) |
| SPLADE++ CoCondenser-SelfDistil (ONNX) | [](docs/regressions/regressions-msmarco-passage-splade-pp-sd-onnx.md) | [](docs/regressions/regressions-dl19-passage-splade-pp-sd-onnx.md) | [](docs/regressions/regressions-dl20-passage-splade-pp-sd-onnx.md) |
| **Learned Dense** | | | |
| cosDPR-distil | [](docs/regressions/regressions-msmarco-passage-cos-dpr-distil.md) | [](docs/regressions/regressions-dl19-passage-cos-dpr-distil.md) | [](docs/regressions/regressions-dl20-passage-cos-dpr-distil.md) |
| cosDPR-distil (ONNX) | [](docs/regressions/regressions-msmarco-passage-cos-dpr-distil-onnx.md) | [](docs/regressions/regressions-dl19-passage-cos-dpr-distil-onnx.md) | [](docs/regressions/regressions-dl20-passage-cos-dpr-distil-onnx.md) |
| OpenAI-ada2 | [](docs/regressions/regressions-msmarco-passage-openai-ada2.md) | [](docs/regressions/regressions-dl19-passage-openai-ada2.md) | [](docs/regressions/regressions-dl20-passage-openai-ada2.md) |
| cosDPR-distil w/ HNSW | [](docs/regressions/regressions-msmarco-passage-cos-dpr-distil-hnsw.md) | [](docs/regressions/regressions-dl19-passage-cos-dpr-distil-hnsw.md) | [](docs/regressions/regressions-dl20-passage-cos-dpr-distil-hnsw.md) |
| cosDPR-distil w/ HSNW (ONNX) | [](docs/regressions/regressions-msmarco-passage-cos-dpr-distil-hnsw-onnx.md) | [](docs/regressions/regressions-dl19-passage-cos-dpr-distil-hnsw-onnx.md) | [](docs/regressions/regressions-dl20-passage-cos-dpr-distil-hnsw-onnx.md) |
| cosDPR-distil w/ "fake words" | [](docs/regressions/regressions-msmarco-passage-cos-dpr-distil-fw.md) | [](docs/regressions/regressions-dl19-passage-cos-dpr-distil-fw.md) | [](docs/regressions/regressions-dl20-passage-cos-dpr-distil-fw.md) |
| cosDPR-distil w/ "LexLSH" | [](docs/regressions/regressions-msmarco-passage-cos-dpr-distil-lexlsh.md) | [](docs/regressions/regressions-dl19-passage-cos-dpr-distil-lexlsh.md) | [](docs/regressions/regressions-dl20-passage-cos-dpr-distil-lexlsh.md) |
| OpenAI-ada2 w/ HNSW | [](docs/regressions/regressions-msmarco-passage-openai-ada2.md) | [](docs/regressions/regressions-dl19-passage-openai-ada2.md) | [](docs/regressions/regressions-dl20-passage-openai-ada2.md) |

### Available Corpora for Download

Expand Down
18 changes: 12 additions & 6 deletions docs/regressions.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,14 @@ nohup python src/main/python/run_regression.py --index --verify --search --regre
nohup python src/main/python/run_regression.py --index --verify --search --regression msmarco-passage-splade-distil-cocodenser-medium >& logs/log.msmarco-passage-splade-distil-cocodenser-medium &
nohup python src/main/python/run_regression.py --index --verify --search --regression msmarco-passage-splade-pp-ed >& logs/log.msmarco-passage-splade-pp-ed &
nohup python src/main/python/run_regression.py --index --verify --search --regression msmarco-passage-splade-pp-sd >& logs/log.msmarco-passage-splade-pp-sd &
nohup python src/main/python/run_regression.py --index --verify --search --regression msmarco-passage-cos-dpr-distil >& logs/log.msmarco-passage-cos-dpr-distil &
nohup python src/main/python/run_regression.py --index --verify --search --regression msmarco-passage-cos-dpr-distil-hnsw >& logs/log.msmarco-passage-cos-dpr-distil-hnsw &
nohup python src/main/python/run_regression.py --index --verify --search --regression msmarco-passage-cos-dpr-distil-fw >& logs/log.msmarco-passage-cos-dpr-distil-fw &
nohup python src/main/python/run_regression.py --index --verify --search --regression msmarco-passage-cos-dpr-distil-lexlsh >& logs/log.msmarco-passage-cos-dpr-distil-lexlsh &
nohup python src/main/python/run_regression.py --index --verify --search --regression msmarco-passage-openai-ada2 >& logs/log.msmarco-passage-openai-ada2 &

nohup python src/main/python/run_regression.py --search-pool 1 --index --verify --search --regression msmarco-passage-splade-pp-ed-onnx >& logs/log.msmarco-passage-splade-pp-ed-onnx &
nohup python src/main/python/run_regression.py --search-pool 1 --index --verify --search --regression msmarco-passage-splade-pp-sd-onnx >& logs/log.msmarco-passage-splade-pp-sd-onnx &
nohup python src/main/python/run_regression.py --search-pool 1 --index --verify --search --regression msmarco-passage-cos-dpr-distil-onnx >& logs/log.msmarco-passage-cos-dpr-distil-onnx &
nohup python src/main/python/run_regression.py --search-pool 1 --index --verify --search --regression msmarco-passage-cos-dpr-distil-hnsw-onnx >& logs/log.msmarco-passage-cos-dpr-distil-hnsw-onnx &

nohup python src/main/python/run_regression.py --index --verify --search --regression msmarco-doc >& logs/log.msmarco-doc &
nohup python src/main/python/run_regression.py --index --verify --search --regression msmarco-doc-wp >& logs/log.msmarco-doc-wp &
Expand All @@ -80,12 +82,14 @@ nohup python src/main/python/run_regression.py --index --verify --search --regre
nohup python src/main/python/run_regression.py --index --verify --search --regression dl19-passage-splade-distil-cocodenser-medium >& logs/log.dl19-passage-splade-distil-cocodenser-medium &
nohup python src/main/python/run_regression.py --index --verify --search --regression dl19-passage-splade-pp-ed >& logs/log.dl19-passage-splade-pp-ed &
nohup python src/main/python/run_regression.py --index --verify --search --regression dl19-passage-splade-pp-sd >& logs/log.dl19-passage-splade-pp-sd &
nohup python src/main/python/run_regression.py --index --verify --search --regression dl19-passage-cos-dpr-distil >& logs/log.dl19-passage-cos-dpr-distil &
nohup python src/main/python/run_regression.py --index --verify --search --regression dl19-passage-cos-dpr-distil-hnsw >& logs/log.dl19-passage-cos-dpr-distil-hnsw &
nohup python src/main/python/run_regression.py --index --verify --search --regression dl19-passage-cos-dpr-distil-fw >& logs/log.dl19-passage-cos-dpr-distil-fw &
nohup python src/main/python/run_regression.py --index --verify --search --regression dl19-passage-cos-dpr-distil-lexlsh >& logs/log.dl19-passage-cos-dpr-distil-lexlsh &
nohup python src/main/python/run_regression.py --index --verify --search --regression dl19-passage-openai-ada2 >& logs/log.dl19-passage-openai-ada2 &

nohup python src/main/python/run_regression.py --search-pool 1 --index --verify --search --regression dl19-passage-splade-pp-ed-onnx >& logs/log.dl19-passage-splade-pp-ed-onnx &
nohup python src/main/python/run_regression.py --search-pool 1 --index --verify --search --regression dl19-passage-splade-pp-sd-onnx >& logs/log.dl19-passage-splade-pp-sd-onnx &
nohup python src/main/python/run_regression.py --search-pool 1 --index --verify --search --regression dl19-passage-cos-dpr-distil-onnx >& logs/log.dl19-passage-cos-dpr-distil-onnx &
nohup python src/main/python/run_regression.py --search-pool 1 --index --verify --search --regression dl19-passage-cos-dpr-distil-hnsw-onnx >& logs/log.dl19-passage-cos-dpr-distil-hnsw-onnx &

nohup python src/main/python/run_regression.py --index --verify --search --regression dl19-doc >& logs/log.dl19-doc &
nohup python src/main/python/run_regression.py --index --verify --search --regression dl19-doc-wp >& logs/log.dl19-doc-wp &
Expand All @@ -110,12 +114,14 @@ nohup python src/main/python/run_regression.py --index --verify --search --regre
nohup python src/main/python/run_regression.py --index --verify --search --regression dl20-passage-splade-distil-cocodenser-medium >& logs/log.dl20-passage-splade-distil-cocodenser-medium &
nohup python src/main/python/run_regression.py --index --verify --search --regression dl20-passage-splade-pp-ed >& logs/log.dl20-passage-splade-pp-ed &
nohup python src/main/python/run_regression.py --index --verify --search --regression dl20-passage-splade-pp-sd >& logs/log.dl20-passage-splade-pp-sd &
nohup python src/main/python/run_regression.py --index --verify --search --regression dl20-passage-cos-dpr-distil >& logs/log.dl20-passage-cos-dpr-distil &
nohup python src/main/python/run_regression.py --index --verify --search --regression dl20-passage-cos-dpr-distil-hnsw >& logs/log.dl20-passage-cos-dpr-distil-hnsw &
nohup python src/main/python/run_regression.py --index --verify --search --regression dl20-passage-cos-dpr-distil-fw >& logs/log.dl20-passage-cos-dpr-distil-fw &
nohup python src/main/python/run_regression.py --index --verify --search --regression dl20-passage-cos-dpr-distil-lexlsh >& logs/log.dl20-passage-cos-dpr-distil-lexlsh &
nohup python src/main/python/run_regression.py --index --verify --search --regression dl20-passage-openai-ada2 >& logs/log.dl20-passage-openai-ada2 &

nohup python src/main/python/run_regression.py --search-pool 1 --index --verify --search --regression dl20-passage-splade-pp-ed-onnx >& logs/log.dl20-passage-splade-pp-ed-onnx &
nohup python src/main/python/run_regression.py --search-pool 1 --index --verify --search --regression dl20-passage-splade-pp-sd-onnx >& logs/log.dl20-passage-splade-pp-sd-onnx &
nohup python src/main/python/run_regression.py --search-pool 1 --index --verify --search --regression dl20-passage-cos-dpr-distil-onnx >& logs/log.dl20-passage-cos-dpr-distil-onnx &
nohup python src/main/python/run_regression.py --search-pool 1 --index --verify --search --regression dl20-passage-cos-dpr-distil-hnsw-onnx >& logs/log.dl20-passage-cos-dpr-distil-hnsw-onnx &

nohup python src/main/python/run_regression.py --index --verify --search --regression dl20-doc >& logs/log.dl20-doc &
nohup python src/main/python/run_regression.py --index --verify --search --regression dl20-doc-wp >& logs/log.dl20-doc-wp &
Expand Down
114 changes: 114 additions & 0 deletions docs/regressions/regressions-dl19-passage-cos-dpr-distil-fw.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
# Anserini Regressions: TREC 2019 Deep Learning Track (Passage)

**Model**: cosDPR-distil with inverted indexes using the "fake-words" technique (q=40); pre-encoded queries

This page describes regression experiments, integrated into Anserini's regression testing framework, using the cosDPR-distil model on the [TREC 2019 Deep Learning Track passage ranking task](https://trec.nist.gov/data/deep2019.html).
In these experiments, we are using pre-encoded queries (i.e., cached results of query encoding).

Note that the NIST relevance judgments provide far more relevant passages per topic, unlike the "sparse" judgments provided by Microsoft (these are sometimes called "dense" judgments to emphasize this contrast).
For additional instructions on working with MS MARCO passage collection, refer to [this page](experiments-msmarco-passage.md).

The exact configurations for these regressions are stored in [this YAML file](../../src/main/resources/regression/dl19-passage-cos-dpr-distil-fw.yaml).
Note that this page is automatically generated from [this template](../../src/main/resources/docgen/templates/dl19-passage-cos-dpr-distil-fw.template) as part of Anserini's regression pipeline, so do not modify this page directly; modify the template instead and then run `bin/build.sh` to rebuild the documentation.

From one of our Waterloo servers (e.g., `orca`), the following command will perform the complete regression, end to end:

```bash
python src/main/python/run_regression.py --index --verify --search --regression dl19-passage-cos-dpr-distil-fw
```

We make available a version of the MS MARCO Passage Corpus that has already been encoded with cosDPR-distil.

From any machine, the following command will download the corpus and perform the complete regression, end to end:

```bash
python src/main/python/run_regression.py --download --index --verify --search --regression dl19-passage-cos-dpr-distil-fw
```

The `run_regression.py` script automates the following steps, but if you want to perform each step manually, simply copy/paste from the commands below and you'll obtain the same regression results.

## Corpus Download

Download the corpus and unpack into `collections/`:

```bash
wget https://rgw.cs.uwaterloo.ca/pyserini/data/msmarco-passage-cos-dpr-distil.tar -P collections/
tar xvf collections/msmarco-passage-cos-dpr-distil.tar -C collections/
```

To confirm, `msmarco-passage-cos-dpr-distil.tar` is 57 GB and has MD5 checksum `e20ffbc8b5e7f760af31298aefeaebbd`.
With the corpus downloaded, the following command will perform the remaining steps below:

```bash
python src/main/python/run_regression.py --index --verify --search --regression dl19-passage-cos-dpr-distil-fw \
--corpus-path collections/msmarco-passage-cos-dpr-distil
```

## Indexing

Sample indexing command, applying inverted indexes to dense vectors using the "fake-words" technique:

```bash
target/appassembler/bin/IndexInvertedDenseVectors \
-collection JsonDenseVectorCollection \
-input /path/to/msmarco-passage-cos-dpr-distil \
-index indexes/lucene-index.msmarco-passage-cos-dpr-distil.fw-40/ \
-generator InvertedDenseVectorDocumentGenerator \
-threads 16 -encoding fw -fw.q 40 \
>& logs/log.msmarco-passage-cos-dpr-distil &
```

The path `/path/to/msmarco-passage-cos-dpr-distil/` should point to the corpus downloaded above.

Upon completion, we should have an index with 8,841,823 documents.

## Retrieval

Topics and qrels are stored [here](https://github.com/castorini/anserini-tools/tree/master/topics-and-qrels), which is linked to the Anserini repo as a submodule.
The regression experiments here evaluate on the 43 topics for which NIST has provided judgments as part of the TREC 2019 Deep Learning Track.
The original data can be found [here](https://trec.nist.gov/data/deep2019.html).

After indexing has completed, you should be able to perform retrieval as follows:

```bash
target/appassembler/bin/SearchInvertedDenseVectors \
-index indexes/lucene-index.msmarco-passage-cos-dpr-distil.fw-40/ \
-topics tools/topics-and-qrels/topics.dl19-passage.cos-dpr-distil.jsonl.gz \
-topicreader JsonIntVector \
-output runs/run.msmarco-passage-cos-dpr-distil.cos-dpr-distil-fw-40.topics.dl19-passage.cos-dpr-distil.jsonl.txt \
-topicfield vector -encoding fw -fw.q 40 -hits 1000 &
```

Evaluation can be performed using `trec_eval`:

```bash
tools/eval/trec_eval.9.0.4/trec_eval -m map -c -l 2 tools/topics-and-qrels/qrels.dl19-passage.txt runs/run.msmarco-passage-cos-dpr-distil.cos-dpr-distil-fw-40.topics.dl19-passage.cos-dpr-distil.jsonl.txt
tools/eval/trec_eval.9.0.4/trec_eval -m ndcg_cut.10 -c tools/topics-and-qrels/qrels.dl19-passage.txt runs/run.msmarco-passage-cos-dpr-distil.cos-dpr-distil-fw-40.topics.dl19-passage.cos-dpr-distil.jsonl.txt
tools/eval/trec_eval.9.0.4/trec_eval -m recall.100 -c -l 2 tools/topics-and-qrels/qrels.dl19-passage.txt runs/run.msmarco-passage-cos-dpr-distil.cos-dpr-distil-fw-40.topics.dl19-passage.cos-dpr-distil.jsonl.txt
tools/eval/trec_eval.9.0.4/trec_eval -m recall.1000 -c -l 2 tools/topics-and-qrels/qrels.dl19-passage.txt runs/run.msmarco-passage-cos-dpr-distil.cos-dpr-distil-fw-40.topics.dl19-passage.cos-dpr-distil.jsonl.txt
```

## Effectiveness

With the above commands, you should be able to reproduce the following results:

| **AP@1000** | **cosDPR-distill**|
|:-------------------------------------------------------------------------------------------------------------|-----------|
| [DL19 (Passage)](https://trec.nist.gov/data/deep2020.html) | 0.4271 |
| **nDCG@10** | **cosDPR-distill**|
| [DL19 (Passage)](https://trec.nist.gov/data/deep2020.html) | 0.6857 |
| **R@100** | **cosDPR-distill**|
| [DL19 (Passage)](https://trec.nist.gov/data/deep2020.html) | 0.5766 |
| **R@1000** | **cosDPR-distill**|
| [DL19 (Passage)](https://trec.nist.gov/data/deep2020.html) | 0.7902 |

Note that due to the non-deterministic nature of HNSW indexing, results may differ slightly between each experimental run.
Nevertheless, scores are generally within 0.005 of the reference values recorded in [our YAML configuration file](../../src/main/resources/regression/dl19-passage-cos-dpr-distil-fw.yaml).

Also note that retrieval metrics are computed to depth 1000 hits per query (as opposed to 100 hits per query for document ranking).
Also, for computing nDCG, remember that we keep qrels of _all_ relevance grades, whereas for other metrics (e.g., AP), relevance grade 1 is considered not relevant (i.e., use the `-l 2` option in `trec_eval`).
The experimental results reported here are directly comparable to the results reported in the [track overview paper](https://arxiv.org/abs/2003.07820).

## Reproduction Log[*](reproducibility.md)

To add to this reproduction log, modify [this template](../../src/main/resources/docgen/templates/dl19-passage-cos-dpr-distil-fw.template) and run `bin/build.sh` to rebuild the documentation.
Loading

0 comments on commit 6369184

Please sign in to comment.