Open shawei3000 opened 4 years ago
I tried adding following in the Model sub-class: @tf.function(input_signature=[{"unique_ids": tf.TensorSpec(shape=[ None], dtype=tf.int32), "input_ids": tf.TensorSpec(shape=[ None, max_seq], dtype=tf.int32), "input_mask": tf.TensorSpec(shape=[ None, max_seq], dtype=tf.int32), "segment_ids": tf.TensorSpec(shape=[ None, max_seq], dtype=tf.int32), "cls_index": tf.TensorSpec(shape=[ None], dtype=tf.int32), "p_mask": tf.TensorSpec(shape=[ None, max_seq], dtype=tf.float32) }#, bool ]) But still have issue/error export model during prediction....
@shawei3000 Post a simple code snippet , where i could reproduce the above error Try saving using https://www.tensorflow.org/api_docs/python/tf/keras/models/save_model
b). in function "predict_squad_customized", right before prediction, add: tf.keras.experimental.export_saved_model( squad_model, your-prefered_dir, serving_only=True, input_signature=[{"unique_ids": tf.TensorSpec(shape=[ None], dtype=tf.int32), "input_ids": tf.TensorSpec(shape=[ None, your_max_seq], dtype=tf.int32), "input_mask": tf.TensorSpec(shape=[ None, your_max_seq], dtype=tf.int32), "segment_ids": tf.TensorSpec(shape=[ None, your_max_seq], dtype=tf.int32), "cls_index": tf.TensorSpec(shape=[ None], dtype=tf.int32), "p_mask": tf.TensorSpec(shape=[ None, your_max_seq], dtype=tf.float32)}#, ],
)
I am guessing 2 issues:
I am new to TF 2.0, I tried to save model by " tf.saved_model.save(squad_m......", but always get errors, such as: " start_positions = inputs["start_positions"] KeyError: 'start_positions'". I am guessing this is because the use of subclassing of keras_model: "class ALBertQAModel(tf.keras.Model):" , could you confirm or help me understand if otherwise? Thanks, Jim