# biome.text.vocabulary Module

Manages vocabulary tasks and fetches vocabulary information

Provides utilities for getting information from a given vocabulary.

Provides management actions such as extending the labels, setting new labels or creating an "empty" vocab.

# get_labels Function


def get_labels(vocab: allennlp.data.vocabulary.Vocabulary) -> List[str]

Gets list of labels in the vocabulary

Parameters

vocab : allennlp.data.Vocabulary
 

Returns

labels : List[str]
A list of label strings

# label_for_index Function


def label_for_index (
  vocab: allennlp.data.vocabulary.Vocabulary,
  idx: int,
)  -> str

Gets label string for a label int id

Parameters

vocab : allennlp.data.Vocabulary
 
idx : `int
the token index

Returns

label : str
The string for a label id

# index_for_label Function


def index_for_label (
  vocab: allennlp.data.vocabulary.Vocabulary,
  label: str,
)  -> int

Gets the label int id for label string

Parameters

vocab : ``allennlp.data.Vocabulary```
 
label : str
the label

Returns

label_idx : int
The label id for label string

# get_index_to_labels_dictionary Function


def get_index_to_labels_dictionary(vocab: allennlp.data.vocabulary.Vocabulary) -> Dict[int, str]

Gets a dictionary for turning label int ids into label strings

Parameters

vocab : allennlp.data.Vocabulary
 

Returns

labels : Dict[int, str]
A dictionary to get fetch label strings from ids

# words_vocab_size Function


def words_vocab_size(vocab: allennlp.data.vocabulary.Vocabulary) -> int

Fetches the vocabulary size for the words namespace

Parameters

vocab : allennlp.data.Vocabulary
 

Returns

size : int
The vocabulary size for the words namespace

# extend_labels Function


def extend_labels (
  vocab: allennlp.data.vocabulary.Vocabulary,
  labels: List[str],
) 

Adds a list of label strings to the vocabulary

Use this to add new labels to your vocabulary (e.g., useful for reusing the weights of an existing classifier)

Parameters

vocab : allennlp.data.Vocabulary
 
labels : List[str]
A list of strings containing the labels to add to an existing vocabulary

# set_labels Function


def set_labels (
  vocab: allennlp.data.vocabulary.Vocabulary,
  new_labels: List[str],
) 

Resets the labels in the vocabulary with a given labels string list

Parameters

vocab : allennlp.data.Vocabulary
 
new_labels : List[str]
The label strings to add to the vocabulary

# create_empty_vocabulary Function


def create_empty_vocabulary() -> allennlp.data.vocabulary.Vocabulary

Creates an empty Vocabulary with configured namespaces

Returns

empty_vocab
The transformers namespace is added to the non_padded_namespace.

# is_empty Function


def is_empty (
  vocab: allennlp.data.vocabulary.Vocabulary,
  namespaces: List[str],
)  -> bool

Checks if a vocab is empty respect to given namespaces

Returns True vocab size is 0 for all given namespaces

# load_vocabulary Function


def load_vocabulary(vocab_path: str) -> Union[allennlp.data.vocabulary.Vocabulary, NoneType]

Loads a vocabulary from a path Parameters


vocab_path : str
The vocab folder path

Returns

An operative allennlp.data.Vocabulary

Maintained by