bert-serving-start giving error TypeError: cannot unpack non-iterable NoneType object - tried multiple paths to the model

Viewed 2445

I am trying to use BERT with bert-serving-start in python3.8 but it does not initialise and throws error:

TypeError: cannot unpack non-iterable NoneType object

This may have something to do with the path not being recognised but I followed the instructions as follows: https://github.com/hanxiao/bert-as-service#install

My folder is unzipped and entire model path is:

C:\Users\g\PycharmProjects\Project1\cased_L-12_H-768_A-12\cased_L-12_H-768_A-12

This occurs when running this in the command line as instructed.

bert-serving-start 
-model_dir \Users\g\PycharmProjects\Project1\cased_L-12_H-768_A-12\cased_L-12_H-768_A-12 -num_worker=1

I don't know if this is a bug to report as it does say untested with the current Tensorflow but it may just be a mistake I made.

Was hoping someone could double check it's not me before submitting a bug report.

5 Answers

Short Answer

You are using too new a version of Tensorflow. BERT-as-a-Service works only with a TF version between 1.10.0 and 1.15.0. Once you install the old version of Tensorflow, this error would go away. Also, use the absolute path, instead of relative path for the model_dir directory.

Long Answer

If you are on the latest version of Python and hence pip, you wouldn't be able to get TF 1.x versions. Currently TF 2.3.0 is out there. The oldest version of TF pip can get for you is 2.1.0cr1. But you can do the following to get say v1.15.0 of Tensorflow:

  1. Create a virtual environment with Python v3.7.6 that comes with old version of pip.

  2. Activate the new virtual environment.

  3. Install v1.15.0 of Tensorflow

  4. Install Bert server in this virtual environment.

  5. Start the Bert server

  6. You don't have to install bert client in this virtual environment. You can continue using the bert client in the base environment. It will still work.

    conda create -n test python=3.7.6
    conda activate test
    pip install tensorflow==1.15.0
    pip install bert-serving-server
    bert-serving-start -model_dir C:\Users\VHS\uncased_L-12_H-768_A-12\ -num_worker=2
    

I got this error with various versions including 1.15.0, 1.15.2, 1.15,3 but found it worked with 1.14.0, 1.15.4 and 1.15.5 when upgrading incrementally

Adding to the answer by @VHS, the following works (using tensorflow 1.13.0rc1).

conda create -n test python=3.7.6
conda activate test
pip install tensorflow==1.13.0rc1
pip install bert-serving-server
bert-serving-start -model_dir /path/to/pretrained/bert/uncased_L-12_H-768_A-12/ -num_worker=4

python 3.7.3 and tensorflow 1.15.0 works for me. be careful about the numpy version, my version is 1.18, too advanced will cause the same error

Related