CategoricalF1Score metric
Bases: CategoricalFBetaScore
Computes F-1 Score on categorical (list / label) structures.
Formula:
This is the harmonic mean of precision and recall.
Its output range is [0, 1]. It operates at a label level
and can be used for classification or retrieval pipelines.
The difference between this metric and F1Score is that this one considers
each element of the list (or the string value) as one label.
If labels is provided, accumulation is performed per-label (sklearn-style)
and result() returns a {label: score} dict for average=None. See
CategoricalFBetaScore for details.
Example:
# for single label classification
class ListClassification(synalinks.DataModel):
label: Literal["label", "label_1", "label_2"]
# for multi label classification
class ListClassification(synalinks.DataModel):
labels: List[Literal["label", "label_1", "label_2"]]
# or use it with retrieval pipelines, in that case make sure to mask
# the correct fields.
class AnswerWithReferences(synalinks.DataModel):
sources: List[str]
answer: str
Compilation example:
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
average
|
str
|
Type of averaging to be performed.
Acceptable values are |
None
|
labels
|
list
|
(Optional) Explicit list of label names to track.
When provided, accumulation is per-label across all batches and
|
None
|
name
|
str
|
(Optional) string name of the metric instance. |
'categorical_f1_score'
|
in_mask
|
list
|
(Optional) list of keys to keep to compute the metric. |
None
|
out_mask
|
list
|
(Optional) list of keys to remove to compute the metric. |
None
|
in_mask_pattern
|
str
|
(Optional) Regex pattern; fields whose names match
are kept (combined with |
None
|
out_mask_pattern
|
str
|
(Optional) Regex pattern; fields whose names match
are dropped (combined with |
None
|
Source code in synalinks/src/metrics/f_score_metrics.py
975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 | |
get_config()
Return the serializable config of the metric.
Returns:
| Type | Description |
|---|---|
dict
|
The config dict. |