pythonpytorchtorchtext

'Vocab' object has no attribute 'itos'


I am building ML models for NLP with pytorch, but as I define vocabulary for tekenized words in my text with "vacab" and try to use vocab.itos I get: 'Vocab' object has no attribute 'itos' error.

This is my vocab:

vocab = torchtext.vocab.vocab(counter, min_freq=1)

How can I solve this problem?


Solution

  • You should access torchtext.vocab.Vocab.get_itos to get the indices->tokens mapping.

    >>> itos = vocab.get_itos()