Tensorflow contrib了解弃用警告

时间:2018-05-30 10:14:11

标签: python tensorflow machine-learning deprecation-warning

当我在代码中使用以下行时

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

我得到了这些警告。我该如何消除它们?

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.

2 个答案:

答案 0 :(得分:0)

没有100%替换功能。但是,有一些暗示的方法可能对替换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)

参考代码: https://github.com/tensorflow/transform/blob/master/examples/sentiment_example.py

2。通过tensorflow.keras进行预处理

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

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

无论如何,要找到100%替换它的方法并不容易。

答案 1 :(得分:-1)

所有这些警告都有更新说明。按照说明操作:切换到tf.data进行预处理。

相关问题