Metrics
npfl138.metrics.BIOEncodingF1Score
Bases: Module
Metric for evaluating F1 score of BIO-encoded spans.
The metric employs a simple heuristic to handle invalid sequences of BIO tags. Notably:
- If there is an
I
tag without precedingB/I
tag, it is considered aB
tag. - If the type of an
I
tag does not match the type of the preceding tag, the type of thisI
tag is ignored (i.e., considered the same as the preceeding tag type).
Source code in npfl138/metrics.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
|
__init__
Construct a new BIOEncodingF1Score metric.
Parameters:
-
labels
(list[str]
) –The list of BIO-encoded labels.
-
ignore_index
(int
) –The gold index to ignore when computing the F1 score.
Source code in npfl138/metrics.py
23 24 25 26 27 28 29 30 31 32 33 34 35 |
|
reset
reset() -> Self
Reset the metric to its initial state.
Returns:
-
Self
–self
Source code in npfl138/metrics.py
37 38 39 40 41 42 43 44 45 46 |
|
update
Update the metric with new predictions and targets.
Returns:
-
Self
–self
Source code in npfl138/metrics.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
|
compute
compute() -> Tensor
Compute the F1 score.
Source code in npfl138/metrics.py
73 74 75 |
|
npfl138.metrics.EditDistance
Bases: Module
An implementation of mean edit distance metric.
Source code in npfl138/metrics.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
|
__init__
__init__(ignore_index: int | None = None) -> None
Construct a new EditDistance metric.
Parameters:
-
ignore_index
(int | None
, default:None
) –If not None, the gold index to ignore when computing the edit distance. The default is None, which means no index is ignored.
Source code in npfl138/metrics.py
81 82 83 84 85 86 87 88 89 90 91 |
|
reset
reset() -> Self
Reset the metric to its initial state.
Returns:
-
Self
–self
Source code in npfl138/metrics.py
93 94 95 96 97 98 99 100 101 |
|
update
Update the metric with new predictions and targets.
Returns:
-
Self
–self
Source code in npfl138/metrics.py
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
|
compute
compute() -> Tensor
Compute the mean edit distance.
Source code in npfl138/metrics.py
119 120 121 |
|
npfl138.metrics.MaskIoU
Bases: Module
An implementation of mean IoU metric computed on binary masks.
Source code in npfl138/metrics.py
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
|
__init__
Construct a new MaskIoU metric.
Parameters:
-
mask_shape
(Sequence[int]
) –The shape of the input masks as (H, W).
-
from_logits
(bool
, default:False
) –If
True
, the predictions are expected to be logits; otherwise, they are probabilities (the default). However, the target masks must always be probabilities.
Source code in npfl138/metrics.py
126 127 128 129 130 131 132 133 134 135 136 137 138 |
|
reset
reset() -> Self
Reset the metric to its initial state.
Returns:
-
Self
–self
Source code in npfl138/metrics.py
140 141 142 143 144 145 146 147 148 |
|
update
Update the metric with new predictions and targets.
Returns:
-
Self
–self
Source code in npfl138/metrics.py
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
|
compute
compute() -> Tensor
Compute the mean IoU.
Source code in npfl138/metrics.py
167 168 169 |
|