flair.data.Label#

class flair.data.Label(data_point, value, score=1.0, **metadata)View on GitHub#

Bases: object

Represents a label assigned to a DataPoint (e.g., Token, Span, Sentence).

data_point#

The data point this label is attached to.

Type:

DataPoint

value#

The string value of the label (e.g., “PERSON”, “POSITIVE”).

Type:

str

score#

The confidence score of the label (0.0 to 1.0).

Type:

float

metadata#

A dictionary for storing arbitrary additional metadata.

Type:

dict

typename#

The name of the annotation layer (set via DataPoint.add_label).

Type:

Optional[str]

__init__(data_point, value, score=1.0, **metadata)View on GitHub#

Initializes a Label.

Parameters:
  • data_point (DataPoint) – The data point this label describes.

  • value (str) – The label’s string value.

  • score (float, optional) – The confidence score (0.0-1.0). Defaults to 1.0.

  • **metadata – Arbitrary keyword arguments stored as metadata.

Methods

__init__(data_point, value[, score])

Initializes a Label.

set_value(value[, score])

Updates the value and score of the label.

to_dict()

Attributes

labeled_identifier

metadata_str

score

The confidence score of the label (between 0.0 and 1.0).

shortstring

typename

The name of the annotation layer this label belongs to (e.g., "ner").

unlabeled_identifier

value

The string value of the label.

set_value(value, score=1.0)View on GitHub#

Updates the value and score of the label.

property value: str#

The string value of the label.

property score: float#

The confidence score of the label (between 0.0 and 1.0).

to_dict()View on GitHub#
property shortstring#
property metadata_str: str#
property labeled_identifier#
property unlabeled_identifier#
property typename: str | None#

The name of the annotation layer this label belongs to (e.g., “ner”).