Shortcuts

torchtext.data.utils

ngrams_iterator

torchtext.data.utils.ngrams_iterator(token_list, ngrams)[source]

Return an iterator that yields the given tokens and their ngrams.

Parameters
  • token_list – A list of tokens

  • ngrams – the number of ngrams.

Examples

>>> token_list = ['here', 'we', 'are']
>>> list(ngrams_iterator(token_list, 2))
>>> ['here', 'here we', 'we', 'we are', 'are']

Docs

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources