Classifying news articles
In this exercise you will create a multi-class classification model.
The dataset is already loaded in the environment as news_novel. Also, all the pre-processing of the training data is already done and tokenizer is also available in the environment.
A RNN model was pre-trained with the following architecture: use the Embedding layer, one LSTM layer and the output Dense layer expecting three classes: sci.space, alt.atheism, and soc.religion.christian. The weights of this trained model are available on the classify_news_weights.h5 file.
You will pre-process the novel data and evaluate on a new dataset news_novel.
Diese Übung ist Teil des Kurses
Recurrent Neural Networks (RNNs) for Language Modeling with Keras
Anleitung zur Übung
- Transform the data present on
news_novel.datausing the loadedtokenizer. - Pad the obtained sequences of numerical indexes.
- Transform the labels present on
news_novel.targetinto a one-hot representation. - Evaluate the model using the method
.evaluate()and print the loss and accuracy obtained.
Interaktive Übung
Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.
# Change text for numerical ids and pad
X_novel = tokenizer.texts_to_sequences(____)
X_novel = pad_sequences(____, maxlen=400)
# One-hot encode the labels
Y_novel = to_categorical(____)
# Load the model pre-trained weights
model.load_weights('classify_news_weights.h5')
# Evaluate the model on the new dataset
loss, acc = model.____(X_novel, Y_novel, batch_size=64)
# Print the loss and accuracy obtained
print("Loss:\t{0}\nAccuracy:\t{1}".format(____, ____))