flair.data._PartOfSentence#
- class flair.data._PartOfSentence(sentence)View on GitHub#
Bases:
DataPoint
,ABC
Abstract base for data points within a Sentence (Token, Span, Relation).
Ensures labels added to these parts are also registered in the parent Sentence.
- __init__(sentence)View on GitHub#
Initializes _PartOfSentence.
- Parameters:
sentence – The parent sentence, can be None initially for Token.
Methods
__init__
(sentence)Initializes _PartOfSentence.
add_label
(typename, value[, score])Adds a label, propagating it to the parent Sentence's layer.
add_metadata
(key, value)Adds a key-value pair to the data point's metadata.
clear_embeddings
([embedding_names])Removes stored embeddings to free memory.
get_each_embedding
([embedding_names])Retrieves a list of individual embedding tensors.
get_embedding
([names])Retrieves embeddings, concatenating if multiple names are given or if names is None.
get_label
([label_type, zero_tag_value])Retrieves the primary label for a given type, or a default 'O' label.
get_labels
([typename])Retrieves all labels for a specific annotation layer.
get_metadata
(key)Retrieves metadata associated with the given key.
has_label
(typename)Checks if the data point has at least one label for the given annotation type.
has_metadata
(key)Checks if the data point has metadata for the given key.
remove_labels
(typename)Removes labels of a type, also removing them from the parent Sentence layer.
set_embedding
(name, vector)Stores an embedding tensor under a given name.
set_label
(typename, value[, score])Sets a label (overwriting), propagating the change to the parent Sentence.
to
(device[, pin_memory])Moves all stored embedding tensors to the specified device.
Attributes
embedding
Provides the primary embedding representation of the data point.
end_position
The ending character offset (exclusive) within the original text.
labels
Returns a list of all labels from all annotation layers.
score
Shortcut property for the score of the first label added.
start_position
The starting character offset within the original text.
tag
Shortcut property for the value of the first label added.
text
The textual representation of this data point.
unlabeled_identifier
A string identifier for the data point itself, without label info.
- add_label(typename, value, score=1.0, **metadata)View on GitHub#
Adds a label, propagating it to the parent Sentence’s layer.
- Return type:
- set_label(typename, value, score=1.0, **metadata)View on GitHub#
Sets a label (overwriting), propagating the change to the parent Sentence.
- Return type:
- remove_labels(typename)View on GitHub#
Removes labels of a type, also removing them from the parent Sentence layer.
- Return type:
None