如何解决“名称'imdb'未定义”错误

时间:2020-02-06 10:19:08

标签: python tensorflow

我正在尝试使用TensorFlow Hub:电影评论创建“ 文本分类”。下面是我的代码:

import tensorflow as td
from tensorflow import keras
import numpy as np

data = keras.datasets.imdb

(train_data, train_labels), (test_data, test_labels) = data.load_data(num_words=10000)

print(train_data[1])

word_index = imdb.get_word_index()

执行此代码时,我收到NameError: name 'imdb' is not defined。我应该如何解决?

1 个答案:

答案 0 :(得分:0)

尝试一下-

import tensorflow as tf
import tensorflow_datasets as tfds

dataset, information = tfds.load('imdb_reviews/subwords8k', with_info=True,                  as_supervised=True)
train_dataset, test_dataset = dataset['train'], dataset['test']