所以我的代码是这样的:
# Fetch dataset
train_data, test_data = tfds.load(name="imdb_reviews", split=["train", "test"],
batch_size=-1, as_supervised=True)
train_examples, train_labels = tfds.as_numpy(train_data)
test_examples, test_labels = tfds.as_numpy(test_data)
np.save("train_examples", train_examples)
np.save("train_labels", train_labels)
np.save("test_examples", test_examples)
np.save("test_labels", test_labels)
# BUILD MODEL
model = "https://tfhub.dev/google/tf2-preview/gnews-swivel-20dim/1"
hub_layer = hub.KerasLayer(model, output_shape=[], input_shape=[],
dtype=tf.string, trainable=True, name='gnews_embedding')
model = build_model(hub_layer)
model.summary()
# SAVE AS CHECKPOINT (THE BEST ONLY)
es = tf.keras.callbacks.EarlyStopping(monitor='val_loss', patience=4, verbose=1, mode='min')
checkpoint = tf.keras.callbacks.ModelCheckpoint('model.h5', monitor='val_loss', save_best_only=True)
# TRAIN MODEL
history = model.fit(
train_examples,
train_labels,
epochs=20,
batch_size=BATCH_SIZE,
validation_split = .2,
shuffle = True,
callbacks = [checkpoint, es],
verbose=1)
# CHECK ACCURACY AND LOSS VALUE
model.load_weights('/app/model.h5')
results = model.evaluate(test_examples, test_labels)
text = "The gold rush apple from natora- this is the most expensive apple."
dataset = tf.data.Dataset.from_tensor_slices([text])
np.save("test_txt", test_txt)
resultsTest = model.evaluate(dataset, test_labels)
print("RESULT ACCURACY = ", resultsTest)
所以我尝试了解此预测的准确性/损失。我可以评估这样一个简单的句子还是只是重新训练模型以获得损失/准确性?