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

export fine-tuned bert model from colab and run locally #473

Open
manishpatel005 opened this issue Mar 3, 2019 · 2 comments
Open

export fine-tuned bert model from colab and run locally #473

manishpatel005 opened this issue Mar 3, 2019 · 2 comments

Comments

@manishpatel005
Copy link

manishpatel005 commented Mar 3, 2019

I have a created a text classifier using SemEval14 dataset taking inspiration from https://colab.research.google.com/github/google-research/bert/blob/master/predicting_movie_reviews_with_bert_on_tf_hub.ipynb#scrollTo=IhJSe0QHNG7U
It seems that running saved_model_cli with the same input feaures with which the model was trained is not working.

!saved_model_cli show --all --dir '/content/drive/My Drive/CSCE665/BERT_Model/1551487035'
=> `MetaGraphDef with tag-set: 'serve' contains the following SignatureDefs:

signature_def['serving_default']:
The given SavedModel SignatureDef contains the following input(s):
inputs['input_ids'] tensor_info:
dtype: DT_INT32
shape: (-1, 128)
name: input_ids_1:0
inputs['input_mask'] tensor_info:
dtype: DT_INT32
shape: (-1, 128)
name: input_mask_1:0
inputs['label_ids'] tensor_info:
dtype: DT_INT32
shape: (-1)
name: label_ids_1:0
inputs['segment_ids'] tensor_info:
dtype: DT_INT32
shape: (-1, 128)
name: segment_ids_1:0
The given SavedModel SignatureDef contains the following output(s):
outputs['labels'] tensor_info:
dtype: DT_INT32
shape: unknown_rank
name: loss/Squeeze:0
outputs['probabilities'] tensor_info:
dtype: DT_FLOAT
shape: (-1, 2)
name: loss/LogSoftmax:0
Method name is: tensorflow/serving/predict`

`def getPrediction(in_sentences):

input_examples = [run_classifier.InputExample(guid="", text_a = x, text_b = y, label = 0) for x,y in in_sentences] # here, "" is just a dummy label
input_features = run_classifier.convert_examples_to_features(input_examples, label_list, MAX_SEQ_LENGTH, tokenizer)

return input_features`

`pred_para = [
"Mohandas was born in Porbandar, India on October 2, 1869. He came from an upper class family and his father was a leader in the local community. As was tradition where he grew up, Mohandas' parents arranged a marriage for him at the age of 13. Both the arranged marriage and the young age may seem strange to some of us, but it was the normal way of doing things where he grew up. ",
"know i am going to sound hypercritical but for me the movie that was being touted as the potential film of the century actually didn't really live up to the hype.Obviously the movie was only a build up to Avengers 4 that's going to feature a resurrection of the fallen avengers.But its not really the ending of the movie that bothers me.",
"In this course, we'll study the theory, design, and implementation of text-based and Web-based information retrieval systems, including algorithms and techniques at the core of modern search and recommender systems. By the end of the semester you will be able to",
"Artificial neural networks (ANN) or connectionist systems are computing systems inspired by the biological neural networks that constitute animal brains.[1] The neural network itself is not an algorithm, but rather a framework for many different machine learning algorithms to work together and process complex data inputs",
"A Binary Tree is complete if all levels are completely filled except possibly the last level and all nodes of last level are as left as possible (Binary Heaps are complete Binary Tree). For a complete Binary Tree, level order traversal is sufficient to store the tree. We know that the first node is root, next two nodes are nodes of next level, next four nodes are nodes of 2nd level and so on. ",
"The world is very full of people-appallingly-full, it has never been so full before, and they are all tumbling overeach other. Most of these people one doesn’t know and some of them one doesn’t like. Well, what is one to do?There are two solutions. One of them is the Nazi solution.If you don’t like people, kill them, banish them, and segregate them. The other way is much less thrilling, but it is on the whole the way of the democracies, and I prefer it. If you don’t like people, put up with them as well as you can. Don’t try to love them; you can’t, you’ll only strain yourself. But try to tolerate them."

]
pred_sentences = [
"When was Mohandas born",
"that was being touted as the potential film of the",
"information storage and retrieval",
"neural networks",
"serialization of binary tree",
"two solutions of people appalingly full"
]
pred = zip(pred_para,pred_sentences)`

Error -
Traceback (most recent call last):
File "/usr/local/bin/saved_model_cli", line 10, in
sys.exit(main())
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/tools/saved_model_cli.py", line 910, in main
args.func(args)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/tools/saved_model_cli.py", line 640, in run
args.inputs, args.input_exprs, args.input_examples)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/tools/saved_model_cli.py", line 552, in load_inputs_from_input_arg_string
input_examples = preprocess_input_examples_arg_string(input_examples_str)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/tools/saved_model_cli.py", line 465, in preprocess_input_examples_arg_string
input_dict = preprocess_input_exprs_arg_string(input_examples_str)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/tools/saved_model_cli.py", line 438, in preprocess_input_exprs_arg_string
'"<input_key>="' % input_exprs_str)
RuntimeError: --input_exprs "pre" format is incorrect. Please follow"<input_key>="

@jinamshah
Copy link

Hey! I'm facing a similar issue. Were you able to solve this?

@dhruvkp090
Copy link

Hey, same issue. Did you solve it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants