#pip install tensorflow import tensorflow as tf from tensorflow.keras.datasets import reuters from tensorflow.keras.preprocessing.sequence import pad_sequences from tensorflow.keras.models import Sequential from tensorflow.keras.layers import Embedding, SimpleRNN, Dense (x_train, y_train), (x_test, y_test) = reuters.load_data(num_words=10000) x_train = pad_sequences(x_train, maxlen=100) x_test = pad_sequences(x_test, maxlen=100) model = Sequential([ Embedding(10000, 64), SimpleRNN(64), Dense(46, activation='softmax') # 46 classes for Reuters dataset ]) model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy']) model.fit(x_train, y_train, epochs=5, validation_data=(x_test, y_test)) test_loss, test_acc = model.evaluate(x_test, y_test) print(f"Test accuracy: {test_acc}")