I'm getting this error while iterating through a tokenized text dataset:
tensorflow.python.framework.errors_impl.DataLossError: Attempted to pad to a smaller size than the input element
It probably stems from the fact that I simply cannot understand the padded_shapes=([None], (1,)) argument. Here's the dataset and the code:
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
import tensorflow as tf
import tensorflow_datasets as tfds
from collections import Counter
os.chdir('/home/nicolas/Documents/Datasets')
data = tf.data.experimental.CsvDataset('rotten_tomatoes_string.csv',
record_defaults=[tf.string, tf.string],
header=True, select_cols=[0, 1])
review_tokenizer= tfds.features.text.Tokenizer()
vocabulary = Counter()
for ix, (_, review) in enumerate(data):
review = tf.strings.lower(review)
tokens = review_tokenizer.tokenize(review.numpy())
vocabulary.update(tokens)
vocabulary = [key for (key, value) in vocabulary.items() if value >= 5 and len(key) > 2]
ratings = {'rotten', 'fresh'}
review_encoder = tfds.features.text.TokenTextEncoder(vocabulary)
freshness_encoder = tfds.features.text.TokenTextEncoder(ratings)
def encode(freshness, review):
review = review_encoder.encode(review.numpy())
freshness = freshness_encoder.encode(freshness.numpy())
return freshness, review
def tf_map(freshness, review):
encoded_freshness, review = tf.py_function(encode,
inp=[freshness, review],
Tout=[tf.int32, tf.int32])
review.set_shape([None])
encoded_freshness.set_shape(1,)
return encoded_freshness, review
TAKE = 480_000
train_data = data.map(tf_map).take(1000)
train_data = train_data.padded_batch(8, padded_shapes=([None], (1,)))
next(iter(train_data))
How can I deal with this?