user872009
user872009

Reputation: 438

Alternative for TensorFlow tf.contrib

I keep getting an error when i run this code:

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))

This is the error I get: AttributeError: module 'tensorflow' has no attribute 'contrib'

Is there another approach to run this without having use an old version of tensorflow. I understand I am getting this error because tf.contrib. has been deprecated.

Upvotes: 0

Views: 517

Answers (1)

lejlot
lejlot

Reputation: 66835

You can take a look at how new examples are dealing with text preprocessing, as an example

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)

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

Upvotes: 1

Related Questions