Skip to content

practicingman/bert_serving

Folders and files

NameName
Last commit message
Last commit date

Latest commit

44d3392 · Dec 12, 2018

History

88 Commits
Dec 12, 2018
Oct 31, 2018
Dec 12, 2018
Oct 31, 2018
Oct 31, 2018
Dec 12, 2018
Oct 31, 2018
Nov 28, 2018
Dec 12, 2018
Dec 12, 2018
Nov 9, 2018
Nov 15, 2018
Nov 15, 2018
Nov 24, 2018
Oct 31, 2018
Oct 31, 2018
Dec 12, 2018
Oct 31, 2018
Dec 12, 2018
Nov 5, 2018
Nov 24, 2018
Oct 31, 2018
Dec 12, 2018
Dec 12, 2018
Nov 24, 2018
Nov 15, 2018
Dec 12, 2018

Repository files navigation

export bert model for serving

predicting with estimator is slow, use export_savedmodel instead

create virtual environment

conda env create -f env.yml

train a classifier

bash train.sh

use the classifier

bash predict.sh

export bert model

bash export.sh

check out exported model

saved_model_cli show --all --dir $exported_dir

test exported model

bash test.sh

export it yourself

def serving_input_fn():
    label_ids = tf.placeholder(tf.int32, [None], name='label_ids')
    input_ids = tf.placeholder(tf.int32, [None, FLAGS.max_seq_length], name='input_ids')
    input_mask = tf.placeholder(tf.int32, [None, FLAGS.max_seq_length], name='input_mask')
    segment_ids = tf.placeholder(tf.int32, [None, FLAGS.max_seq_length], name='segment_ids')
    input_fn = tf.estimator.export.build_raw_serving_input_receiver_fn({
        'label_ids': label_ids,
        'input_ids': input_ids,
        'input_mask': input_mask,
        'segment_ids': segment_ids,
    })()
    return input_fn

and

estimator._export_to_tpu = False
estimator.export_savedmodel(FLAGS.export_dir, serving_input_fn)