flair.data.Dictionary#
- class flair.data.Dictionary(add_unk=True)View on GitHub#
Bases:
object
This class holds a dictionary that maps strings to IDs, used to generate one-hot encodings of strings.
- __init__(add_unk=True)View on GitHub#
Methods
__init__
([add_unk])add_item
(item)Add string - if already in dictionary returns its ID.
get_idx_for_item
(item)Returns the ID of the string, otherwise 0.
get_idx_for_items
(items)Returns the IDs for each item of the list of string, otherwise 0 if not found.
get_item_for_index
(idx)has_item
(item)load
(name)load_from_file
(filename)remove_item
(item)save
(savefile)- remove_item(item)View on GitHub#
- add_item(item)View on GitHub#
Add string - if already in dictionary returns its ID. if not in dictionary, it will get a new ID.
- Parameters:
item (
str
) – a string for which to assign an id.- Return type:
int
- Returns:
ID of string
- get_idx_for_item(item)View on GitHub#
Returns the ID of the string, otherwise 0.
- Parameters:
item (
str
) – string for which ID is requested- Return type:
int
- Returns:
ID of string, otherwise 0
- get_idx_for_items(items)View on GitHub#
Returns the IDs for each item of the list of string, otherwise 0 if not found.
- Parameters:
items (
list
[str
]) – List of string for which IDs are requested- Return type:
list
[int
]- Returns:
List of ID of strings
- get_items()View on GitHub#
- Return type:
list
[str
]
- get_item_for_index(idx)View on GitHub#
- Return type:
str
- has_item(item)View on GitHub#
- Return type:
bool
- set_start_stop_tags()View on GitHub#
- Return type:
None
- is_span_prediction_problem()View on GitHub#
- Return type:
bool
- start_stop_tags_are_set()View on GitHub#
- Return type:
bool
- save(savefile)View on GitHub#
- classmethod load_from_file(filename)View on GitHub#
- Return type:
- classmethod load(name)View on GitHub#
- Return type: