kpe / bert-for-tf2

A Keras TensorFlow 2.0 implementation of BERT, ALBERT and adapter-BERT.
https://github.com/kpe/bert-for-tf2
MIT License
803 stars 193 forks source link

support for dynamic length input #61

Open xuxingya opened 4 years ago

xuxingya commented 4 years ago

Instead of fixed length input: max_seq_len = 128 l_input_ids = keras.layers.Input(shape=(max_seq_len,), dtype='int32') l_token_type_ids = keras.layers.Input(shape=(max_seq_len,), dtype='int32')

Is it possible to support dynamic length input like: l_input_ids = keras.layers.Input(shape=(None,), dtype='int32') l_token_type_ids = keras.layers.Input(shape=(None,), dtype='int32')

Padding every single example makes the inference quite slower, especially when the length of inputs vary a lot.

sataliulan commented 4 years ago

I have the same issue