/bert_exportable

TensorFlow code and pre-trained models for BERT

Primary LanguagePythonApache License 2.0Apache-2.0

This repository is fork of BERT

For export model as saved model, I added export functionality to run_squad.py.

Saved Model signature

$ saved_model_cli show --dir <pb basename> --tag_set serve --signature_def serving_default
The given SavedModel SignatureDef contains the following input(s):
  inputs['input_ids'] tensor_info:
      dtype: DT_INT32
      shape: (-1, 384)
      name: input_ids_1:0
  inputs['input_mask'] tensor_info:
      dtype: DT_INT32
      shape: (-1, 384)
      name: input_mask_1:0
  inputs['segment_ids'] tensor_info:
      dtype: DT_INT32
      shape: (-1, 384)
      name: segment_ids_1:0
  inputs['unique_ids'] tensor_info:
      dtype: DT_INT32
      shape: (-1)
      name: unique_ids_1:0
The given SavedModel SignatureDef contains the following output(s):
  outputs['end_logits'] tensor_info:
      dtype: DT_FLOAT
      shape: (-1, 384)
      name: unstack:1
  outputs['start_logits'] tensor_info:
      dtype: DT_FLOAT
      shape: (-1, 384)
      name: unstack:0
  outputs['unique_ids'] tensor_info:
      dtype: DT_INT32
      shape: (-1)
      name: Identity:0
Method name is: tensorflow/serving/predict

Serving exported model using tensorflow/serving

docker run -p 8500:8500 \
--mount type=bind,source=/Users/yoohyuck/data/korquad_v1/1614927513,target=/models/korquad_v1/1 \
-e MODEL_NAME=korquad_v1 \
-t tensorflow/serving 

Korquad Client (Will be made)

See client directory.

Build tensorflow docker image

See Dockerfile

Run run_squad.py in Docker

Run using mount files

Build tensorflow docker image by using Dockerfile. Use following command to run docker.

docker run \
-v ~/data/bert_exportable/:/bert_exportable \
-v ~/data/korquad_v1/:/korquad_v1 \
-v ~/data/bert_finetuned:/bert_finetuned \
-v /tmp:/tmp \
-it yoohuck12/ubuntu_with_tf:latest \
python3 /bert_exportable/run_squad.py \
--vocab_file=/bert_finetuned/vocab.txt \
--bert_config_file=/bert_finetuned/bert_config.json \
--init_checkpoint=/bert_finetuned/model.ckpt-7550 \
--do_predict=True \
--predict_file=/korquad_v1/dev_small.json \
--output_dir=/tmp

Build docker image directly (Not working yet)

You can run the run_squad in Docker by push image into Docker hub. Before pushing image into Docker hub, you should make a repository.

bazel run run_squad_image_push --incompatible_restrict_string_escapes=false

Error: IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!

Importing the numpy C-extensions failed. This error can happen for many reasons, often due to issues with your setup or how NumPy was installed.

We have compiled some common reasons and troubleshooting tips at:

https://numpy.org/devdocs/user/troubleshooting-importerror.html

Please note and check the following:

  • The Python version is: Python3.6 from "/usr/bin/python3"
  • The NumPy version is: "1.19.5"

and make sure that they are the versions you expect. Please carefully study the documentation linked above for further help.

Original error was: No module named 'numpy.core._multiarray_umath'