speechbrain.utils.Accuracy moduleο
Calculate accuracy.
Authors * Jianyuan Zhong 2020
Summaryο
Classes:
Module for calculate the overall one-step-forward prediction accuracy. |
Functions:
Calculates the accuracy for predicted log probabilities and targets in a batch. |
Referenceο
- speechbrain.utils.Accuracy.Accuracy(log_probabilities, targets, length=None)[source]ο
Calculates the accuracy for predicted log probabilities and targets in a batch.
- Parameters:
log_probabilities (torch.Tensor) β Predicted log probabilities (batch_size, time, feature).
targets (torch.Tensor) β Target (batch_size, time).
length (torch.Tensor) β Length of target (batch_size,).
- Returns:
numerator (float) β The number of correct samples
denominator (float) β The total number of samples
Example
>>> probs = torch.tensor([[0.9, 0.1], [0.1, 0.9], [0.8, 0.2]]).unsqueeze(0) >>> acc = Accuracy( ... torch.log(probs), ... torch.tensor([1, 1, 0]).unsqueeze(0), ... torch.tensor([2 / 3]), ... ) >>> print(acc) (1.0, 2.0)
- class speechbrain.utils.Accuracy.AccuracyStats[source]ο
Bases:
objectModule for calculate the overall one-step-forward prediction accuracy.
Example
>>> probs = torch.tensor([[0.9, 0.1], [0.1, 0.9], [0.8, 0.2]]).unsqueeze(0) >>> stats = AccuracyStats() >>> stats.append( ... torch.log(probs), ... torch.tensor([1, 1, 0]).unsqueeze(0), ... torch.tensor([2 / 3]), ... ) >>> acc = stats.summarize() >>> print(acc) 0.5
- append(log_probabilities, targets, length=None)[source]ο
This function is for updating the stats according to the prediction and target in the current batch.
- Parameters:
log_probabilities (torch.Tensor) β Predicted log probabilities (batch_size, time, feature).
targets (torch.Tensor) β Target (batch_size, time).
length (torch.Tensor) β Length of target (batch_size,).