# Working with named entities with bert

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fworking-with-named-entities-with-bert%2F919%3E%5C
**Category:** Beginners\
**Created:** [August 29, 2020, 2:26pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fworking-with-named-entities-with-bert%2F919 "2020-08-29T14:26:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pritam](https://avatars.discourse-cdn.com/v4/letter/p/e36b37/32.png) [@pritam](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fpritam)%5C
**Post date:** [August 29, 2020, 2:26pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fworking-with-named-entities-with-bert%2F919%2F1 "2020-08-29T14:26:39Z")

</div>

I am working on a project where I have some named entities and I know their locations in the text. I want to use separate embedding vectors for those names. How do I modify the tokenizer and how do I add learnable vectors to the embedding matrix? Any suggestion or guide will be highly appreciated.

Edit:  
After looking into some documentations I found([here](https://huggingface.co/transformers/main_classes/tokenizer.html#transformers.SpecialTokensMixin.add_special_tokens)) that `tokenizer.add_special_tokens` is the thing I was looking for. However after `model.resize_token_embeddings(len(tokenizer))` is there any way to make only these new embeddings trainable?

---

<div class="post-metadata">

**Author:** ![rgwatwormhill](https://avatars.discourse-cdn.com/v4/letter/r/a9adbd/32.png) [@rgwatwormhill](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Frgwatwormhill)%5C
**Post date:** [August 30, 2020, 11:48am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fworking-with-named-entities-with-bert%2F919%2F2 "2020-08-30T11:48:35Z")

</div>

[I am not an expert]

I think the answer is No (unless you want to write some very detailed code).

Freezing is done on a per-layer basis, so either all the embeddings are trainable or all of them are not.

I’m not sure it would even make sense to try to write code to alter only your new embeddings. The whole Bert only works in context.

Are you sure you have enough data to train Bert to make useful embeddings of your new names?

---

<div class="post-metadata">

**Author:** ![pritam](https://avatars.discourse-cdn.com/v4/letter/p/e36b37/32.png) [@pritam](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fpritam)%5C
**Post date:** [August 30, 2020, 1:25pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fworking-with-named-entities-with-bert%2F919%2F3 "2020-08-30T13:25:55Z")

</div>

Thanks for your reply. I have just started working with BERT and trying out different things. I am not sure if there is enough data to create new embeddings, but I shall try it anyway.
