Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix double input bug for classification #265

Merged
merged 1 commit into from
Nov 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion bert_base/server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,10 @@ def classification_model_fn(features, labels, mode, params):
graph_def.ParseFromString(f.read())
input_ids = features["input_ids"]
input_mask = features["input_mask"]
input_map = {"input_ids": input_ids, "input_mask": input_mask}
#为了兼容多输入,增加segment_id特征,即训练代码中的input_type_ids特征。
#input_map = {"input_ids": input_ids, "input_mask": input_mask}
segment_ids=features["input_type_ids"]
input_map = {"input_ids": input_ids, "input_mask": input_mask,"segment_ids":segment_ids}
pred_probs = tf.import_graph_def(graph_def, name='', input_map=input_map, return_elements=['pred_prob:0'])

return EstimatorSpec(mode=mode, predictions={
Expand Down
7 changes: 5 additions & 2 deletions bert_base/server/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,11 @@ def optimize_class_model(args, num_labels, logger=None):

bert_config = modeling.BertConfig.from_json_file(os.path.join(args.bert_model_dir, 'bert_config.json'))
from bert_base.train.models import create_classification_model
loss, per_example_loss, logits, probabilities = create_classification_model(bert_config=bert_config, is_training=False,
input_ids=input_ids, input_mask=input_mask, segment_ids=None, labels=None, num_labels=num_labels)
#为了兼容多输入,增加segment_id特征,即训练代码中的input_type_ids特征。
#loss, per_example_loss, logits, probabilities = create_classification_model(bert_config=bert_config, is_training=False,
#input_ids=input_ids, input_mask=input_mask, segment_ids=None, labels=None, num_labels=num_labels)
segment_ids = tf.placeholder(tf.int32, (None, args.max_seq_len), 'segment_ids')
loss, per_example_loss, logits, probabilities = create_classification_model(bert_config=bert_config, is_training=False, input_ids=input_ids, input_mask=input_mask, segment_ids=segment_ids, labels=None, num_labels=num_labels)
# pred_ids = tf.argmax(probabilities, axis=-1, output_type=tf.int32, name='pred_ids')
# pred_ids = tf.identity(pred_ids, 'pred_ids')
probabilities = tf.identity(probabilities, 'pred_prob')
Expand Down