ntonellotto commited on
Commit
1cf162a
·
verified ·
1 Parent(s): ecbbe2d

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +64 -10
README.md CHANGED
@@ -3,36 +3,90 @@
3
  tags:
4
  - pyterrier
5
  - pyterrier-artifact
6
- - pyterrier-artifact.dense_index
7
- - pyterrier-artifact.dense_index.flex
8
  task_categories:
9
  - text-retrieval
10
  viewer: false
11
  ---
12
 
13
- # msmarco-passage.tasb.flex
14
 
15
  ## Description
16
 
17
- *TODO: What is the artifact?*
18
 
19
  ## Usage
20
 
 
21
  ```python
22
- # Load the artifact
23
  import pyterrier as pt
24
- artifact = pt.Artifact.from_hf('ntonellotto/msmarco-passage.tasb.flex')
25
- # TODO: Show how you use the artifact
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
  ```
27
 
28
- ## Benchmarks
 
 
 
29
 
30
- *TODO: Provide benchmarks for the artifact.*
31
 
32
  ## Reproduction
33
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  ```python
35
- # TODO: Show how you constructed the artifact.
 
 
 
 
 
36
  ```
37
 
38
  ## Metadata
 
3
  tags:
4
  - pyterrier
5
  - pyterrier-artifact
6
+ - pyterrier-dr
7
+ - pyterrier-flex
8
  task_categories:
9
  - text-retrieval
10
  viewer: false
11
  ---
12
 
13
+ # Flex Index of MSMarco Passage using TASB
14
 
15
  ## Description
16
 
17
+ This artifact represents the retrieval index of the MSMarco Passage collection produced by the TaASB model (more info [here](https://pyterrier.readthedocs.io/en/latest/_modules/pyterrier_dr/hgf_models.html#TasB)).
18
 
19
  ## Usage
20
 
21
+ The following code snippete shows how to use this artifact to perform a dense retrieval experiment:
22
  ```python
23
+
24
  import pyterrier as pt
25
+ import pyterrier_dr
26
+ from pyterrier.measures import *
27
+
28
+ # Load the artifact
29
+ index = pt.Artifact.from_hf('ntonellotto/msmarco-passage.tasb.flex')
30
+ # Load the query encoder (must be the same used to create the artifact)
31
+ model = pyterrier_dr.TasB()
32
+ # Load the dataset
33
+ dataset = pt.get_dataset('msmarco_passage')
34
+ # Run the PyTerrier experiment
35
+ pt.Experiment(
36
+ [model >> index],
37
+ dataset.get_topics('test-2019'),
38
+ dataset.get_qrels('test-2019'),
39
+ eval_metrics=[RR@10, Recall(rel=2)@100, Recall@100, nDCG@10, "mrt"],
40
+ names=["Dense Retrieval"]
41
+ )
42
  ```
43
 
44
+ You should get something like:
45
+ | name | RR@10 | R(rel=2)@100 | R@100 | nDCG@10 | mrt |
46
+ |------------------|----------|---------------|----------|----------|------------|
47
+ | Dense Retrieval | 0.976744 | 0.607269 | 0.514744 | 0.718238 | 280.014161 |
48
 
 
49
 
50
  ## Reproduction
51
 
52
+ ### Generating the data
53
+
54
+ The data has been generated using the following code snippet:
55
+
56
+ ```python
57
+ import torch
58
+ import pyterrier as pt
59
+ import pyterrier_dr
60
+
61
+ # Select the available Torch's backend
62
+ if torch.backends.mps.is_available():
63
+ device = torch.device("mps")
64
+ elif torch.cuda.is_available():
65
+ device = torch.device("cuda")
66
+ else:
67
+ device = torch.device("cpu")
68
+ print(f"Using device: {device}")
69
+ # Create the encoder model
70
+ tct = pyterrier_dr.TasB(device=device, batch_size=256)
71
+ # Create the destination index folder
72
+ index = pyterrier_dr.FlexIndex("./msmarco-passage.tasb.flex")
73
+ # Indexing
74
+ (tct >> index).index(pt.get_dataset("msmarco_passage").get_corpus_iter())
75
+
76
+ print(f"Indexed {len(index)} documents")
77
+ ```
78
+
79
+ ### Uploading the data
80
+
81
+ To upload the index to Hugging Face, use the following code snippet (the dataset sheet will be created automatically):
82
+
83
  ```python
84
+ import pyterrier as pt
85
+
86
+ # Load the artifact from disk
87
+ artifact = pt.Artifact.load("./msmarco-passage.tasb.flex")
88
+ # Upload the artifact to HF
89
+ artifact.to_hf('ntonellotto/msmarco-passage.tasb.flex')
90
  ```
91
 
92
  ## Metadata