# NameError: name 'BertTokenizer' is not defined

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fnameerror-name-berttokenizer-is-not-defined%2F6727%3E%5C
**Category:** Beginners\
**Created:** [June 11, 2021, 2:00pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fnameerror-name-berttokenizer-is-not-defined%2F6727 "2021-06-11T14:00:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon58275033](https://avatars.discourse-cdn.com/v4/letter/a/5f8ce5/32.png) [@anon58275033](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fanon58275033)%5C
**Post date:** [June 11, 2021, 2:00pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fnameerror-name-berttokenizer-is-not-defined%2F6727%2F1 "2021-06-11T14:00:27Z")

</div>

Hi,

I am trying to add custom tokens using this code below:

```auto
# Let's see how to increase the vocabulary of Bert model and tokenizer
tokenizer = BertTokenizer.from_pretrained('bert-base-uncased')
model = AutoModelForMaskedLM.from_pretrained('bert-base-uncased')

num_added_toks = tokenizer.add_tokens(['token_1'])
print('We have added', num_added_toks, 'tokens')
model.resize_token_embeddings(len(tokenizer)) # Notice: resize_token_embeddings expect to receive the full size of the new vocabulary, i.e. the length of the tokenizer.

```

Though, when executing the above code, I get this error:

```auto
---------------------------------------------------------------------------

NameError Traceback (most recent call last)

<ipython-input-36-31798d520617> in <module>()
      1 # Let's see how to increase the vocabulary of Bert model and tokenizer
----> 2 tokenizer = BertTokenizer.from_pretrained('bert-base-uncased')
      3 model = AutoModelForMaskedLM.from_pretrained('bert-base-uncased')
      4 
      5 num_added_toks = tokenizer.add_tokens(['token_1'])

NameError: name 'BertTokenizer' is not defined

```

---

<div class="post-metadata">

**Author:** ![lewtun](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/lewtun/32/30995_2.png) [@lewtun](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Flewtun)%5C
**Post date:** [June 11, 2021, 3:50pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fnameerror-name-berttokenizer-is-not-defined%2F6727%2F2 "2021-06-11T15:50:40Z")

</div>

hey @anon58275033 what version of `transformers` are you using? i was not able to reproduce the error in v4.6.1

---

<div class="post-metadata">

**Author:** ![anon58275033](https://avatars.discourse-cdn.com/v4/letter/a/5f8ce5/32.png) [@anon58275033](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fanon58275033)%5C
**Post date:** [June 11, 2021, 3:55pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fnameerror-name-berttokenizer-is-not-defined%2F6727%2F3 "2021-06-11T15:55:23Z")

</div>

Hi @lewtun - I have actually fixed the error by adding this line of code:

```auto
from transformers import BertTokenizer, BertForMaskedLM

```
