# Find the eqivalent for word.index in BERT?

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ffind-the-eqivalent-for-word-index-in-bert%2F13170%3E%5C
**Category:** 🤗Transformers\
**Created:** [December 28, 2021, 6:28am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ffind-the-eqivalent-for-word-index-in-bert%2F13170 "2021-12-28T06:28:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![toyl](https://avatars.discourse-cdn.com/v4/letter/t/73ab20/32.png) [@toyl](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Ftoyl)%5C
**Post date:** [December 28, 2021, 6:28am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ffind-the-eqivalent-for-word-index-in-bert%2F13170%2F1 "2021-12-28T06:28:52Z")

</div>

excuse me i need to get like a dictionary contains the word with its index like this

```auto
def word_for_id(integer, tokenizer):
    for word, index in tokenizer.word_index.items():
        if index == integer:
            return word
    return None

```

but with using BERT i couldn’t find the equivalent as i got `berttokenizer' object has no attribute 'word_index'`

---

<div class="post-metadata">

**Author:** ![jon-fernandes](https://avatars.discourse-cdn.com/v4/letter/j/57b2e6/32.png) [@jon-fernandes](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fjon-fernandes)%5C
**Post date:** [December 29, 2021, 7:07pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ffind-the-eqivalent-for-word-index-in-bert%2F13170%2F2 "2021-12-29T19:07:26Z")

</div>

BERT has word-piece tokens, so if you are after the associated IDs for these word-piece tokens, you can find these.

```auto
from transformers import AutoModel
checkpoint = 'bert-base-uncased'
tokenizer = AutoTokenizer.from_pretrained(checkpoint)
tokenizer.vocab

```

---

<div class="post-metadata">

**Author:** ![toyl](https://avatars.discourse-cdn.com/v4/letter/t/73ab20/32.png) [@toyl](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Ftoyl)%5C
**Post date:** [December 29, 2021, 11:18pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ffind-the-eqivalent-for-word-index-in-bert%2F13170%2F3 "2021-12-29T23:18:09Z")

</div>

thanks a lot for replying … excuse me what is the difference between tokenizer.get\_vocab() and tokenizer. vocab ? are both work the same?

---

<div class="post-metadata">

**Author:** ![toyl](https://avatars.discourse-cdn.com/v4/letter/t/73ab20/32.png) [@toyl](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Ftoyl)%5C
**Post date:** [December 31, 2021, 4:25pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ffind-the-eqivalent-for-word-index-in-bert%2F13170%2F4 "2021-12-31T16:25:36Z")

</div>

excuse me do i need to load my sentences to get the vocab or the vocab here for the pre-trained bert ?

---

<div class="post-metadata">

**Author:** ![jon-fernandes](https://avatars.discourse-cdn.com/v4/letter/j/57b2e6/32.png) [@jon-fernandes](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fjon-fernandes)%5C
**Post date:** [December 31, 2021, 9:52pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ffind-the-eqivalent-for-word-index-in-bert%2F13170%2F5 "2021-12-31T21:52:20Z")

</div>

> [@jon-fernandes](#):
>
> ```auto
> from transformers import AutoModel
> checkpoint = 'bert-base-uncased'
> tokenizer = AutoTokenizer.from_pretrained(checkpoint)
> tokenizer.vocab
> 
> ```

From a very quick scan, tokenizer.vocab is an attribute. tokenizer.get\_vocab() is a function. They both return a dictionary with the same number of items. I’m not sure why we need both.
