flair.data.DataPoint#
- class flair.data.DataPointView on GitHub#
Bases:
object
This is the parent class of all data points in Flair.
Examples for data points are Token, Sentence, Image, etc. Each DataPoint must be embeddable (hence the abstract property embedding() and methods to() and clear_embeddings()). Also, each DataPoint may have Labels in several layers of annotation (hence the functions add_label(), get_labels() and the property ‘label’)
- __init__()View on GitHub#
Methods
__init__
()add_label
(typename, value[, score])Adds a label to the
DataPoint
by internally creating aLabel
object.add_metadata
(key, value)clear_embeddings
([embedding_names])get_each_embedding
([embedding_names])get_embedding
([names])get_label
([label_type, zero_tag_value])get_labels
([typename])Returns all labels of this datapoint belonging to a specific annotation layer.
get_metadata
(key)has_label
(type)has_metadata
(key)remove_labels
(typename)set_embedding
(name, vector)set_label
(typename, value[, score])to
(device[, pin_memory])Attributes
- abstract property embedding: Tensor#
- set_embedding(name, vector)View on GitHub#
- get_embedding(names=None)View on GitHub#
- Return type:
Tensor
- get_each_embedding(embedding_names=None)View on GitHub#
- Return type:
list
[Tensor
]
- to(device, pin_memory=False)View on GitHub#
- Return type:
None
- clear_embeddings(embedding_names=None)View on GitHub#
- Return type:
None
- has_label(type)View on GitHub#
- Return type:
bool
- add_metadata(key, value)View on GitHub#
- Return type:
None
- get_metadata(key)View on GitHub#
- Return type:
Any
- has_metadata(key)View on GitHub#
- Return type:
bool
- add_label(typename, value, score=1.0, **metadata)View on GitHub#
Adds a label to the
DataPoint
by internally creating aLabel
object.- Parameters:
typename (
str
) – A string that identifies the layer of annotation, such as “ner” for named entity labels or “sentiment” for sentiment labelsvalue (
str
) – A string that sets the value of the label.score (
float
) – Optional value setting the confidence level of the label (between 0 and 1). If not set, a default confidence of 1 is used.**metadata – Additional metadata information.
- Return type:
- Returns:
A pointer to itself (DataPoint object, now with an added label).
- set_label(typename, value, score=1.0, **metadata)View on GitHub#
- remove_labels(typename)View on GitHub#
- Return type:
None
- get_label(label_type=None, zero_tag_value='O')View on GitHub#
- Return type:
- get_labels(typename=None)View on GitHub#
Returns all labels of this datapoint belonging to a specific annotation layer.
For instance, if a data point has been labeled with “sentiment”-labels, you can call this function as get_labels(“sentiment”) to return a list of all sentiment labels.
- abstract property unlabeled_identifier#
- abstract property start_position: int#
- abstract property end_position: int#
- abstract property text#
- property tag#
- property score#