Axioms¶
API of ir_axioms.axiom
For descriptions, original formulations, and references of the axioms, see the axiom catalog. For how to use and combine axioms, see the core concepts.
Base Class¶
ir_axioms.axiom.base.Axiom ¶
Bases: ABC, Generic[Input, Output]
An axiom describes a pairwise constraint between two outputs given the same input, as expressed as a preference.
Subclasses must implement the preference() method that determines the pairwise preference between two outputs, and can optionally also override preference_matrix() to batch-compute a full preference matrix of arbitrarily many outputs more efficiently.
This base class also exposes various operators (i.e., +, -, *, /, %, &, ~) for combining and manipulating axioms, as well as rerank() for KwikSort re-ranking the outputs, and other methods for evaluating rankings of outputs in comparison to the axiom's preferences.
preference
abstractmethod
¶
Compute the pairwise preference between two outputs for the same input.
The function should return a positive value if output1 is to be prefered, a negative value if output2 is to be prefered, and zero if there is no preference or if some precondition was not met.
Note that the preference should be independent of the order of output1 and output2, i.e., if the inputs are flipped, the output should be flipped as well.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input
|
Input
|
Common input for both outputs. |
required |
output1
|
Output
|
One output for the common input. |
required |
output2
|
Output
|
Another output for the common input. |
required |
Returns:
| Type | Description |
|---|---|
Preference
|
|
Source code in ir_axioms/axiom/base.py
preferences ¶
Batch-compute the preferences for a sequence of potential outputs.
While the naive default implementation just delegates to preference(), it might make sense to override it to avoid computating certain costly features again and again for the same output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input
|
Input
|
Common input for all outputs. |
required |
outputs
|
Sequence[Output]
|
The outputs for the common input. |
required |
Returns:
| Type | Description |
|---|---|
PreferenceMatrix
|
A preference matrix, where the ij-th entry corresponds to the preference between the i-th and j-th output. |
Source code in ir_axioms/axiom/base.py
batch_preferences ¶
Batch-compute the preference matrices for multiple inputs, each with its own sequence of outputs.
While the naive default implementation just delegates to preferences() for each input-outputs pair, it might make sense to override it to batch costly computations (e.g., model inference) across inputs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
Sequence[tuple[Input, Sequence[Output]]]
|
Pairs of an input and the outputs for that input. |
required |
Returns:
| Type | Description |
|---|---|
PreferenceMatrices
|
A stacked array of preference matrices, where the kij-th entry corresponds to the preference between the i-th and j-th output of the k-th input. |
Source code in ir_axioms/axiom/base.py
majority_vote ¶
normalized ¶
Return the normalized preference of this axiom, replacing positive values with 1 and negative values with -1.
cached ¶
Cache this axiom's preferences in the given cache path,
meaning the preference() method will only be called once
for each query-documents tuple.
Source code in ir_axioms/axiom/base.py
parallel ¶
Parallelize preference matrix computation of this axiom.
Source code in ir_axioms/axiom/base.py
as_precondition ¶
as_precondition(
expected_sign: Literal[1, 0, -1] = 0,
strip_preconditions: bool = True,
) -> Precondition[Input, Output]
Source code in ir_axioms/axiom/base.py
rerank_kwiksort ¶
rerank_kwiksort(
input: Input,
ranking: Sequence[Output],
pivot_selection: PivotSelection[
Input, Output
] = RandomPivotSelection(),
) -> Sequence[Output]
Source code in ir_axioms/axiom/base.py
Combinators¶
See combining axioms and the arithmetic axioms.
ir_axioms.axiom.arithmetic ¶
ProductAxiom
dataclass
¶
Multiply the preferences of the given axioms.
Notes:
- The product of axiom preferences does not necessarily preserve asymmetry, e.g., for axiom * -axiom, the ij-th and ji-th entries are the same.
- The product of axiom preferences does not necessarily preserve transitivity, e.g., for axiom * axiom, any negative preference value's sign is flipped, indicating a > b and b < a at the same time.
MultiplicativeInverseAxiom
dataclass
¶
Invert the preferences of the given axiom (i.e., 1 / preference).
Notes: - The multiplicative inverse of axiom preferences does not preserve irreflexivity, e.g., for any previously irreflexive axiom, the multiplicative inverse is undefined along the diagonal (division by zero).
preference ¶
ConjunctionAxiom
dataclass
¶
preference ¶
Source code in ir_axioms/axiom/arithmetic.py
preferences ¶
Source code in ir_axioms/axiom/arithmetic.py
VoteAxiom
dataclass
¶
minimum_votes
class-attribute
instance-attribute
¶
Minimum portion of votes in favor or against either document, to be considered a majority, for example, 0.5 for absolute majority, 0.6 for qualified majority, 0 for relative majority, or 1 for consensus.
preference ¶
Source code in ir_axioms/axiom/arithmetic.py
preferences ¶
Source code in ir_axioms/axiom/arithmetic.py
MajorityVoteAxiom
dataclass
¶
CascadeAxiom
dataclass
¶
preference ¶
Source code in ir_axioms/axiom/arithmetic.py
preferences ¶
Source code in ir_axioms/axiom/arithmetic.py
Preconditions¶
ir_axioms.axiom.precondition.PreconditionMixin
dataclass
¶
Bases: Axiom[Input, Output], ABC
preference ¶
Source code in ir_axioms/axiom/precondition.py
preferences ¶
Source code in ir_axioms/axiom/precondition.py
ir_axioms.precondition ¶
AxiomPrecondition
dataclass
¶
AxiomPrecondition(
*,
axiom: Axiom[Input, Output],
expected_sign: Literal[1, 0, -1] = 0,
strip_preconditions: bool = True,
)
Precondition ¶
Bases: Generic[Input, Output], Protocol
A precondition can be used to restrict an axiom's preference computation to only those outputs that meet a certain condition (e.g., similar length).
precondition ¶
Check if the precondition holds for a pair of outputs given an input.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input
|
Input
|
Common input for both outputs. |
required |
output1
|
Output
|
One output for the common input. |
required |
output2
|
Output
|
Another output for the common input. |
required |
Returns:
| Type | Description |
|---|---|
Mask
|
|
Source code in ir_axioms/precondition/base.py
preconditions ¶
Check if the precondition holds for all pairs of outputs given an input.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input
|
Input
|
Common input for all outputs. |
required |
outputs
|
Sequence[Output]
|
The outputs for the common input. |
required |
Returns:
| Type | Description |
|---|---|
MaskMatrix
|
A mask matrix, where the ij-th entry corresponds to whether the precondition holds for the i-th and j-th output. |
Source code in ir_axioms/precondition/base.py
LenPrecondition
dataclass
¶
LenPrecondition(
*,
text_contents: TextContents[Document],
term_tokenizer: TermTokenizer,
margin_fraction: NoInject[float] = 0.1,
)
Bases: Precondition[Input, Document]
precondition ¶
Source code in ir_axioms/precondition/length.py
preconditions ¶
Source code in ir_axioms/precondition/length.py
NopPrecondition
dataclass
¶
Bases: Precondition[Input, Document]
precondition ¶
Caching and Parallelization¶
ir_axioms.axiom.cache ¶
SupportsRepr ¶
Bases: Protocol
DbmCachedAxiom
dataclass
¶
Bases: Axiom[_Input, _Output]
preference ¶
preferences ¶
Source code in ir_axioms/axiom/cache.py
ir_axioms.axiom.parallel ¶
ParallelAxiom
dataclass
¶
Bases: Axiom[Input, Output], Generic[Input, Output]
preference ¶
preferences ¶
Source code in ir_axioms/axiom/parallel.py
Learned Axioms¶
ir_axioms.axiom.estimator ¶
EstimatorAxiom ¶
ScikitLearnEstimator ¶
ScikitLearnEstimatorAxiom
dataclass
¶
ScikitLearnEstimatorAxiom(
axioms: Sequence[Axiom[Input, Output]],
estimator: ScikitLearnEstimator,
)
Bases: EstimatorAxiom[Input, Output], ABC
fit ¶
fit(
target: Axiom[Input, Output],
inputs_outputs: Iterable[
tuple[Input, Sequence[Output]]
],
) -> None
Source code in ir_axioms/axiom/estimator.py
preference ¶
Source code in ir_axioms/axiom/estimator.py
preferences ¶
Source code in ir_axioms/axiom/estimator.py
Simple Axioms¶
See the utility axioms.
ir_axioms.axiom.simple ¶
GreaterThanAxiom
dataclass
¶
LessThanAxiom
dataclass
¶
Retrieval Axioms¶
See the retrieval axioms in the catalog.
ir_axioms.axiom.retrieval.term_frequency ¶
Tfc1Axiom
dataclass
¶
Tfc1Axiom(
*,
precondition: NoInject[
Precondition[Query, Document]
] = LEN(),
text_contents: TextContents[Query | Document],
term_tokenizer: TermTokenizer,
text_statistics: TextStatistics[Document],
margin_fraction: NoInject[float] = 0.1,
)
Bases: PreconditionMixin[Query, Document], Axiom[Query, Document]
precondition
class-attribute
instance-attribute
¶
preference ¶
Source code in ir_axioms/axiom/retrieval/term_frequency.py
preferences ¶
Source code in ir_axioms/axiom/retrieval/term_frequency.py
Tfc3Axiom
dataclass
¶
Tfc3Axiom(
*,
precondition: NoInject[
Precondition[Query, Document]
] = LEN(),
text_contents: TextContents[Query | Document],
term_tokenizer: TermTokenizer,
index_statistics: IndexStatistics,
text_statistics: TextStatistics[Document],
margin_fraction: NoInject[float] = 0.1,
)
Bases: PreconditionMixin[Query, Document], Axiom[Query, Document]
precondition
class-attribute
instance-attribute
¶
preference ¶
Source code in ir_axioms/axiom/retrieval/term_frequency.py
preferences ¶
Source code in ir_axioms/axiom/retrieval/term_frequency.py
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 | |
ModifiedTdcAxiom
dataclass
¶
ModifiedTdcAxiom(
*,
text_contents: TextContents[Query | Document],
term_tokenizer: TermTokenizer,
index_statistics: IndexStatistics,
text_statistics: TextStatistics[Query | Document],
)
Modified TDC as in:
Shi, S., Wen, J.R., Yu, Q., Song, R., Ma, W.Y.: Gravitation-based model for information retrieval. In: SIGIR โ05.
preference ¶
Source code in ir_axioms/axiom/retrieval/term_frequency.py
preferences ¶
Source code in ir_axioms/axiom/retrieval/term_frequency.py
LenModifiedTdcAxiom
dataclass
¶
LenModifiedTdcAxiom(
*,
text_contents: TextContents[Query | Document],
term_tokenizer: TermTokenizer,
index_statistics: IndexStatistics,
text_statistics: TextStatistics[Query | Document],
precondition: NoInject[
Precondition[Query, Document]
] = LEN(),
)
Bases: PreconditionMixin[Query, Document], ModifiedTdcAxiom
precondition
class-attribute
instance-attribute
¶
ir_axioms.axiom.retrieval.length_norm ¶
Lnc1Axiom
dataclass
¶
Lnc1Axiom(
*,
text_contents: TextContents[Query | Document],
term_tokenizer: TermTokenizer,
text_statistics: TextStatistics[Document],
margin_fraction: NoInject[float] = 0.1,
)
preference ¶
Source code in ir_axioms/axiom/retrieval/length_norm.py
preferences ¶
Source code in ir_axioms/axiom/retrieval/length_norm.py
TfLncAxiom
dataclass
¶
TfLncAxiom(
*,
text_contents: TextContents[Query | Document],
term_tokenizer: TermTokenizer,
text_statistics: TextStatistics[Document],
)
preference ¶
Source code in ir_axioms/axiom/retrieval/length_norm.py
preferences ¶
Source code in ir_axioms/axiom/retrieval/length_norm.py
ir_axioms.axiom.retrieval.lower_bound ¶
Lb1Axiom
dataclass
¶
Lb1Axiom(
*,
text_contents: TextContents[Query | Document],
term_tokenizer: TermTokenizer,
text_statistics: TextStatistics[Document],
margin_fraction: NoInject[float] = 0.1,
)
preference ¶
Source code in ir_axioms/axiom/retrieval/lower_bound.py
preferences ¶
Source code in ir_axioms/axiom/retrieval/lower_bound.py
ir_axioms.axiom.retrieval.query_aspects ¶
RegAxiom
dataclass
¶
RegAxiom(
*,
precondition: NoInject[
Precondition[Query, Document]
] = LEN(),
text_contents: TextContents[Query | Document],
term_tokenizer: TermTokenizer,
text_statistics: TextStatistics[Document],
term_similarity: TermSimilarity,
)
Bases: PreconditionMixin[Query, Document], Axiom[Query, Document]
Reference: Zheng, W., Fang, H.: Query aspect based term weighting regularization in information retrieval. In: Gurrin, C., et al. (eds.) ECIR 2010.
precondition
class-attribute
instance-attribute
¶
preference ¶
Source code in ir_axioms/axiom/retrieval/query_aspects.py
preferences ¶
Source code in ir_axioms/axiom/retrieval/query_aspects.py
AntiRegAxiom
dataclass
¶
AntiRegAxiom(
*,
precondition: NoInject[
Precondition[Query, Document]
] = LEN(),
text_contents: TextContents[Query | Document],
term_tokenizer: TermTokenizer,
text_statistics: TextStatistics[Document],
term_similarity: TermSimilarity,
)
Bases: PreconditionMixin[Query, Document], Axiom[Query, Document]
Reference: Zheng, W., Fang, H.: Query aspect based term weighting regularization in information retrieval. In: Gurrin, C., et al. (eds.) ECIR 2010.
Modified to use maximum similarity instead of minimum similarity.
precondition
class-attribute
instance-attribute
¶
preference ¶
Source code in ir_axioms/axiom/retrieval/query_aspects.py
preferences ¶
Source code in ir_axioms/axiom/retrieval/query_aspects.py
AspectRegAxiom
dataclass
¶
AspectRegAxiom(
*,
text_contents: TextContents[Query | Document],
term_tokenizer: TermTokenizer,
index_statistics: IndexStatistics,
term_similarity: TermSimilarity,
term_discriminator_margin_fraction: NoInject[
float
] = 0.1,
)
Similar to REG but follows the query aspect clustering from the paper and then counts the number of aspects covered in each document.
Reference: Zheng, W., Fang, H.: Query aspect based term weighting regularization in information retrieval. In: Gurrin, C., et al. (eds.) ECIR 2010.
term_discriminator_margin_fraction
class-attribute
instance-attribute
¶
preference ¶
Source code in ir_axioms/axiom/retrieval/query_aspects.py
preferences ¶
Source code in ir_axioms/axiom/retrieval/query_aspects.py
AndAxiom
dataclass
¶
preference ¶
Source code in ir_axioms/axiom/retrieval/query_aspects.py
preferences ¶
Source code in ir_axioms/axiom/retrieval/query_aspects.py
LenAndAxiom
dataclass
¶
LenAndAxiom(
*,
text_contents: TextContents[Query | Document],
term_tokenizer: TermTokenizer,
precondition: NoInject[
Precondition[Query, Document]
] = LEN(),
)
Bases: PreconditionMixin[Query, Document], AndAxiom
precondition
class-attribute
instance-attribute
¶
ModifiedAndAxiom
dataclass
¶
ModifiedAndAxiom(
*,
text_contents: TextContents[Query | Document],
term_tokenizer: TermTokenizer,
)
Modified AND: One document contains a larger subset of query terms.
preference ¶
Source code in ir_axioms/axiom/retrieval/query_aspects.py
preferences ¶
Source code in ir_axioms/axiom/retrieval/query_aspects.py
LenModifiedAndAxiom
dataclass
¶
LenModifiedAndAxiom(
*,
text_contents: TextContents[Query | Document],
term_tokenizer: TermTokenizer,
precondition: NoInject[
Precondition[Query, Document]
] = LEN(),
)
Bases: PreconditionMixin[Query, Document], ModifiedAndAxiom
precondition
class-attribute
instance-attribute
¶
DivAxiom
dataclass
¶
preference ¶
Source code in ir_axioms/axiom/retrieval/query_aspects.py
preferences ¶
Source code in ir_axioms/axiom/retrieval/query_aspects.py
ir_axioms.axiom.retrieval.term_similarity ¶
Stmc1Axiom
dataclass
¶
Stmc1Axiom(
*,
text_contents: TextContents[Query | Document],
term_tokenizer: TermTokenizer,
term_similarity: TermSimilarity,
)
preference ¶
Source code in ir_axioms/axiom/retrieval/term_similarity.py
preferences ¶
Source code in ir_axioms/axiom/retrieval/term_similarity.py
Stmc2Axiom
dataclass
¶
Stmc2Axiom(
*,
text_contents: TextContents[Query | Document],
term_tokenizer: TermTokenizer,
term_similarity: TermSimilarity,
text_statistics: TextStatistics[Document],
margin_fraction: NoInject[float] = 0.2,
)
preference ¶
Given the most similar pair of a query term and non-query term, prefer the first document if the second document's non-query term frequency compared to the first document's query term frequency is similar to the second document's length compared to the first document's length.
Source code in ir_axioms/axiom/retrieval/term_similarity.py
preferences ¶
Source code in ir_axioms/axiom/retrieval/term_similarity.py
ir_axioms.axiom.retrieval.proximity ¶
Prox1Axiom
dataclass
¶
preference ¶
Source code in ir_axioms/axiom/retrieval/proximity.py
preferences ¶
Source code in ir_axioms/axiom/retrieval/proximity.py
Prox2Axiom
dataclass
¶
preference ¶
Source code in ir_axioms/axiom/retrieval/proximity.py
preferences ¶
Source code in ir_axioms/axiom/retrieval/proximity.py
Prox3Axiom
dataclass
¶
preference ¶
Source code in ir_axioms/axiom/retrieval/proximity.py
preferences ¶
Source code in ir_axioms/axiom/retrieval/proximity.py
Prox4Axiom
dataclass
¶
preference ¶
Source code in ir_axioms/axiom/retrieval/proximity.py
preferences ¶
Source code in ir_axioms/axiom/retrieval/proximity.py
Prox5Axiom
dataclass
¶
preference ¶
Source code in ir_axioms/axiom/retrieval/proximity.py
preferences ¶
Source code in ir_axioms/axiom/retrieval/proximity.py
ir_axioms.axiom.retrieval.argumentative ¶
ArgumentativeUnitsCountAxiom
dataclass
¶
ArgumentativeUnitsCountAxiom(
*,
models: NoInject[Iterable[str]] = DEFAULT_TARGER_MODELS,
api_url: NoInject[str] = DEFAULT_TARGER_API_URL,
cache_dir: NoInject[Path | None] = None,
precondition: NoInject[
Precondition[Any, Document]
] = LEN(),
text_contents: TextContents[Document],
)
Bases: PreconditionMixin[Any, Document], _TargerMixin, Axiom[Any, Document]
Favor documents with more argumentative units.
precondition
class-attribute
instance-attribute
¶
preference ¶
Source code in ir_axioms/axiom/retrieval/argumentative.py
QueryTermOccurrenceInArgumentativeUnitsAxiom
dataclass
¶
QueryTermOccurrenceInArgumentativeUnitsAxiom(
*,
models: NoInject[Iterable[str]] = DEFAULT_TARGER_MODELS,
api_url: NoInject[str] = DEFAULT_TARGER_API_URL,
cache_dir: NoInject[Path | None] = None,
precondition: NoInject[
Precondition[Any, Document]
] = LEN(),
text_contents: TextContents[Query | Document],
term_tokenizer: TermTokenizer,
)
Bases: PreconditionMixin[Query, Document], _TargerMixin, Axiom[Query, Document]
Favor documents with more query terms in argumentative units.
precondition
class-attribute
instance-attribute
¶
preference ¶
Source code in ir_axioms/axiom/retrieval/argumentative.py
QueryTermPositionInArgumentativeUnitsAxiom
dataclass
¶
QueryTermPositionInArgumentativeUnitsAxiom(
*,
models: NoInject[Iterable[str]] = DEFAULT_TARGER_MODELS,
api_url: NoInject[str] = DEFAULT_TARGER_API_URL,
cache_dir: NoInject[Path | None] = None,
precondition: NoInject[
Precondition[Any, Document]
] = LEN(),
text_contents: TextContents[Query | Document],
term_tokenizer: TermTokenizer,
penalty: NoInject[int | None] = 100000,
)
Bases: PreconditionMixin[Query, Document], _TargerMixin, Axiom[Query, Document]
Favor documents where the first occurrence of a query term in an argumentative unit is closer to the beginning of the document.
This axiom is based on the general observation that query terms occur โearlierโ in relevant documents.
References: Troy, A.D., Zhang, G.: Enhancing Relevance Scoring with Chronological Term Rank. In: Proceedings of SIGIR 2007. pp. 599โ606. ACM. Mitra, B., Diaz, F., Craswell, N.: Learning to Match Using Local and Distributed Representations of Text for Web Search. In: Proceedings of WWW 2017. pp. 1291โ1299. ACM.
penalty
class-attribute
instance-attribute
¶
Penalty for the average query term position, if a query term is not found in any argumentative unit for a document. Set to None to use the maximum length of the two compared documents.
precondition
class-attribute
instance-attribute
¶
preference ¶
Source code in ir_axioms/axiom/retrieval/argumentative.py
AverageSentenceLengthAxiom
dataclass
¶
AverageSentenceLengthAxiom(
*,
precondition: NoInject[
Precondition[Any, Document]
] = LEN(),
text_contents: TextContents[Document],
term_tokenizer: TermTokenizer,
sentence_tokenizer: SentenceTokenizer,
min_sentence_length: NoInject[int] = 12,
max_sentence_length: NoInject[int] = 20,
)
Bases: PreconditionMixin[Any, Document], Axiom[Any, Document]
Favor documents with an average sentence length between a minimum (default: 12) and a maximum (default: 20) number of words.
This axiom is based on the general observation for text readability / good writing style [8, 10].
References: Markel, M.: Technical Communication. 9th ed. Bedford/St Martinโs (2010) Newell, C.: Editing Tip: Sentence Length (2014)
precondition
class-attribute
instance-attribute
¶
preference ¶
Source code in ir_axioms/axiom/retrieval/argumentative.py
preferences ¶
Source code in ir_axioms/axiom/retrieval/argumentative.py
ir_axioms.axiom.retrieval.simple ¶
OriginalAxiom
dataclass
¶
preference ¶
Source code in ir_axioms/axiom/retrieval/simple.py
ir_axioms.axiom.retrieval.trec ¶
TrecOracleAxiom
dataclass
¶
preference ¶
Source code in ir_axioms/axiom/retrieval/trec.py
preferences ¶
Source code in ir_axioms/axiom/retrieval/trec.py
RAG Axioms¶
See the RAG axioms in the catalog.
ir_axioms.axiom.generation.coherence ¶
Coherence axioms for retrieval augmented text.
For a definition of this utility dimension, see: https://doi.org/10.1145/3626772.3657849
- Logical coherence: Is the response well-structured?
- Stylistic coherence: Does the response have a uniform style of speech?
WordLengthDeviationCoherenceAxiom
dataclass
¶
WordLengthDeviationCoherenceAxiom(
*,
text_contents: TextContents[GenerationResponse],
sentence_tokenizer: SentenceTokenizer,
term_tokenizer: TermTokenizer,
margin_fraction: NoInject[float] = 0.0,
)
Bases: Axiom[Any, GenerationResponse]
Prefer text with lower standard deviation of average word lengths across sentences.
preference ¶
Source code in ir_axioms/axiom/generation/coherence.py
preferences ¶
Source code in ir_axioms/axiom/generation/coherence.py
SubjectVerbClosenessCoherenceAxiom
dataclass
¶
SubjectVerbClosenessCoherenceAxiom(
*,
text_contents: TextContents[GenerationResponse],
language_name: NoInject[str] = "en_core_web_sm",
margin_fraction: NoInject[float] = 0.1,
)
Bases: Axiom[Any, GenerationResponse]
Prefer text with subjects and verbs that are closer together.
preference ¶
Source code in ir_axioms/axiom/generation/coherence.py
preferences ¶
Source code in ir_axioms/axiom/generation/coherence.py
ir_axioms.axiom.generation.coverage ¶
Coverage axioms for retrieval-augmented generation.
For a definition of this utility dimension, see: https://doi.org/10.1145/3626772.3657849
- Broad coverage: Does the response cover diverse information?
- Deep coverage: Does the response provide in-depth and highly informative content?
AspectCountCoverageAxiom
dataclass
¶
AspectCountCoverageAxiom(
*,
text_contents: TextContents[GenerationResponse],
aspect_extraction: AspectExtraction,
margin_fraction: NoInject[float] = 0.0,
)
Bases: Axiom[Any, GenerationResponse]
Prefer text with more distinct extracted aspects.
preference ¶
Source code in ir_axioms/axiom/generation/coverage.py
preferences ¶
Source code in ir_axioms/axiom/generation/coverage.py
AspectRedundancyCoverageAxiom
dataclass
¶
AspectRedundancyCoverageAxiom(
*,
text_contents: TextContents[GenerationResponse],
aspect_extraction: AspectExtraction,
sentence_similarity: SentenceSimilarity,
margin_fraction: NoInject[float] = 0.2,
)
Bases: Axiom[Any, GenerationResponse]
Prefer text that has less redundant extracted aspects according to sentence similarity between the aspects.
preference ¶
Source code in ir_axioms/axiom/generation/coverage.py
preferences ¶
Source code in ir_axioms/axiom/generation/coverage.py
AspectSimilaritySentenceCountCoverageAxiom
dataclass
¶
AspectSimilaritySentenceCountCoverageAxiom(
*,
text_contents: TextContents[
GenerationRequest | GenerationResponse
],
aspect_extraction: AspectExtraction,
sentence_tokenizer: SentenceTokenizer,
sentence_similarity: SentenceSimilarity,
margin_fraction: NoInject[float] = 0.5,
)
Bases: Axiom[GenerationRequest, GenerationResponse]
Prefer text with extracted aspects from the input text mentioned in more sentences of the output, weighing by the sentence's similarity to the aspects.
text_contents
instance-attribute
¶
preference ¶
preference(
input: GenerationRequest,
output1: GenerationResponse,
output2: GenerationResponse,
) -> Preference
Source code in ir_axioms/axiom/generation/coverage.py
preferences ¶
Source code in ir_axioms/axiom/generation/coverage.py
ir_axioms.axiom.generation.consistency ¶
Consistency axioms for retrieval-augmented generation.
For a definition of this utility dimension, see: https://doi.org/10.1145/3626772.3657849
- External consistency: Is the statement accurately conveying from the sources?
- Internal consistency: Does the statement not contradict itself?
CONS1
module-attribute
¶
AspectSimilaritySentenceCountConsistencyAxiom
dataclass
¶
AspectSimilaritySentenceCountConsistencyAxiom(
*,
text_contents: TextContents[
GenerationRequest | GenerationResponse
],
aspect_extraction: AspectExtraction,
sentence_tokenizer: SentenceTokenizer,
sentence_similarity: SentenceSimilarity,
margin_fraction: NoInject[float] = 0.5,
)
Bases: Axiom[GenerationRequest, GenerationResponse]
Prefer text with extracted aspects from the input context mentioned in more sentences of the output, weighing by the sentence's similarity to the aspects.
text_contents
instance-attribute
¶
preference ¶
preference(
input: GenerationRequest,
output1: GenerationResponse,
output2: GenerationResponse,
) -> Preference
Source code in ir_axioms/axiom/generation/consistency.py
preferences ¶
Source code in ir_axioms/axiom/generation/consistency.py
RougeConsistencyAxiom
dataclass
¶
RougeConsistencyAxiom(
*,
text_contents: TextContents[
GenerationRequest | GenerationResponse
],
sentence_tokenizer: SentenceTokenizer,
term_tokenizer: TermTokenizer,
margin_fraction: NoInject[float] = 0.1,
)
Bases: Axiom[GenerationRequest, GenerationResponse]
Prefer text with higher ROUGE score compared to the input contexts.
text_contents
instance-attribute
¶
preference ¶
preference(
input: GenerationRequest,
output1: GenerationResponse,
output2: GenerationResponse,
) -> Preference
Source code in ir_axioms/axiom/generation/consistency.py
preferences ¶
Source code in ir_axioms/axiom/generation/consistency.py
EntityContradictionConsistencyAxiom
dataclass
¶
EntityContradictionConsistencyAxiom(
*,
text_contents: TextContents[GenerationResponse],
language_name: NoInject[str] = "en_core_web_sm",
margin_fraction: NoInject[float] = 0.2,
)
Bases: Axiom[Any, GenerationResponse]
Prefer text with entities less frequently mentioned in contradictory phrases.
preference ¶
Source code in ir_axioms/axiom/generation/consistency.py
preferences ¶
Source code in ir_axioms/axiom/generation/consistency.py
ir_axioms.axiom.generation.correctness ¶
Correctness axioms for retrieval-augmented generation.
For a definition of this utility dimension, see: https://doi.org/10.1145/3626772.3657849
- Factuality: Does the statement state things that are verifiable?
- Topical correctness: Does the statement state things within the scope of the user's information need?
CitationSentenceCorrectnessAxiom
dataclass
¶
CitationSentenceCorrectnessAxiom(
*,
text_contents: TextContents[GenerationResponse],
sentence_tokenizer: SentenceTokenizer,
margin_fraction: NoInject[float] = 0.1,
)
Bases: Axiom[Any, GenerationResponse]
Prefer text with more sentences containing citations.
preference ¶
Source code in ir_axioms/axiom/generation/correctness.py
preferences ¶
Source code in ir_axioms/axiom/generation/correctness.py
ir_axioms.axiom.generation.clarity ¶
Clarity axioms for retrieval-augmented generation.
For a definition of this utility dimension, see: https://doi.org/10.1145/3626772.3657849
- Language clarity: Is the response concise, comprehensible, lexically and grammatically correct, and user-accessible?
- Content clarity: Does the response clearly communicate the most salient information and where it stems from?
CLAR1
module-attribute
¶
LanguageToolGrammarErrorProportionClarityAxiom
dataclass
¶
LanguageToolGrammarErrorProportionClarityAxiom(
*,
text_contents: TextContents[GenerationResponse],
language: NoInject[str] = "en-US",
enabled_categories: NoInject[
Iterable[_LanguageToolCategory]
] = frozenset({"GRAMMAR"}),
margin_fraction: NoInject[float] = 0.1,
)
Bases: _LanguageToolErrorProportionClarityAxiom
Prefer text with a lower proportion of characters covered by grammar errors.
enabled_categories
class-attribute
instance-attribute
¶
FleschReadingEaseClarityAxiom
dataclass
¶
FleschReadingEaseClarityAxiom(
*,
text_contents: TextContents[GenerationResponse],
language_name: NoInject[str] = "en_core_web_sm",
margin_fraction: NoInject[float] = 0.0,
)
Bases: Axiom[Any, GenerationResponse]
Prefer text with higher readability as measured by the Flesch reading ease score.
preference ¶
Source code in ir_axioms/axiom/generation/clarity.py
preferences ¶
Source code in ir_axioms/axiom/generation/clarity.py
ir_axioms.axiom.generation.retrieval ¶
GEN_ArgUC
module-attribute
¶
GEN_QTArg
module-attribute
¶
GEN_QTPArg
module-attribute
¶
GenerativeArgumentativeUnitsCountAxiom
dataclass
¶
Bases: _RetrievalAxiomWrapper
GenerativeQueryTermOccurrenceInArgumentativeUnitsAxiom
dataclass
¶
GenerativeQueryTermOccurrenceInArgumentativeUnitsAxiom(
*, axiom: QueryTermOccurrenceInArgumentativeUnitsAxiom
)
Bases: _RetrievalAxiomWrapper
GenerativeQueryTermPositionInArgumentativeUnitsAxiom
dataclass
¶
GenerativeQueryTermPositionInArgumentativeUnitsAxiom(
*, axiom: QueryTermPositionInArgumentativeUnitsAxiom
)
Bases: _RetrievalAxiomWrapper
GenerativeAverageSentenceLengthAxiom
dataclass
¶
Bases: _RetrievalAxiomWrapper
GenerativeLnc1Axiom
dataclass
¶
Bases: _RetrievalAxiomWrapper
GenerativeTfLncAxiom
dataclass
¶
Bases: _RetrievalAxiomWrapper
GenerativeProx1Axiom
dataclass
¶
Bases: _RetrievalAxiomWrapper
GenerativeProx2Axiom
dataclass
¶
Bases: _RetrievalAxiomWrapper
GenerativeProx3Axiom
dataclass
¶
Bases: _RetrievalAxiomWrapper
GenerativeProx4Axiom
dataclass
¶
Bases: _RetrievalAxiomWrapper
GenerativeProx5Axiom
dataclass
¶
Bases: _RetrievalAxiomWrapper
GenerativeRegAxiom
dataclass
¶
Bases: _RetrievalAxiomWrapper
GenerativeAntiRegAxiom
dataclass
¶
Bases: _RetrievalAxiomWrapper
GenerativeAndAxiom
dataclass
¶
Bases: _RetrievalAxiomWrapper
GenerativeLenAndAxiom
dataclass
¶
Bases: _RetrievalAxiomWrapper
GenerativeModifiedAndAxiom
dataclass
¶
Bases: _RetrievalAxiomWrapper
GenerativeDivAxiom
dataclass
¶
Bases: _RetrievalAxiomWrapper
GenerativeLenDivAxiom
dataclass
¶
Bases: _RetrievalAxiomWrapper
GenerativeTfc1Axiom
dataclass
¶
Bases: _RetrievalAxiomWrapper
GenerativeStmc1Axiom
dataclass
¶
Bases: _RetrievalAxiomWrapper
ir_axioms.axiom.generation.trec ¶
TrecRagNuggetScoreType
module-attribute
¶
TrecRagNuggetAxiom
dataclass
¶
TrecRagNuggetAxiom(
*,
assignments_path: Path = Path(
"data/nugget_assignment.20241108.jsonl"
),
score_type: TrecRagNuggetScoreType = "all",
strict: bool = False,
margin_fraction: float = 0.0,
)
Bases: Axiom[GenerationRequest, GenerationResponse]
assignments_path
class-attribute
instance-attribute
¶
preference ¶
preference(
input: GenerationRequest,
output1: GenerationResponse,
output2: GenerationResponse,
) -> float
Source code in ir_axioms/axiom/generation/trec.py
ir_axioms.axiom.generation.crowd ¶
TrecRagCrowdUtilityType
module-attribute
¶
TrecRagCrowdUtilityType: TypeAlias = Literal[
"overall",
"logical coherence",
"stylistic coherence",
"coherence",
"internal consistency",
"consistency",
"topical correctness",
"correctness",
"broad coverage",
"deep coverage",
"coverage",
]
TrecRagCrowdAxiom
dataclass
¶
TrecRagCrowdAxiom(
*,
ratings_path: Path = Path(
"data/crowd/ratings.jsonl.gz"
),
responses_path: Path = Path(
"data/crowd/responses.jsonl.gz"
),
utility_type: TrecRagCrowdUtilityType,
margin_fraction: float = 0.1,
)
Bases: Axiom[GenerationRequest, GenerationResponse]
ratings_path
class-attribute
instance-attribute
¶
responses_path
class-attribute
instance-attribute
¶
preference ¶
preference(
input: GenerationRequest,
output1: GenerationResponse,
output2: GenerationResponse,
) -> float
Source code in ir_axioms/axiom/generation/crowd.py
ir_axioms.axiom.generation.llm ¶
TrecRagLlmOrigAxiom
dataclass
¶
TrecRagLlmOrigAxiom(
*,
ratings_path: Path = Path(
"data/ratings-HuggingFaceTB-SmolLM-360M-Instruct.jsonl"
),
margin_fraction: NoInject[float] = 0.0,
)
Bases: Axiom[GenerationRequest, GenerationResponse]
ratings_path
class-attribute
instance-attribute
¶
preference ¶
preference(
input: GenerationRequest,
output1: GenerationResponse,
output2: GenerationResponse,
) -> float