MCPcopy Create free account
hub / github.com/modelscope/FunASR / th_accuracy

Function th_accuracy

funasr/metrics/compute_acc.py:4–22  ·  view source on GitHub ↗

Calculate accuracy. Args: pad_outputs (Tensor): Prediction tensors (B * Lmax, D). pad_targets (LongTensor): Target label tensors (B, Lmax, D). ignore_label (int): Ignore label id. Returns: float: Accuracy value (0.0 - 1.0).

(pad_outputs, pad_targets, ignore_label)

Source from the content-addressed store, hash-verified

2
3
4def th_accuracy(pad_outputs, pad_targets, ignore_label):
5 """Calculate accuracy.
6
7 Args:
8 pad_outputs (Tensor): Prediction tensors (B * Lmax, D).
9 pad_targets (LongTensor): Target label tensors (B, Lmax, D).
10 ignore_label (int): Ignore label id.
11
12 Returns:
13 float: Accuracy value (0.0 - 1.0).
14
15 """
16 pad_pred = pad_outputs.view(
17 pad_targets.size(0), pad_targets.size(1), pad_outputs.size(1)
18 ).argmax(2)
19 mask = pad_targets != ignore_label
20 numerator = torch.sum(pad_pred.masked_select(mask) == pad_targets.masked_select(mask))
21 denominator = torch.sum(mask)
22 return float(numerator) / float(denominator)
23
24
25def compute_accuracy(pad_outputs, pad_targets, ignore_label):

Callers 15

_calc_att_lossMethod · 0.90
_calc_att_lossMethod · 0.90
_calc_att_lossMethod · 0.90
_calc_att_lossMethod · 0.90
forwardMethod · 0.90
_calc_att_lossMethod · 0.90
_calc_att_clas_lossMethod · 0.90
_calc_att_lossMethod · 0.90
_calc_att_lossMethod · 0.90
_calc_att_lossMethod · 0.90

Calls 1

argmaxMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…