Skip to content

Commit 98cb3fd

Browse files
Merge pull request #161 from webis-de/docu
Enhance documentation for dataset classes and model configurations
2 parents 6a41a4a + 142062b commit 98cb3fd

3 files changed

Lines changed: 108 additions & 20 deletions

File tree

docs/guide/datasets.rst

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@
44
Which Dataset Format to Use?
55
===========================
66

7-
Lightning IR provides four dataset classes. The right one depends on your
8-
workflow and the shape of your data.
7+
Lightning IR provides four dataset classes —
8+
:py:class:`~lightning_ir.data.dataset.TupleDataset`,
9+
:py:class:`~lightning_ir.data.dataset.RunDataset`,
10+
:py:class:`~lightning_ir.data.dataset.DocDataset`, and
11+
:py:class:`~lightning_ir.data.dataset.QueryDataset` —
12+
which one to use depends on your workflow and the shape of your data.
913

1014
.. code-block:: text
1115
@@ -49,15 +53,15 @@ Dataset Class Reference
4953
* - :py:class:`~lightning_ir.data.dataset.RunDataset`
5054
- ``fit``, ``re_rank``
5155
- Loads a ranked list of documents per query from a TREC-format run file
52-
or an ir_datasets ID. Key parameters: ``depth`` (max rank to load),
56+
or an `ir_datasets <https://ir-datasets.com/>`_ ID. Key parameters: ``depth`` (max rank to load),
5357
``sample_size`` (docs per query), ``sampling_strategy``
5458
(``top`` or ``random``), ``targets`` (``relevance`` or ``score``).
5559
* - :py:class:`~lightning_ir.data.dataset.DocDataset`
5660
- ``index``
57-
- Iterates over all documents in a collection. Backed by ir_datasets.
61+
- Iterates over all documents in a collection. Backed by `ir_datasets <https://ir-datasets.com/>`_.
5862
* - :py:class:`~lightning_ir.data.dataset.QueryDataset`
5963
- ``search``
60-
- Iterates over queries in a dataset split. Backed by ir_datasets.
64+
- Iterates over queries in a dataset split. Backed by `ir_datasets <https://ir-datasets.com/>`_.
6165

6266
.. tip::
6367

docs/guide/index-types.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ Index Type Comparison
104104
Quick Examples
105105
--------------
106106

107+
Index Configs
108+
^^^^^^^^^^^^^
109+
107110
**FAISS IVF index** (approximate nearest-neighbor for large dense collections):
108111

109112
.. code-block:: yaml
@@ -202,6 +205,9 @@ Quick Examples
202205
)
203206
trainer.index(module, data_module)
204207
208+
Search Configs
209+
^^^^^^^^^^^^^^
210+
205211
**FAISS search** (querying a FAISS IVF index with a dense bi-encoder):
206212

207213
.. code-block:: yaml

docs/guide/models.rst

Lines changed: 93 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,47 @@ Architecture Comparison
7979
- ❌
8080
- ✅
8181
- Sees all candidates at once; highest re-rank quality
82+
* - **MVR**
83+
- :py:class:`~lightning_ir.models.bi_encoders.mvr.MvrConfig`
84+
- Separate
85+
- Multi dense (viewer tokens)
86+
- ✅
87+
- ✅
88+
- Fixed-count multi-vector; balances index size and quality
89+
* - **COIL**
90+
- :py:class:`~lightning_ir.models.bi_encoders.coil.CoilConfig`
91+
- Separate
92+
- Multi (token + CLS)
93+
- ✅
94+
- ✅
95+
- Exact lexical match with context; sparse + dense hybrid
96+
* - **UniCOIL**
97+
- :py:class:`~lightning_ir.models.bi_encoders.coil.UniCoilConfig`
98+
- Separate
99+
- Single sparse (token weights)
100+
- ✅
101+
- ✅
102+
- Lightweight token-weight sparse retrieval; simpler than SPLADE
82103

83104
.. note::
84105

85-
Lightning IR also supports several other bi-encoder variants (:py:class:`~lightning_ir.models.bi_encoders.coil.CoilConfig`,
86-
:py:class:`~lightning_ir.models.bi_encoders.mvr.MvrConfig`) and external models such as XTR for advanced use cases. See
87-
the :ref:`concepts-model` page and the :py:mod:`~lightning_ir.models` API
88-
reference for a full list.
106+
External checkpoints are also supported out of the box. For example, XTR
107+
(``google/xtr-base-en``) uses the ColBERT architecture (:py:class:`~lightning_ir.models.bi_encoders.col.ColConfig`)
108+
with a T5 backbone. See the :ref:`concepts-model` page and the :py:mod:`~lightning_ir.models` API
109+
reference for a full list of registered checkpoints.
89110

90111
Quick Examples
91112
--------------
92113

93114
**DPR bi-encoder** — simplest dense retrieval:
94115

