vqa_benchmarking_backend.utils.vocab

Module Contents

Classes

Vocabulary

class vqa_benchmarking_backend.utils.vocab.Vocabulary(itos: Dict[int, str] = {}, stoi: Dict[str, int] = {})
add_token(self, token: str)

Add a new token to the vocabulary. Will only be added, if it is not already inside the vocabulary.

save(self, path: str = '.data/vocab.json')

Save current state of voocabulary to file.

classmethod load(cls, path: str = '.data/vocab.json')

Load existing vocabulary from file. Returns:

An instance of the loaded vocabulary.

stoi(self, word: str) Union[int, None]

String to index

itos(self, index: str) Union[str, None]

Index to string

exists(self, word: str) bool

Returns: True, if word exists in this vocabulary, else False

__len__(self) int

Returns: Size of vocabulary (how many words in vocabulary)