ListFBetaScore metric
Bases: FBetaScore
Computes F-Beta score on categorical (list / label) structures.
Formula:
This is the weighted 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, comparing
label sets rather than tokenized words.
If labels is provided, accumulation is performed per-label (sklearn-style):
for each label L, tp[L] += 1 when L appears in both y_true and
y_pred, fp[L] += 1 when it appears only in y_pred, fn[L] += 1 when
it appears only in y_true. This enables stable macro/weighted
averaging across batches even when some labels are absent from a given
sample, and lets result() return a {label: score} dict when
average=None.
If labels is None, a single global set-based TP/FP/FN is computed
over the pooled label values; in that mode average=None returns one
scalar (use labels=... for a per-label breakdown).
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 across per-field results
in the multi-field case.
Acceptable values are |
None
|
beta
|
float
|
Determines the weight of given to recall
in the harmonic mean between precision and recall. Defaults to |
1.0
|
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_fbeta_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
719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 | |
get_config()
Return the serializable config of the metric.
Returns:
| Type | Description |
|---|---|
dict
|
The config dict. |