PyTerrier Integration¶
API of ir_axioms.integrations.pyterrier
See the integrations guide and the walkthroughs for usage examples.
ir_axioms.integrations.pyterrier.transformers ¶
KwikSortReranker
dataclass
¶
KwikSortReranker(
*,
axiom: Axiom[Query, Document],
pivot_selection: PivotSelection = RandomPivotSelection(),
text_field: str | None = "text",
verbose: bool = False,
)
Bases: Transformer
pivot_selection
class-attribute
instance-attribute
¶
transform ¶
Source code in ir_axioms/integrations/pyterrier/transformers.py
AggregatedAxiomaticPreferences
dataclass
¶
AggregatedAxiomaticPreferences(
axioms: Sequence[Axiom[Query, Document]],
aggregations: Sequence[
Callable[[Sequence[float]], float]
] = (lambda: [max, min, mean])(),
text_field: str | None = "text",
verbose: bool = False,
)
Bases: Transformer
aggregations
class-attribute
instance-attribute
¶
aggregations: Sequence[
Callable[[Sequence[float]], float]
] = field(default_factory=lambda: [max, min, mean])
transform ¶
Source code in ir_axioms/integrations/pyterrier/transformers.py
AxiomaticPreferences
dataclass
¶
AxiomaticPreferences(
axioms: Sequence[Axiom],
axiom_names: Sequence[str] | None = None,
text_field: str | None = "text",
verbose: bool = False,
)
Bases: Transformer
transform ¶
Source code in ir_axioms/integrations/pyterrier/transformers.py
ir_axioms.integrations.pyterrier.estimator ¶
EstimatorKwikSortReranker
dataclass
¶
EstimatorKwikSortReranker(
*,
axioms: Sequence[Axiom[Query, Document]],
target: Axiom[Query, Document] = ORACLE(),
estimator: ScikitLearnEstimator,
pivot_selection: PivotSelection = RandomPivotSelection(),
text_field: str | None = "text",
verbose: bool = False,
)
Bases: Estimator
A KwikSort re-ranker that uses a scikit-learn estimator to estimate the target preferences (e.g., ORACLE preferences) from the preferences of multiple axioms.
This class extends from PyTerrier's Estimator so that it can be fitted/trained like any other PyTerrier estimator.
target
class-attribute
instance-attribute
¶
pivot_selection
class-attribute
instance-attribute
¶
fit ¶
fit(
topics_or_res_tr: DataFrame,
qrels_tr: DataFrame,
topics_or_res_va: DataFrame | None = None,
qrels_va: DataFrame | None = None,
) -> Transformer
Train the model with the given rankings and qrels.
Source code in ir_axioms/integrations/pyterrier/estimator.py
transform ¶
Source code in ir_axioms/integrations/pyterrier/estimator.py
ir_axioms.integrations.pyterrier.experiment ¶
AxiomaticExperiment
dataclass
¶
AxiomaticExperiment(
*,
retrieval_systems: Sequence[Transformer],
names: Sequence[str] | None = None,
topics: DataFrame,
qrels: DataFrame,
axioms: Sequence[Axiom],
axiom_names: Sequence[str] | None = None,
depth: int | None = 10,
filter_by_qrels: bool = True,
filter_by_topics: bool = False,
text_field: str | None = "text",
parallel_jobs: int = 1,
parallel_backend: Literal["joblib", "ray"] = "joblib",
verbose: bool = False,
)
parallel_backend
class-attribute
instance-attribute
¶
preferences
cached
property
¶
Return a dataframe with each axiom's preference for each document pair, query and retrieval system.
The returned dataframe has the following columns:
- name: Retrieval system name (if found in source)
- qid: Query ID
- query: Query text
- docno_a: Document A ID
- score_a: Document A score
- rank_a: Document A rank
- label_a: Document A relevance label (if qrels were given)
- docno_b: Document B ID
- score_b: Document B score
- rank_b: Document B rank
- rank_b: Document B relevance label (if qrels were given)
- ORIG_preference: Preference from original retrieved ranking
- ORACLE_preference: Preference from qrels (NaN if qrels are missing)
-
preference_distribution
cached
property
¶
Return a dataframe with each axiom's preference distribution across all documents, queries and retrieval systems.
The returned dataframe has the following columns: - axiom: Axiom name - axiom == 0: Absolute number of preferences equal to 0. - axiom == ORIG: Absolute number of preferences equal to the original ranking preference. - axiom != ORIG: Absolute number of preferences opposing the original ranking preference.
preference_consistency
cached
property
¶
Return a dataframe with each axiom's consistency with the original ranking preferences and oracle preferences across all documents, queries and retrieval systems.
The returned dataframe has the following columns:
- axiom: Axiom name
- ORIG_consistency: Relative consistency of non-zero preferences
with ORIG preferences.
- ORACLE_consistency: Relative consistency of non-zero preferences
with ORACLE preferences.
-
ir_axioms.integrations.pyterrier.utils ¶
FilterTopicsTransformer
dataclass
¶
Bases: Transformer
Retain only queries that are contained in the topics.
FilterQrelsTransformer
dataclass
¶
Bases: Transformer
Retain only query-document pairs that are contained in the qrels.
JoinQrelsTransformer
dataclass
¶
AddNameTransformer
dataclass
¶
Bases: Transformer
Add a colum containing the system's name.
inject_pyterrier ¶
inject_pyterrier(
index_location: TerrierIndex
| Path
| str
| Any
| None = None,
text_field: str | None = "text",
tokeniser: TerrierTokeniser | Any | None = None,
dataset: Dataset | str | None = None,
injector: Injector = _default_injector,
) -> None
Source code in ir_axioms/integrations/pyterrier/utils.py
require_columns ¶
Source code in ir_axioms/integrations/pyterrier/utils.py
query_columns ¶
Return the columns that are used to identify a query in the ranking.
Note: This function patches the query_columns function from PyTerrier to also include the query_toks column.
Remove this patch, once https://github.com/terrier-org/pyterrier/issues/566 is resolved.
Source code in ir_axioms/integrations/pyterrier/utils.py
ensure_query_columns_hashable ¶
load_document ¶
load_document(
row: Series | Mapping[Hashable, Any],
text_column: str | None = "text",
) -> Document