Learning to rank
Learning to rank is handled by various classes. Some are located in the learning module.
Listeners
Scorers
Scorers are able to give a score to a (query, document) pair. Among the scorers, some are have learnable parameters.
- XPM Configxpmir.rankers.Scorer[source]
Bases:
Config,Initializable,EasyLogger,ABCSubmit type:
xpmir.rankers.ScorerQuery-document scorer
A model able to give a score to a list of documents given a query
- getRetriever(retriever: Retriever, batch_size: int, batcher: Batcher = Config[xpmir.learning.batchers.batcher], top_k=None, device=None)[source]
Returns a two stage re-ranker from this retriever and a scorer
- Parameters:
device – Device for the ranker or None if no change should be made
batch_size – The number of documents in each batch
top_k – Number of documents to re-rank (or None for all)
- initialize(*args, **kwargs)
Main initialization
Calls
__initialize__()once (using__initialize__())
- XPM Configxpmir.rankers.RandomScorer(*, random)[source]
Bases:
ScorerSubmit type:
xpmir.rankers.RandomScorerA random scorer
- random: xpmir.learning.base.Random
The random number generator
- XPM Configxpmir.rankers.AbstractModuleScorer[source]
-
Submit type:
xpmir.rankers.AbstractModuleScorerBase class for all learnable scorer
This class provides a compute method that calls the forward method,
- XPM Configxpmir.rankers.LearnableScorer[source]
Bases:
AbstractModuleScorerSubmit type:
xpmir.rankers.LearnableScorerLearnable scorer
A scorer with parameters that can be learnt
Adapters
- XPM Configxpmir.rankers.adapters.ScorerTransformAdapter(*, scorer, adapter)[source]
Bases:
ScorerSubmit type:
xpmir.rankers.adapters.ScorerTransformAdapterTransforms topic and/or documents output by a scorer when rescoring documents
- scorer: xpmir.rankers.Scorer
The original scorer to be transform
- adapter: xpmir.letor.samplers.hydrators.SampleTransform
The list of sample transforms to apply
Utility functions
- xpmir.rankers.scorer_retriever(documents: Documents, *, retrievers: RetrieverFactory, scorer: Scorer, **kwargs)[source]
Helper function that returns a two stage retriever. This is useful when used with partial (when the scorer is not known).
- Parameters:
documents – The document collection
retrievers – A retriever factory
scorer – The scorer
- Returns:
A retriever, calling the :meth:scorer.getRetriever
Retrievers
Scores can be used as retrievers through a xpmir.rankers.TwoStageRetriever
Samplers
Samplers provide samples in the form of records. They all inherit from:
- class xpmir.letor.samplers.SerializableIterator[source]
Bases:
Iterator[T],Generic[T,State]An iterator that can be serialized through state dictionaries.
This is used when saving the sampler state
- XPM Configxpmir.letor.samplers.ModelBasedSampler(*, dataset, retriever)[source]
Bases:
SamplerSubmit type:
xpmir.letor.samplers.ModelBasedSamplerBase class for retriever-based sampler
- dataset: datamaestro_text.data.ir.Adhoc
The IR adhoc dataset
- retriever: xpmir.rankers.Retriever
A retriever to sample negative documents
Records for training
- class xpmir.letor.records.PairwiseRecord(query: Record, positive: Record, negative: Record)[source]
Bases:
objectA pairwise record is composed of a query, a positive and a negative document
- class xpmir.letor.records.PointwiseRecord(topic: Record, document: Record, relevance: float | None = None)[source]
Bases:
objectA record from a pointwise sampler
Document samplers
Useful for pre-training or when learning index parameters (e.g. for FAISS).
- XPM Configxpmir.documents.samplers.DocumentSampler(*, documents)[source]
Bases:
Config,ABCSubmit type:
xpmir.documents.samplers.DocumentSamplerHow to sample from a document store
- documents: datamaestro_text.data.ir.DocumentStore
- XPM Configxpmir.documents.samplers.HeadDocumentSampler(*, documents, max_count, max_ratio)[source]
Bases:
DocumentSamplerSubmit type:
xpmir.documents.samplers.HeadDocumentSamplerA basic sampler that iterates over the first documents
if max_count is 0, it iterates over all documents
- documents: datamaestro_text.data.ir.DocumentStore
- max_count: int = 0
Maximum number of documents (if 0, no limit)
- max_ratio: float = 0
Maximum ratio of documents (if 0, no limit)
- XPM Configxpmir.documents.samplers.RandomDocumentSampler(*, documents, max_count, max_ratio, random)[source]
Bases:
DocumentSamplerSubmit type:
xpmir.documents.samplers.RandomDocumentSamplerA basic sampler that iterates over the first documents
Either max_count or max_ratio should be non null
- documents: datamaestro_text.data.ir.DocumentStore
- max_count: int = 0
Maximum number of documents (if 0, no limit)
- max_ratio: float = 0
Maximum ratio of documents (if 0, no limit)
- random: xpmir.learning.base.Random
Random sampler
Adapters
- XPM Configxpmir.letor.samplers.hydrators.SampleTransform[source]
Bases:
Config,ABCSubmit type:
xpmir.letor.samplers.hydrators.SampleTransform
- XPM Configxpmir.letor.samplers.hydrators.SampleHydrator(*, documentstore, querystore)[source]
Bases:
SampleTransformSubmit type:
xpmir.letor.samplers.hydrators.SampleHydratorBase class for document/topic hydrators
- documentstore: datamaestro_text.data.ir.DocumentStore
The store for document texts if needed
- querystore: xpmir.datasets.adapters.TextStore
The store for query texts if needed
- XPM Configxpmir.letor.samplers.hydrators.SamplePrefixAdding(*, query_prefix, document_prefix)[source]
Bases:
SampleTransformSubmit type:
xpmir.letor.samplers.hydrators.SamplePrefixAddingTransform the query and documents by adding the prefix
- query_prefix: str
The prefix for the query
- document_prefix: str
The prefix for the document
- XPM Configxpmir.letor.samplers.hydrators.SampleTransformList(*, adapters)[source]
Bases:
SampleTransformSubmit type:
xpmir.letor.samplers.hydrators.SampleTransformListA class which group a list of sample transforms
- adapters: List[xpmir.letor.samplers.hydrators.SampleTransform]
The list of sample transform to be applied