scorers package

Submodules

scorers.boolean_scorer module

class scorers.boolean_scorer.BooleanScorer(predicate)[source]

Bases: PositiveScorer

Predicate-based scoring class

log_score(samples, context)[source]

Returns log-probabilities for the samples given the context by converting their scores to logspace

Parameters:
sampleslist(Sample)

samples to score, as a list

context: text

context used for the samples

Returns:
tensor of (-np.Inf / 0) log-probabilities
score(samples, context)[source]

Computes probabilities for samples and context by casting the instance’s predicate, ie scoring, function

Parameters:
sampleslist(Sample)

samples to score, as a list

context: text

context used for the samples

Returns:
tensor of (0 / 1) probabilities

scorers.exponential_scorer module

class scorers.exponential_scorer.ExponentialScorer(features, coefficients)[source]

Bases: PositiveScorer

Exponential scorer to add distributional constraints when building an EBM.

log_score(samples, context)[source]

Log-scores the samples given the context using the instance’s features and their coefficients

Parameters:
sampleslist(str)

list of samples to log-score

context: text

context used for the samples

Returns:
tensor of log-scores

scorers.pipeline_scorer module

class scorers.pipeline_scorer.PipelineScorer(label, params, temperature=1.0)[source]

Bases: PositiveScorer

Feature class relying on the pipelines from Huggingface’s transformers

log_score(samples, _)[source]

computes the log-scores of the samples from the label returned by the pipeline

Parameters:
sampleslist(Sample)

list of samples to log-score

Returns:
tensor of log-probabilities

scorers.positive_scorer module

class scorers.positive_scorer.PositiveScorer(scoring_function)[source]

Bases: Scorer

Scorer, but limited to positive values

log_score(samples, context)[source]

relies on the instance’s scoring function to compute the log-scores of the samples given the context

Parameters:
sampleslist(Sample)

list of samples to log-score

context: text

context that the samples relate to

Returns:
tensor of log-scores for the samples
score(samples, context)[source]

returns the scores for the samples given the context by exponentiating their log-scores

Parameters:
sampleslist(Sample)

list of samples to score

context: text

context that the samples relate to

Returns:
tensor of scores for the samples
class scorers.positive_scorer.Product(*scorers)[source]

Bases: PositiveScorer

Utility class to compose scorers on the product of their scores

log_score(samples, context)[source]

computes the product of the log-scores, hence adds the log-scores from the individual scorers

Parameters:
sampleslist(Sample)

list of samples to log-score

context: text

context used for the samples

scorers.scorer module

class scorers.scorer.Scorer(scoring_function)[source]

Bases: object

Generic scorer

score(samples, context)[source]

Relies on the instance’s scoring function to compute scores for the samples given the context

Parameters:
sampleslist()

the samples to score, as a list

context: text

context that the samples relate to

Returns:
tensor of scores for the samples

Module contents