Create new translator for other Bert models #152
Replies: 8 comments 1 reply
-
The translator describes how to pre-process and post-process your model. To create a translator, you need to figure out what format is expected by your BERT model and what format the output it produces is in. Then, you just need to convert into that format from whatever Java type your naturally have and what Java type you would like to use for the results. Is there a particular BERT model you want to create a translator for? |
Beta Was this translation helpful? Give feedback.
-
I would like to deploy BERT model to predict masked word in a sentence |
Beta Was this translation helpful? Give feedback.
-
@FatosTorba we are working on common BERT translators and the tokenizer which uses https://github.com/google/sentencepiece. We will let you know when it is done. Meanwhile, you can check how to inference your own bert model for question answering for reference. |
Beta Was this translation helpful? Give feedback.
-
This is good. I am going to try it with TensorFlow. I was getting an error with the Tensflow because of Input/Output share for SQUD. I don't think we have appropriate packages for the same? Do you have any thing which is inline with input/output shape of this https://miro.medium.com/max/1192/0*1N9VOiOYeunX2Y1Z |
Beta Was this translation helpful? Give feedback.
-
I'm trying to run BertQA using model trained on Tensorflow 2 and exported as saved model. The model loads properly and shows correct input/output tensors with org.tensorflow.exceptions.TFInvalidArgumentException: unique_ids_1:0 is both fed and fetched.
at org.tensorflow.internal.c_api.AbstractTF_Status.throwExceptionIfNotOK (AbstractTF_Status.java:87)
at org.tensorflow.Session.run (Session.java:595)
at org.tensorflow.Session.access$100 (Session.java:70)
at org.tensorflow.Session$Runner.runHelper (Session.java:335)
at org.tensorflow.Session$Runner.run (Session.java:285)
at ai.djl.tensorflow.engine.TfSymbolBlock.forward (TfSymbolBlock.java:121)
at ai.djl.nn.Block.forward (Block.java:117)
at ai.djl.inference.Predictor.predict (Predictor.java:117)
at ai.djl.inference.Predictor.batchPredict (Predictor.java:157)
at ai.djl.inference.Predictor.predict (Predictor.java:112)
at com.mycompany.app.App.main (App.java:117)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run (ExecJavaMojo.java:254)
at java.lang.Thread.run (Thread.java:834) The same model runs fine on python. Any suggestions? |
Beta Was this translation helpful? Give feedback.
-
Hi @uniquetrij what translators are you using for your Bert model? You may need to modify existing BertQA Translator to preprocess the input to the exact format that the model requires. Could you share your reproducible code, model, and output of Here is an example of Bert Translator for TensorFlow 2 model, but it's for classification, it takes a single string input, you may need to modify it to take paragraph and questions ( |
Beta Was this translation helpful? Give feedback.
-
@roywei The issue seemed to be with the I was able to get around the error by changing line 672 in
to
and line 1260 (to prevent the code from breaking in
to
Exporting this to saved-model and then using it with DJL ran perfectly without any errors. I'll try to share an example soon. The modified version of the file can be found here. Note that this was forked from ultrons' repo to run on TF-v2. Also, I've added options for exporting a trained checkpoint to saved model in this file, thanks to bigboNed3. |
Beta Was this translation helpful? Give feedback.
-
Thanks! looks like a bug from TF Java side when invoking the C API. We will report and look into it. |
Beta Was this translation helpful? Give feedback.
-
Question
How to create translator for other Bert models ?
Thank you :)
Beta Was this translation helpful? Give feedback.
All reactions