# Does build\_vocab\_from\_iterator "flatten" the Iterable input?

**URL:** <https://discuss.pytorch.org/t/does-build-vocab-from-iterator-flatten-the-iterable-input/143688>\
**Category:** Uncategorized\
**Created:** [February 9, 2022, 5:27pm UTC](https://discuss.pytorch.org/t/does-build-vocab-from-iterator-flatten-the-iterable-input/143688 "2022-02-09T17:27:24Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![hogru](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/h/eb9ed0/32.png) [@hogru](https://discuss.pytorch.org/u/hogru)\
**Post date:** [February 9, 2022, 5:27pm UTC](https://discuss.pytorch.org/t/does-build-vocab-from-iterator-flatten-the-iterable-input/143688/1 "2022-02-09T17:27:24Z")

</div>

Hi,

basic question/issue about building a vocabulary. The toy code:

```auto
from torchtext.vocab import build_vocab_from_iterator
tokens = ['a', 'bc', 'def']
voc = build_vocab_from_iterator(tokens)
voc.get_stoi() # {'f': 5, 'c': 2, 'e': 4, 'd': 3, 'b': 1, 'a': 0}

```

I would have expected 3 entries in the vocabulary (instead of 6).

Is there another way to achieve this or is this not intended/supported?

Best,  
Stephan

torchtext version 0.11.2 on macOS
