Skip to content
Advertisement

TensorFlow TextVectorization producing Ragged Tensor with no padding after loading it from pickle

I have a TensorFlow TextVectorization layer named “eng_vectorization“:

JavaScript

and I saved it in a pickle file, using this code:

JavaScript

Then I load that pickle file properly as new_eng_vectorization:

JavaScript

Now I am expecting, both previous vectorization eng_vectorization and newly loaded vectorization new_eng_vectorization to work the same, but they are not.

The output of original vectorization, eng_vectorization(['Hello people']) is a Tensor:

JavaScript

And the output of pickled vectorization, new_eng_vectorization(['Hello people']) is a Ragged Tensor.

JavaScript

Both eng_vectorization and new_eng_vectorization have same config:

JavaScript

I think there is some problem with the way I saved the vectorization, how do I fix this? I am using this for deployment, that’s why I want that pickled vectorization to work as the previous one.

Here is a Google Colab link to a reproduciable code – [CLICK HERE]

Advertisement

Answer

The problem is related to a very recent bug, where the output_mode is not set correctly when it comes from a saved configuration.

This works:

JavaScript
JavaScript

This is currently not working correctly:

JavaScript
JavaScript

Even though both 'int' and from_disk['config']['output_mode'] are equal and of the same data type. Anyway, you can use the workaround for now.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement