from __future__ import absolute_import, division, print_function
import tensorflow as tf
from tensorflow import keras
import tensorflow_datasets as tfds
import numpy as np
# 加载IMDB数据集(train_data, test_data), info = tfds.load(# 数据集'imdb_reviews/subwords8k',# 训练集,数据集以tuple形式返回
split=(tfds.Split.TRAIN, tfds.Split.TEST),# Return (example, label) pairs from the dataset (instead of a dictionary).
as_supervised=True,# 返回`info`的结构
with_info=True)
for train_example, train_label in train_data.take(1):# 每个example都是一个数值数据,表示这电影评论print(train_example[0:10])# tf.Tensor([ 249 4 277 309 560 6 6639 4574 2 12], shape=(10,), dtype=int64)print(encoder.decode(train_example))# 解码 评论: As a lifelong fan of Dickens, I have invariably been disappointed by adaptations of his novels.<br /><br />Altho。。。。print(train_label)# 标签0: negative/1: positive