I've trained a Keras model using the tf.data.Dataset API. So I have something like this:
dataset = tf.data.Dataset.from_tensor_slices((x, y))
dataset = dataset.map(lambda x, y: ({'reviews': x}, y))
dataset = dataset.map(preprocess)
sess = tf.Session()
sess.run(tf.tables_initializer())
tf.keras.backend.set_session(sess)
dataset = dataset.batch(50).repeat()
and then I do:
model.fit(dataset, steps_per_epoch=100, epochs=20)
and it all works.
However, I then try to evaluate my model on a test tf.data.Dataset with:
dataset = dataset.map(preprocess)
x = dataset.map(lambda x, y: x["reviews"])
y = dataset.map(lambda x, y: y)
preds = model.predict(x)
and it fails before prediction with this error:
TypeError: cannot concatenate 'str' and 'int' objects
from this call:
x = dataset.map(lambda x, y: x["reviews"])
I'm not sure what I'm doing incorrectly; when I inspect my dataset, I see elements that look like what I'd expect:
(array([30000, 28, 4417, 39, 77, 87, 52, 30000, 30000,
28, 955, 55, 30000, 707, 30000, 164, 295, 755,
183, 30000, 30000, 15, 1322, 30000, 30000, 102, 23,
755, 527, 52, 803, 804, 1125, 30000, 30000, 65,
30000, 21, 30000, 111, 127, 743, 23, 30000, 30000,
3337, 77, 2125, 5, 111, 220, 383, 102, 23,
30000, 527, 408, 5, 30000, 30000, 856, 1487, 28,
39, 14, 87, 52, 42, 31, 30000, 30000, 30000,
30000, 95, 153, 14, 87, 547, 12, 940, 30000,
30000, 15, 620, 1109, 55, 14, 87, 93, 408,
52, 30000, 30000, 30000, 1066, 6, 30000, 30000, 95,
153], dtype=int32), array([0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0.,
0., 0., 0.], dtype=float32))
Any ideas what I'm doing incorrectly?
Thanks!