Can't import bert.tokenization

Viewed 18039

I am using Google Colab and the following import doesn't work somehow:

from bert.tokenization import FullTokenizer

I am getting this error:

ModuleNotFoundError: No module named 'bert.tokenization'

I tried to install bert by running the following command:

!pip install  --upgrade bert

Any idea how to resolve this error?

8 Answers

I found it:

!pip install bert-tensorflow

install : pip install bert-for-tf2

then import,

from bert import bert_tokenization BertTokenizer = bert_tokenization.FullTokenizer

or you may use previous version of BERT to avoid further complications (Atleast for now)

!pip install tensorflow-gpu==1.15.0
!pip install bert-tensorflow
from sklearn.model_selection import train_test_split
import pandas as pd
import tensorflow as tf
import tensorflow_hub as hub
from datetime import datetime
import bert
from bert import run_classifier
from bert import optimization
from bert import tokenization

In tf1:

!pip install bert-tokenizer
import bert_tokenizer as tokenization

tokenization.tokenizer.FullTokenizer

I could fix it by uninstalling and installing using both pip3 and pip.

!pip3  uninstall -y bert-tensorflow 
!pip  uninstall -y bert-tensorflow

!pip3  install bert-tensorflow 
!pip install bert-tensorflow

This worked for me:

!pip install bert-tokenizer

to use:

import bert_tokenizer as tokenizer

NOT import bert_tokenization as tokenization !!!

You might try this:

!pip install bert-tensorflow

!pip install  --upgrade bert

!pip install tokenization


from bert import tokenization  
from **bert.tokenization.bert_tokenization** import **FullTokenizer** 


tokenizer = FullTokenizer(vocab_file=vocab_file, do_lower_case=do_lower_case)
Related