116+
DPR encodes each query and document into a single dense vector using a
117+
pooling step (typically the CLS token). Similarity is computed with a single
118+
dot product or cosine comparison, which makes retrieval fast and straightforward
119+
to index. The optional ``projection`` head lets you reduce the embedding
120+
dimension and add a non-linear bottleneck; set ``embedding_dim`` to control the
121+
output size.
122+
95123
.. code-block:: yaml
96124
97125
# model-dpr.yaml
@@ -101,6 +129,13 @@ Quick Examples
101129
model_name_or_path: bert-base-uncased
102130
config:
103131
class_path: lightning_ir.models.DprConfig
132+
init_args:
133+
similarity_function: dot # or "cosine"
134+
query_length: 32 # max query tokens
135+
doc_length: 512 # max document tokens
136+
pooling_strategy: first # CLS token; also "mean", "max", "sum"
137+
embedding_dim: null # null → use backbone hidden size
138+
projection: linear # linear projection head; null to disable
104139
105140
.. code-block:: python
106141
@@ -109,11 +144,23 @@ Quick Examples
109144
110145
module = BiEncoderModule(
111146
model_name_or_path="bert-base-uncased",
112-
config=DprConfig(),
147+
config=DprConfig(
148+
similarity_function="dot",
149+
query_length=32,
150+
doc_length=512,
151+
pooling_strategy="first",
152+
embedding_dim=None, # None → use backbone hidden size
153+
projection="linear",
154+
),
113155
)
114156
115157
**ColBERT** — multi-vector late interaction:
116158

159+
ColBERT produces one embedding **per token**, so controlling sequence lengths and
160+
the per-token embedding dimension directly affects index size and quality.
161+
It also supports special ColBERT-specific options (query expansion, marker
162+
tokens, per-token ``normalization_strategy``) that DPR and SPLADE do not have.
163+
117164
.. code-block:: yaml
118165
119166
# model-colbert.yaml
@@ -126,13 +173,13 @@ Quick Examples
126173
init_args:
127174
similarity_function: dot
128175
query_aggregation_function: sum
129-
query_expansion: true
176+
query_expansion: true # ColBERT-specific: pad queries to query_length
130177
query_length: 32
131-
doc_length: 256
132-
normalization_strategy: l2
133-
embedding_dim: 128
134-
projection: linear_no_bias
135-
add_marker_tokens: true
178+
doc_length: 256 # kept smaller than DPR to limit index size
179+
normalization_strategy: l2 # ColBERT-specific: per-token l2 normalisation
180+
embedding_dim: 128 # project every token to 128-d (reduces index size)
181+
projection: linear_no_bias # ColBERT convention: no bias in projection
182+
add_marker_tokens: true # ColBERT-specific: [Q]/[D] special tokens
136183
137184
.. code-block:: python
138185
@@ -144,18 +191,26 @@ Quick Examples
144191
config=ColConfig(
145192
similarity_function="dot",
146193
query_aggregation_function="sum",
147-
query_expansion=True,
194+
query_expansion=True, # ColBERT-specific
148195
query_length=32,
149196
doc_length=256,
150-
normalization_strategy="l2",
197+
normalization_strategy="l2", # ColBERT-specific
151198
embedding_dim=128,
152199
projection="linear_no_bias",
153-
add_marker_tokens=True,
200+
add_marker_tokens=True, # ColBERT-specific
154201
),
155202
)
156203
157204
**SPLADE** — learned sparse retrieval:
158205

206+
SPLADE maps each query and document to a sparse vector over the full vocabulary.
207+
Each vocabulary dimension is activated by taking the max-pool of the token
208+
logits, so the representation is directly interpretable as a bag of weighted
209+
terms. Because the embedding space is the tokenizer vocabulary, ``embedding_dim``
210+
cannot be set freely — it is always equal to the vocabulary size. The key
211+
knob is ``pooling_strategy``: ``max`` (the default) gives standard SPLADE
212+
behaviour; ``sum`` gives SPLADE-doc behaviour.
213+
159214
.. code-block:: yaml
160215
161216
# model-splade.yaml
@@ -165,6 +220,17 @@ Quick Examples
165220
model_name_or_path: bert-base-uncased
166221
config:
167222
class_path: lightning_ir.models.SpladeConfig
223+
init_args:
224+
similarity_function: dot # sparse dot product
225+
query_length: 32 # max query tokens
226+
doc_length: 512 # max document tokens
227+
pooling_strategy: max # max over token activations (SPLADE default)
228+
229+
.. note::
230+
231+
SPLADE uses the full vocabulary as its embedding space, so
232+
``embedding_dim`` is tied to the vocabulary size and cannot be configured
233+
via the constructor (it is derived from the backbone tokenizer).
168234

169235
.. code-block:: python
170236
@@ -173,11 +239,23 @@ Quick Examples
173239
174240
module = BiEncoderModule(
175241
model_name_or_path="bert-base-uncased",
176-
config=SpladeConfig(),
242+
config=SpladeConfig(
243+
similarity_function="dot",
244+
query_length=32,
245+
doc_length=512,
246+
pooling_strategy="max", # max over token activations (SPLADE default)
247+
),
177248
)
178249
179250
**Cross-encoder (MonoEncoder)** — highest quality re-ranking:
180251

252+
A cross-encoder concatenates query and document into a single input and runs
253+
them jointly through the backbone, so every layer can attend across both texts.
254+
This yields the highest scoring quality but means no pre-indexing is possible
255+
— documents must be re-encoded for every new query. Use this architecture when
256+
you already have a candidate list (e.g. from a bi-encoder first stage) and
257+
need the best possible re-ranking without latency constraints.
258+
181259
.. code-block:: yaml
182260
183261
# model-cross-encoder.yaml

0 commit comments

Comments
 (0)