How to save one_hot from tensorflow?

  nlp, one-hot-encoding, python, tensorflow, tensorflow2.0

I am doing a Natural Language Processing Project.

for this I am using one hot encoding from tensorflow.

from keras.preprocessing.text import one_hot

I have generated a sequence of numbers for a particular sentence .
i.e.[7473,
7491,
6019,
5950,
7562,
1396,
4641,
7098,
135,
6836,
4566,
934,
5085,
5521,
5786,
2854]

Now. I have created a lstm model and want to deploy using Flask API.
But , now , the one hot is not generating the same sequence of numbers for the same sentences.

I have tried saving one hot using pickle file ..But it didnt worked.

import joblib
joblib.dump(one_hot,"encoder.pkl")

I even tried using PythonHashSeed in terminal. They works on the same environment for the same time only.

!PYTHONHASHSEED=0

But None of them works for another place/future use.

Is there any method to save the one hot encoding list..using dict , json or any other methods ??

Source: Python Questions

LEAVE A COMMENT