TensorFlow tf.contrib 的替代方案

每次运行以下代码时,我都会遇到错误:

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

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注