每次运行以下代码时,我都会遇到错误:
from sklearn import preprocessing
lencoder = preprocessing.LabelEncoder()
voc_processor = tf.contrib.learn.preprocessing.VocabularyProcessor(kw_list)
voc_processor.fit(vocabulary)
X_transform = voc_processor.transform(reviews_df.reviewText)
X_transform = np.array(list(X_transform))
我得到的错误是:AttributeError: module 'tensorflow' has no attribute 'contrib'
有没有其他方法可以运行这段代码而不需要使用旧版本的TensorFlow?我明白我会遇到这个错误是因为tf.contrib.
已经被弃用。
回答:
你可以看看新的示例是如何处理文本预处理的,作为一个例子
import tensorflow as tf
import tensorflow_transform as tft
[...]
review_tokens = tf.compat.v1.string_split(review, DELIMITERS)
review_indices = tft.compute_and_apply_vocabulary(
review_tokens, top_k=VOCAB_SIZE)
来自https://github.com/tensorflow/transform/blob/master/examples/sentiment_example.py