CategoricalAccuracy metric
Bases: Accuracy
Computes accuracy on list / categorical structures.
Formula (per field, Jaccard index over label sets):
Its output range is [0, 1]. It operates at a label level
and can be used for classification or retrieval pipelines.
Unlike Accuracy, this metric 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, a sample is "correct for L" when L's presence in
y_true matches its presence in y_pred. 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 for average=None.
If labels is None, a single global set-Jaccard 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
|
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_accuracy'
|
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/accuracy_metrics.py
476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 | |
get_config()
Return the serializable config of the metric.
Returns:
| Type | Description |
|---|---|
dict
|
The config dict. |