kiwi.metrics package

Submodules

kiwi.metrics.functions module

kiwi.metrics.functions.confusion_matrix(hat_y, y, n_classes=None)[source]
kiwi.metrics.functions.delta_average(y_true, y_rank)[source]

Calculate the DeltaAvg score

This is a much faster version than the Perl one provided in the WMT QE task 1.

References: could not find any.

Author: Fabio Kepler (contributed to MARMOT)

Parameters:
  • y_true – array of reference score (not rank) of each segment.
  • y_rank – array of rank of each segment.

Returns: the absolute delta average score.

kiwi.metrics.functions.f1_product(hat_y, y)[source]
kiwi.metrics.functions.f1_scores(hat_y, y)[source]

Return f1_bad, f1_ok and f1_product

kiwi.metrics.functions.fscore(tp, fp, fn)[source]
kiwi.metrics.functions.mean_absolute_error(y, y_hat)[source]
kiwi.metrics.functions.mean_squared_error(y, y_hat)[source]
kiwi.metrics.functions.precision(tp, fp, fn)[source]
kiwi.metrics.functions.precision_recall_fscore_support(hat_y, y, labels=None)[source]
kiwi.metrics.functions.recall(tp, fp, fn)[source]
kiwi.metrics.functions.scores_for_class(class_index, cnfm)[source]

kiwi.metrics.metrics module

class kiwi.metrics.metrics.CorrectMetric(**kwargs)[source]

Bases: kiwi.metrics.metrics.Metric

reset()[source]
summarize()[source]
update(model_out, batch, **kwargs)[source]
class kiwi.metrics.metrics.ExpectedErrorMetric(**kwargs)[source]

Bases: kiwi.metrics.metrics.Metric

reset()[source]
summarize()[source]
update(model_out, batch, **kwargs)[source]
class kiwi.metrics.metrics.F1Metric(labels, **kwargs)[source]

Bases: kiwi.metrics.metrics.Metric

reset()[source]
summarize()[source]
update(model_out, batch, **kwargs)[source]
class kiwi.metrics.metrics.LogMetric(targets, metric_name=None, **kwargs)[source]

Bases: kiwi.metrics.metrics.Metric

Logs averages of values in loss, model or batch.

reset()[source]
summarize()[source]
update(**kwargs)[source]
class kiwi.metrics.metrics.Metric(target_name=None, metric_name=None, PAD=None, STOP=None, prefix=None)[source]

Bases: object

get_name()[source]
get_predictions(model_out)[source]
get_predictions_flat(model_out, batch)[source]
get_target(batch)[source]
get_target_flat(batch)[source]
get_token_indices(batch)[source]
get_tokens(batch)[source]
reset()[source]
summarize(**kwargs)[source]
token_mask(batch)[source]
update(**kwargs)[source]
class kiwi.metrics.metrics.MovingF1[source]

Bases: kiwi.metrics.metrics.MovingMetric

choose(thresholds)[source]

Choose the best (threshold, metric) tuple from an iterable.

compute()[source]

Compute the current Value of the metric

init(scores, labels, class_idx=1)[source]

Compute F1 Mult for all decision thresholds over (scores, labels) Initialize the threshold s.t. all examples are classified as class_idx. :param scores: Likelihood scores for class index :param Labels: Gold Truth classes in {0,1} :param class_index: ID of class

update(score, label)[source]

Move the decision threshold.

class kiwi.metrics.metrics.MovingMetric[source]

Bases: object

Class to compute the changes in one metric as a function of a second metric. Example: F1 score vs. Classification Threshold, Quality vs Skips

choose(thresholds)[source]

Choose the best (threshold, metric) tuple from an iterable.

compute()[source]

Compute the current Value of the metric

eval(scores, labels)[source]

Compute the graph metric1 vs metric2 :param Scores: Model Outputs :param Labels: Corresponding Labels

init(scores, labels)[source]

Initialize the Metric for threshold < min(scores)

sort(scores, labels)[source]

Sort List of labels and scores.

update(score, label)[source]

Move the threshold past score

class kiwi.metrics.metrics.MovingSkipsAtQuality(scores_higher_is_better=False, labels_higher_is_better=False)[source]

Bases: kiwi.metrics.metrics.MovingMetric

Computes Quality of skipped examples vs fraction of skips.

choose(thresholds, target_qual)[source]

Chooses the smallest threshold such that avg. quality is greater than or equal to target_qual

compute()[source]

Compute the current Value of the metric

eval(scores, labels)[source]
Parameters:
  • scores – Model output quality or error scores. If quality scores are provided, pass scores_higher_is_better=True.
  • labels – Ground truth quality or error scores. If quality scores are provided, pass labels_higher_is_better=True.
init(scores, labels)[source]
Parameters:
  • scores – Model output quality or error scores. If quality scores are provided, pass scores_higher_is_better=True.
  • labels – Ground truth quality or error scores. If quality scores are provided, pass labels_higher_is_better=True.
sort(scores, labels)[source]

Sort List of labels and scores.

update(score, label)[source]

Move the threshold past score

class kiwi.metrics.metrics.NLLMetric(**kwargs)[source]

Bases: kiwi.metrics.metrics.Metric

reset()[source]
summarize()[source]
update(loss, batch, **kwargs)[source]
class kiwi.metrics.metrics.PearsonMetric(**kwargs)[source]

Bases: kiwi.metrics.metrics.Metric

reset()[source]
summarize()[source]
update(model_out, batch, **kwargs)[source]
class kiwi.metrics.metrics.PerplexityMetric(**kwargs)[source]

Bases: kiwi.metrics.metrics.Metric

reset()[source]
summarize()[source]
update(loss, batch, **kwargs)[source]
class kiwi.metrics.metrics.RMSEMetric(**kwargs)[source]

Bases: kiwi.metrics.metrics.Metric

reset()[source]
summarize()[source]
update(batch, model_out, **kwargs)[source]
class kiwi.metrics.metrics.SpearmanMetric(**kwargs)[source]

Bases: kiwi.metrics.metrics.Metric

reset()[source]
summarize()[source]
update(model_out, batch, **kwargs)[source]
class kiwi.metrics.metrics.ThresholdCalibrationMetric(**kwargs)[source]

Bases: kiwi.metrics.metrics.Metric

reset()[source]
summarize()[source]
update(model_out, batch, **kwargs)[source]
class kiwi.metrics.metrics.TokPerSecMetric(**kwargs)[source]

Bases: kiwi.metrics.metrics.Metric

reset()[source]
summarize()[source]
update(batch, **kwargs)[source]
class kiwi.metrics.metrics.TokenMetric(target_token=0, token_name='UNK', **kwargs)[source]

Bases: kiwi.metrics.metrics.Metric

reset()[source]
summarize()[source]
update(batch, **kwargs)[source]

kiwi.metrics.stats module

class kiwi.metrics.stats.Stats(metrics, main_metric=None, main_metric_ordering=<built-in function max>, log_interval=0)[source]

Bases: object

log(step=None)[source]
reset()[source]
summarize(prefix=None)[source]
update(**kwargs)[source]
wrap_up(prefix=None)[source]
class kiwi.metrics.stats.StatsSummary(prefix=None, main_metric=None, ordering=<built-in function max>, **kwargs)[source]

Bases: collections.OrderedDict

better_than(other)[source]
get(k[, d]) → D[k] if k in D, else d. d defaults to None.[source]
log()[source]

Log statistics to output and also to tracking logger.

Parameters:stats_summary – StatsSummary object
main_metric
main_metric_value()[source]

Module contents