how can I make BERT word embedding faster?
Hello guys,
I have a code in which words get embedded with **Glove Embedding**  for the number of iterations.

model.word_emb= utils.load_word_emb(args.glove_embed_path)
a =time.time()
w = "Transformer"
X = model.word_emb.get(w, model.word_emb['unk'])
b =time.time()
print(b-a)
 
and for each word glove embedding takes 0.000275 sec. Now I want to shift with BERT embedding but the problem is,

from transformers import BertModel, BertTokenizer
tokenizer = BertTokenizer.from_pretrained('bert-base-uncased', do_lower_case=True)
bertModel = BertModel.from_pretrained('bert-base-uncased')
device = torch.device("cuda")
def bert_embedding(text):
        input_ids = (torch.tensor(tokenizer.encode(text)).unsqueeze(0))
        outputs = bertModel(input_ids)
        return (outputs[0][0][1])
a =time.time()
w = "Transformers"
X = bert_embedding(w)
b =time.time()
print(b-a)

it takes around 0.04235 sec which is **154 times** slower than Glove
how should I use Bert but with a speed of glove embedding?

Thank you so much in advance!
It seems you're not actually putting anything on GPU. You need to call `bertModel.to(device)` and `input_ids.to(device)`.

The BERT model is much larger than GloVe, however, so you'll never get the same speed.<|||||>Thank you @LysandreJik. It actually increases speed but not that much.
Is there any model which is better than Glove and also fast in embedding like Glove.<|||||>The fatest model we have in the library that I know of would be `DistilBERT`, which would still be slower than GloVe, but faster than BERT.

GloVe and transformer models are very different concepts, and solve different problems, hence why transformer models are way bigger/slower.<|||||>This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
