parlai.core.metrics¶
Provides standard metric evaluations for dialog, as well as an aggregator.
- classparlai.core.metrics.MetricDisplayData(title, description)[source] ¶
Bases:
NamedTuple- title:str¶
Alias for field number 0
- description:str¶
Alias for field number 1
- classparlai.core.metrics.Metric[source] ¶
Bases:
ABCBase class for storing metrics.
Subclasses should define .value(). Examples are provided for each subclass.
- propertyis_global:bool¶
Indicates whether this metric should be reported globally or per-task.
- propertymacro_average:bool¶
Indicates whether this metric should be macro-averaged when globally reported.
- classmethodmany(*objs:List[Union[List[Union[int,float,Tensor]],Tensor]]) → List[Metric ][source] ¶
Construct many of a Metric from the base parts.
Useful if you separately compute numerators and denominators, etc.
- classmethodfrom_mask(metric_per_token:Tensor, mask:Tensor) → List[Metric ][source] ¶
From token-level metrics, returns an aggregate MyMetric per example in the batch.
- Parameters
metric_per_token – a (batchsize x num_tokens) Tensor
mask – a (batchsize x num_tokens) Tensor to mask out tokens that should not be considered in the aggregate metric calculation.
- Returns
a (batchsize) Tensor
- classparlai.core.metrics.FixedMetric(value:Union[int,float,Tensor])[source] ¶
Bases:
MetricFixed metrics are verified to be the same when combined, or throw an error.
FixedMetric is used for things like total_train_updates, which should not be combined across different multitasks or different workers.
- classparlai.core.metrics.SumMetric(sum_:Union[int,float,Tensor]=0)[source] ¶
Bases:
MetricClass that keeps a running sum of some metric.
Examples of SumMetric include things like "exs", the number of examples seen since the last report, which depends exactly on a teacher.
- classparlai.core.metrics.AverageMetric(numer:Union[int,float,Tensor], denom:Union[int,float,Tensor]=1)[source] ¶
Bases:
MetricClass that keeps a running average of some metric.
Examples of AverageMetrics include hits@1, F1, accuracy, etc. These metrics all have per-example values that can be directly mapped back to a teacher.
- propertymacro_average:bool¶
Indicates whether this metric should be macro-averaged when globally reported.
- classparlai.core.metrics.MacroAverageMetric(metrics:Dict[str,Metric ])[source] ¶
Bases:
MetricClass that represents the macro average of several numbers.
Used for aggregating task level metrics. It is only used for things that are AverageMetrics already.
- classparlai.core.metrics.TimerMetric(value:Union[int,float,Tensor], start_time:Optional[float]=None, end_time:Optional[float]=None)[source] ¶
Bases:
MetricA timer metric keep tracks of the first/last times it was used.
- classparlai.core.metrics.GlobalMetric[source] ¶
Bases:
objectA global metric is one that should not be aggregated across different tasks.
Examples of global metric include things like learning rate and updates. These need to be accumulated or averaged over multiple parleys, but cannot be correlated with a single task.
Key to it is the notion that any one worker or any one task already has a global view of the value, and so no combinations should be done. Note this is different then a FixedMetric, in that a GlobalMetric can be still averaged across multiple parleys(), but a FixedMetric is always fixed.
- classparlai.core.metrics.GlobalFixedMetric(value:Union[int,float,Tensor])[source] ¶
Bases:
GlobalMetric,FixedMetricGlobal fixed metric.
Used for things like total_train_updates.
- classparlai.core.metrics.GlobalSumMetric(sum_:Union[int,float,Tensor]=0)[source] ¶
Bases:
GlobalMetric,SumMetricGlobal sum metric.
Used for ‘exs’ and ‘updates’.
- classparlai.core.metrics.GlobalAverageMetric(numer:Union[int,float,Tensor], denom:Union[int,float,Tensor]=1)[source] ¶
Bases:
GlobalMetric,AverageMetricGlobal Average metric.
Used for things like learning rate, and many agent-specific metrics.
- classparlai.core.metrics.LegacyMetric(numer:Union[int,float,Tensor], denom:Union[int,float,Tensor]=1)[source] ¶
Bases:
GlobalAverageMetricLegacy Metrics are reported by agent as float.
- classparlai.core.metrics.GlobalTimerMetric(value:Union[int,float,Tensor], start_time:Optional[float]=None, end_time:Optional[float]=None)[source] ¶
Bases:
GlobalMetric,TimerMetric
- classparlai.core.metrics.F1Metric(numer:Union[int,float,Tensor], denom:Union[int,float,Tensor]=1)[source] ¶
Bases:
AverageMetricHelper class which computes token-level F1.
- classparlai.core.metrics.ExactMatchMetric(numer:Union[int,float,Tensor], denom:Union[int,float,Tensor]=1)[source] ¶
Bases:
AverageMetric
- classparlai.core.metrics.BleuMetric(numer:Union[int,float,Tensor], denom:Union[int,float,Tensor]=1)[source] ¶
Bases:
AverageMetric- staticcompute(guess:str, answers:List[str], k:int=4) → Optional[BleuMetric ][source] ¶
Compute approximate BLEU score between guess and a set of answers.
- classparlai.core.metrics.FairseqBleuMetric(pred:Union[Tensor,List[int]], ref:Union[Tensor,List[int]], pad_idx:int, eos_idx:int, unk_idx:int, order:int)[source] ¶
Bases:
MetricRe-implementation of https://github.com/pytorch/fairseq/blob/main/fairseq/scoring/bleu.py.
- __init__(pred:Union[Tensor,List[int]], ref:Union[Tensor,List[int]], pad_idx:int, eos_idx:int, unk_idx:int, order:int)[source] ¶
- propertymacro_average:bool¶
Indicates whether this metric should be macro-averaged when globally reported.
- classparlai.core.metrics.RougeMetric(numer:Union[int,float,Tensor], denom:Union[int,float,Tensor]=1)[source] ¶
Bases:
AverageMetric- staticcompute_many(guess:str, answers:List[str], measure:str='r') → Tuple[Optional[RougeMetric ],Optional[RougeMetric ],Optional[RougeMetric ]][source] ¶
Compute ROUGE score between guess and any answer.
Done with compute_many due to increased efficiency.
- Returns
(rouge-1, rouge-2, rouge-L)
- classparlai.core.metrics.IntraDistinctMetric(numer:Union[int,float,Tensor], denom:Union[int,float,Tensor]=1)[source] ¶
Bases:
AverageMetricCompute intra-distinct (per-utterance).
- classparlai.core.metrics.InterDistinctMetric(counts:Counter[Tuple])[source] ¶
Bases:
MetricCompute inter-distinct metric over corpus-level.
- parlai.core.metrics.normalize_answer(s)[source] ¶
Lower text and remove punctuation, articles and extra whitespace.
- parlai.core.metrics.aggregate_named_reports(named_reports:Dict[str,Dict[str,Metric ]], micro_average:bool=False) → Dict[str,Metric ][source] ¶
Aggregate metrics from multiple reports.
- Parameters
reports – Dict of tasks -> metrics.
micro_average – If true, top level metrics will be the micro average. By default, we use macro average.
- Returns
The aggregated report
- parlai.core.metrics.aggregate_unnamed_reports(reports:List[Dict[str,Metric ]]) → Dict[str,Metric ][source] ¶
Combines metrics without regard for tracking provenence.
- classparlai.core.metrics.Metrics(threadsafe=False, shared=None)[source] ¶
Bases:
objectMetrics aggregator.