Comparison ¶
A comparison between two corpora: a reference corpus and a comparison corpus.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reference
|
str
|
Name of the reference corpus |
required |
comparison
|
str
|
Name of the comparison corpus |
required |
Methods:
| Name | Description |
|---|---|
alias |
Returns a new |
normalize |
Returns a new |
Attributes:
| Name | Type | Description |
|---|---|---|
exclude |
ComparisonExcluder
|
Namespace for excluding tokens from the reference and comparison corpora. |
score |
Scorer
|
Namespace for scoring comparisons between the reference and comparison corpora. |
Attributes¶
exclude
cached
property
¶
Namespace for excluding tokens from the reference and comparison corpora.
See the available exclusion strategies.
score
cached
property
¶
Namespace for scoring comparisons between the reference and comparison corpora.
See the available scoring methods.
Methods:¶
alias ¶
Returns a new Comparison with the given alias, an internal name for it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name to give to the comparison |
required |
Returns:
| Type | Description |
|---|---|
Comparison
|
A new |
normalize ¶
Returns a new Comparison whose token contributions are normalized onto a common scale.
Each scoring measure produces a per-token contribution \(\delta_\tau\). Normalization rescales every contribution by a single constant so that scores become interpretable and comparable across measures. There are two normalization strategies:
"sum_abs"divides by the sum of absolute contributions, \(\sum_\tau |\delta_\tau|\). The absolute values of the normalized contributions then sum to 1."abs_sum"divides by the absolute sum of contributions, \(|\sum_\tau \delta_\tau|\). The normalized contributions then sum to \(\pm 1\).
Normalizing again by the same strategy is a no-op; normalizing by a different strategy raises an error, since the contributions are already on a normalized scale.
Example
Warning
Using this method forces the comparison to be evaluated eagerly rather than lazily, because validating it requires computing the scores over the full vocabulary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
by
|
NormalizeBy
|
The normalization strategy. |
required |
Returns:
| Type | Description |
|---|---|
Comparison
|
A new |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the comparison is already normalized by a different strategy. |
ValueError
|
If |
ValueError
|
If |