# How to save my tokenizer using save\_pretrained?

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-save-my-tokenizer-using-save-pretrained%2F9189%3E%5C
**Category:** Beginners\
**Created:** [August 12, 2021, 4:39pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-save-my-tokenizer-using-save-pretrained%2F9189 "2021-08-12T16:39:15Z")\
**Posts on this page:** 6\
**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:** [August 12, 2021, 4:39pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-save-my-tokenizer-using-save-pretrained%2F9189%2F1 "2021-08-12T16:39:15Z")

</div>

I have just followed [this](https://github.com/huggingface/notebooks/blob/master/examples/tokenizer_training.ipynb) tutorial on how to train my own tokenizer.

Now, from training my tokenizer, I have wrapped it inside a Transformers object, so that I can use it with the transformers library:

```auto
from transformers import BertTokenizerFast

new_tokenizer = BertTokenizerFast(tokenizer_object=tokenizer)

```

Then, I try to save my tokenizer using this code:

```auto
tokenizer.save_pretrained('/content/drive/MyDrive/Tokenzier')

```

However, from executing the code above, I get this error:

```auto
AttributeError: 'tokenizers.Tokenizer' object has no attribute 'save_pretrained'

```

Am I saving the tokenizer wrong?

If so, what is the correct approach to save it to my local files, so I can use it later?

---

<div class="post-metadata">

**Author:** ![sgugger](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/sgugger/32/2291_2.png) [@sgugger](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fsgugger)%5C
**Post date:** [August 12, 2021, 4:54pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-save-my-tokenizer-using-save-pretrained%2F9189%2F2 "2021-08-12T16:54:40Z")

</div>

You are saving the wrong tokenizer ;-). `new_tokenizer.save_pretrained(xxx)` should work.

---

<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:** [August 12, 2021, 5:07pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-save-my-tokenizer-using-save-pretrained%2F9189%2F3 "2021-08-12T17:07:18Z")

</div>

Thank you very much for that! And, one more thing… When I want to use my tokenizer for masked language modelling, do I use the pretrained model notebook?

---

<div class="post-metadata">

**Author:** ![sgugger](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/sgugger/32/2291_2.png) [@sgugger](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fsgugger)%5C
**Post date:** [August 12, 2021, 5:11pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-save-my-tokenizer-using-save-pretrained%2F9189%2F4 "2021-08-12T17:11:25Z")

</div>

I’m not sure which notebook you are referencing. If you want to train a language model from scratch on masked language modeling, it’s in [this notebook](https://github.com/huggingface/notebooks/blob/master/examples/language_modeling_from_scratch.ipynb).

---

<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:** [August 12, 2021, 10:52pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-save-my-tokenizer-using-save-pretrained%2F9189%2F5 "2021-08-12T22:52:06Z")

</div>

I see - will take a look at that. So, after training my tokenizer, how do I use it for masked language modelling task?

---

<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:** [August 13, 2021, 1:06pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-save-my-tokenizer-using-save-pretrained%2F9189%2F6 "2021-08-13T13:06:43Z")

</div>

@sgugger Do I replace the following with where I saved my trained tokenizer?

```auto
model_checkpoint = "bert-base-cased"
tokenizer_checkpoint = "sgugger/bert-like-tokenizer"

```
