简体   繁体   中英

Tensorflow contrib learn deprecation warnings

When I am using the below line in my code

vocab_processor = learn.preprocessing.VocabularyProcessor(max_document_length, vocabulary=bow)

I get theses warnings. How do I eliminate them ?

WARNING:tensorflow:From /usr/local/lib/python3.5/dist-packages/tensorflow/contrib/learn/python/learn/datasets/base.py:198: retry (from tensorflow.contrib.learn.python.learn.datasets.base) is deprecated and will be removed in a future version. Instructions for updating: Use the retry module or similar alternatives. WARNING:tensorflow:From /tmp/anyReader-376H566fJpAUSEt/anyReader-376qtSRQxT2gOiq.tmp:67: VocabularyProcessor.__init__ (from tensorflow.contrib.learn.python.learn.preprocessing.text) is deprecated and will be removed in a future version. Instructions for updating: Please use tensorflow/transform or tf.data. WARNING:tensorflow:From /usr/local/lib/python3.5/dist-packages/tensorflow/contrib/learn/python/learn/preprocessing/text.py:154: CategoricalVocabulary.__init__ (from tensorflow.contrib.learn.python.learn.preprocessing.categorical_vocabulary) is deprecated and will be removed in a future version. Instructions for updating: Please use tensorflow/transform or tf.data. WARNING:tensorflow:From /usr/local/lib/python3.5/dist-packages/tensorflow/contrib/learn/python/learn/preprocessing/text.py:170: tokenizer (from tensorflow.contrib.learn.python.learn.preprocessing.text) is deprecated and will be removed in a future version. Instructions for updating: Please use tensorflow/transform or tf.data.

There is no 100% replacement function. However, there are some implying methods that might be useful to replace the function of vocab_processor()

1. compute_and_apply_vocabulary()

# Need to install tensorflow_transform with tf 2.3 
import tensorflow_transform as tft
review_indices = tft.compute_and_apply_vocabulary(review_tokens, top_k=VOCAB_SIZE)

reference code: https://github.com/tensorflow/transform/blob/master/examples/sentiment_example.py

2. Adopt preprocessing from tensorflow.keras

from tensorflow.keras.preprocessing import text, sequence
x = tf.keraspreprocessing.sequence.pad_sequences(x, maxlen=max_document_length, padding='post', truncating='post')

reference: https://github.com/dennybritz/cnn-text-classification-tf/issues/147

Anyway, it is not easy to figure out a way to replace it 100%.

All of these warning have instructions for updating. Follow the instructions: switch to tf.data for preprocessing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM