Update README.md
Browse files
README.md
CHANGED
|
@@ -14,7 +14,8 @@ viewer: false
|
|
| 14 |
|
| 15 |
## Description
|
| 16 |
|
| 17 |
-
|
|
|
|
| 18 |
|
| 19 |
## Usage
|
| 20 |
|
|
@@ -22,7 +23,27 @@ viewer: false
|
|
| 22 |
# Load the artifact
|
| 23 |
import pyterrier as pt
|
| 24 |
artifact = pt.Artifact.from_hf('astappiev/ragwiki-corpusgraph')
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
```
|
| 27 |
|
| 28 |
## Benchmarks
|
|
@@ -31,13 +52,33 @@ artifact = pt.Artifact.from_hf('astappiev/ragwiki-corpusgraph')
|
|
| 31 |
|
| 32 |
## Reproduction
|
| 33 |
|
|
|
|
|
|
|
| 34 |
```python
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
```
|
| 37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
## Metadata
|
| 39 |
|
| 40 |
-
```
|
| 41 |
{
|
| 42 |
"type": "corpus_graph",
|
| 43 |
"format": "np_topk",
|
|
@@ -45,4 +86,4 @@ artifact = pt.Artifact.from_hf('astappiev/ragwiki-corpusgraph')
|
|
| 45 |
"doc_count": 21015324,
|
| 46 |
"k": 16
|
| 47 |
}
|
| 48 |
-
```
|
|
|
|
| 14 |
|
| 15 |
## Description
|
| 16 |
|
| 17 |
+
A corpus graph for Wikipedia corpus (`rag:nq_wiki`), built using `ragwiki-terrier` sparse index.
|
| 18 |
+
The graph encodes semantic relationships between documents by connecting each document to its `k=16` nearest neighbors based on `bm25` retriever.
|
| 19 |
|
| 20 |
## Usage
|
| 21 |
|
|
|
|
| 23 |
# Load the artifact
|
| 24 |
import pyterrier as pt
|
| 25 |
artifact = pt.Artifact.from_hf('astappiev/ragwiki-corpusgraph')
|
| 26 |
+
```
|
| 27 |
+
|
| 28 |
+
### Usage with GAR
|
| 29 |
+
|
| 30 |
+
```python
|
| 31 |
+
import pyterrier as pt
|
| 32 |
+
from pyterrier_adaptive import GAR, NpTopKCorpusGraph
|
| 33 |
+
from pyterrier_t5 import MonoT5ReRanker
|
| 34 |
+
|
| 35 |
+
sparse_index: pt.terrier.TerrierIndex = pt.Artifact.from_hf("pyterrier/ragwiki-terrier")
|
| 36 |
+
retriever = pt.rewrite.tokenise() >> sparse_index.bm25(include_fields=["docno", "text", "title"]) >> pt.rewrite.reset()
|
| 37 |
+
|
| 38 |
+
get_text = sparse_index.text_loader(["docno", "text", "title"])
|
| 39 |
+
prepare_text = pt.apply.generic(lambda df: df.assign(qid=df["qid"].map(str), docno=df["docno"].map(str))) >> get_text
|
| 40 |
+
scorer = prepare_text >> MonoT5ReRanker(verbose=False, batch_size=64)
|
| 41 |
+
|
| 42 |
+
graph: NpTopKCorpusGraph = pt.Artifact.from_hf("astappiev/ragwiki-corpusgraph").to_limit_k(8)
|
| 43 |
+
|
| 44 |
+
pipeline = retriever >> GAR(scorer, graph) >> get_text
|
| 45 |
+
pipeline.search("hello world")
|
| 46 |
+
|
| 47 |
```
|
| 48 |
|
| 49 |
## Benchmarks
|
|
|
|
| 52 |
|
| 53 |
## Reproduction
|
| 54 |
|
| 55 |
+
This graph was constructed using [PyTerrier Adaptive](https://github.com/terrierteam/pyterrier_adaptive).
|
| 56 |
+
|
| 57 |
```python
|
| 58 |
+
import pyterrier as pt
|
| 59 |
+
from pyterrier_adaptive import NpTopKCorpusGraph
|
| 60 |
+
|
| 61 |
+
dataset: pt.datasets.Dataset = pt.get_dataset("rag:nq_wiki")
|
| 62 |
+
sparse_index: pt.terrier.TerrierIndex = pt.Artifact.from_hf("pyterrier/ragwiki-terrier")
|
| 63 |
+
bm25 = pt.rewrite.tokenise() >> sparse_index.bm25(include_fields=["docno", "text", "title"], threads=slurm_cpus) >> pt.rewrite.reset()
|
| 64 |
+
|
| 65 |
+
graph = NpTopKCorpusGraph.from_retriever(
|
| 66 |
+
bm25 % (build_graph_k + 1),
|
| 67 |
+
dataset.get_corpus_iter(),
|
| 68 |
+
"../index/ragwiki-corpusgraph",
|
| 69 |
+
k=build_graph_k,
|
| 70 |
+
batch_size=65_536,
|
| 71 |
+
)
|
| 72 |
+
graph.to_hf('astappiev/ragwiki-corpusgraph')
|
| 73 |
```
|
| 74 |
|
| 75 |
+
However the code above will take 2 months to run on a single machine. The graph was built using modified version of `from_retriever` to enable parallel compute on the cluster.
|
| 76 |
+
|
| 77 |
+
It took around 14340 CPU-hours to build the graph on our cluster.
|
| 78 |
+
|
| 79 |
## Metadata
|
| 80 |
|
| 81 |
+
```json
|
| 82 |
{
|
| 83 |
"type": "corpus_graph",
|
| 84 |
"format": "np_topk",
|
|
|
|
| 86 |
"doc_count": 21015324,
|
| 87 |
"k": 16
|
| 88 |
}
|
| 89 |
+
```
|