I have to work on an AI project. From now on, I will explain the project I have to do.
Assistant
Sure, I'm here to help! Please go ahead and explain your AI project, and I'll do my best to assist you.
User
The data is divided into two parts.
Training data: train-p.csv
Test data: test-p.csv
The train-p.csv file consists of 3 columns of 'id', 'text' and 'label', and the test-p.csv file consists of 2 columns of 'id' and 'text'
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Okay, it sounds like you have a dataset with labeled text data and a corresponding label for each piece of text. This is a common setup for text classification tasks in AI.
To clarify, is the goal of your project to train a machine learning model on the training data and then use that model to predict the labels for the test data? And could you please provide more information about the type of labels in the dataset and the overall goal of the project?
User
Label consists of a total of 8, and the text column consists of news article data.
My goal is to predict test-p.csv and get the result in submission.csv that consists 'id' and 'label'
It is single-label, multiclass classification probelem
Assistant
Great, thank you for the additional information. It seems like you have a clear objective for your project, which is to train a machine learning model on the labeled training data and use it to predict the labels for the test data.
As you mentioned, this is a single-label, multiclass classification problem, where each article can be assigned to one of eight possible labels. This means that you will need to use a machine learning algorithm that is appropriate for this type of problem, such as a multiclass classifier like logistic regression, decision trees, random forests, or neural networks.
To start with the project, you can begin by exploring the dataset and performing some basic data analysis to gain a better understanding of the data. This can involve tasks like visualizing the distribution of labels in the training data, analyzing the length of the articles, and exploring any patterns or trends in the data.
Once you have a good understanding of the data, you can then preprocess the text data to prepare it for machine learning. This can involve tasks like tokenization, stemming or lemmatization, removing stop words, and converting the text data into numerical vectors that can be fed into a machine learning algorithm.
After preprocessing the data, you can then train a machine learning model on the training data and use it to predict the labels for the test data. Finally, you can submit the predictions to a submission.csv file that contains the article ids and predicted labels.
I hope this helps you get started with your AI project. Let me know if you have any further questions or need additional guidance!
User
How can I use one_hot encoding in this project?
Assistant
One hot encoding is a technique used to represent categorical data as numerical data, which is suitable for machine learning models. In your case, you can use one hot encoding to represent the categorical labels in your dataset as numerical data.
To apply one hot encoding to your dataset, you can use a library like scikit-learn. Here's an example code snippet that shows how you can use scikit-learn to apply one hot encoding to the labels in your dataset:
python
import pandas as pd
from sklearn.preprocessing import LabelEncoder, OneHotEncoder
# Load the training data
train_data = pd.read_csv('train-p.csv')
# Extract the labels from the training data
labels = train_data['label']
# Apply label encoding to the labels
label_encoder = LabelEncoder()
labels_encoded = label_encoder.fit_transform(labels)
# Apply one hot encoding to the encoded labels
onehot_encoder = OneHotEncoder(sparse=False)
labels_onehot = onehot_encoder.fit_transform(labels_encoded.reshape(-1, 1))
# Print the first five rows of the encoded and one hot encoded labels
print(labels_encoded[:5])
print(labels_onehot[:5])
In the above code, we first load the training data into a pandas dataframe and extract the labels column. We then apply label encoding to the labels using the LabelEncoder class from scikit-learn. This assigns a unique numerical value to each label in the dataset.
Next, we apply one hot encoding to the encoded labels using the OneHotEncoder class from scikit-learn. This creates a binary vector for each label in the dataset, where each element in the vector corresponds to a possible label value. For example, if we have eight possible labels in our dataset, each one hot encoded vector will have eight elements.
Finally, we print the first five rows of the encoded and one hot encoded labels to verify that the encoding was applied correctly.
You can use the same approach to apply one hot encoding to the labels in your test data as well.
User
Can you use to_categorical?
Assistant
Yes, you can also use the to_categorical function from the Keras utility module to perform one hot encoding on the labels in your dataset. Here's an example code snippet that shows how to use to_categorical to perform one hot encoding:
python
import pandas as pd
from keras.utils import to_categorical
# Load the training data
train_data = pd.read_csv('train-p.csv')
# Extract the labels from the training data
labels = train_data['label']
# Convert the labels to categorical
labels_categorical = to_categorical(labels)
# Print the shape of the categorical labels
print(labels_categorical.shape)
In the above code, we first load the training data into a pandas dataframe and extract the labels column. We then apply to_categorical to the labels to convert them into one hot encoded vectors.
The to_categorical function takes the label values as input and returns a binary matrix where each row corresponds to a label and each column corresponds to a possible label value. For example, if we have eight possible labels in our dataset, each one hot encoded vector will have eight elements.
Finally, we print the shape of the categorical labels to verify that the encoding was applied correctly.
Note that if you use to_categorical to encode your labels, you will need to make sure that the labels are integer values, rather than string values. You can use the LabelEncoder class from scikit-learn to convert string labels to integer labels before using to_categorical.
User
Using Sequential, can you make a model for this project?
Assistant
Sure, I can help you build a machine learning model for your text classification problem using Keras Sequential API. Here's an example code snippet that shows how you can build a simple neural network model using the Sequential API:
python
from keras.models import Sequential
from keras.layers import Dense, Dropout
from keras.optimizers import Adam
from keras.utils import to_categorical
import pandas as pd
import numpy as np
# Load the training data
train_data = pd.read_csv('train-p.csv')
# Extract the text and labels from the training data
texts = train_data['text']
labels = train_data['label']
# Convert the labels to categorical
labels_categorical = to_categorical(labels)
# Define the maximum number of words to use in the model
max_words = 10000
# Create a tokenizer to tokenize the text data
tokenizer = Tokenizer(num_words=max_words)
tokenizer.fit_on_texts(texts)
sequences = tokenizer.texts_to_sequences(texts)
# Pad the sequences to a maximum length of 1000 words
maxlen = 1000
X = pad_sequences(sequences, maxlen=maxlen)
# Define the model architecture
model = Sequential()
model.add(Dense(512, activation='relu', input_shape=(maxlen,)))
model.add(Dropout(0.5))
model.add(Dense(8, activation='softmax'))
# Compile the model
model.compile(loss='categorical_crossentropy', optimizer=Adam(lr=0.001), metrics=['accuracy'])
# Train the model on the training data
model.fit(X, labels_categorical, batch_size=32, epochs=10, validation_split=0.2)
# Load the test data
test_data = pd.read_csv('test-p.csv')
# Extract the text from the test data
test_texts = test_data['text']
# Tokenize and pad the test data
test_sequences = tokenizer.texts_to_sequences(test_texts)
test_X = pad_sequences(test_sequences, maxlen=maxlen)
# Make predictions on the test data
predictions = model.predict(test_X)
# Convert the predictions to labels
predicted_labels = np.argmax(predictions, axis=1)
# Save the predictions to a CSV file
submission = pd.DataFrame({'id': test_data['id'], 'label': predicted_labels})
submission.to_csv('submission.csv', index=False)
User
Can you decrease the dense layer size to 32? And add more dense layer
Assistant
Sure, here's an updated code snippet that reduces the size of the dense layer to 32 and adds another dense layer with 64 units:
python
from keras.models import Sequential
from keras.layers import Dense, Dropout
from keras.optimizers import Adam
from keras.utils import to_categorical
from keras.preprocessing.text import Tokenizer
from keras.preprocessing.sequence import pad_sequences
import pandas as pd
import numpy as np
# Load the training data
train_data = pd.read_csv('train-p.csv')
# Extract the text and labels from the training data
texts = train_data['text']
labels = train_data['label']
# Convert the labels to categorical
labels_categorical = to_categorical(labels)
# Define the maximum number of words to use in the model
max_words = 10000
# Create a tokenizer to tokenize the text data
tokenizer = Tokenizer(num_words=max_words)
tokenizer.fit_on_texts(texts)
sequences = tokenizer.texts_to_sequences(texts)
# Pad the sequences to a maximum length of 1000 words
maxlen = 1000
X = pad_sequences(sequences, maxlen=maxlen)
# Define the model architecture
model = Sequential()
model.add(Dense(32, activation='relu', input_shape=(maxlen,)))
model.add(Dropout(0.5))
model.add(Dense(64, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(8, activation='softmax'))
# Compile the model
model.compile(loss='categorical_crossentropy', optimizer=Adam(lr=0.001), metrics=['accuracy'])
# Train the model on the training data
model.fit(X, labels_categorical, batch_size=32, epochs=10, validation_split=0.2)
# Load the test data
test_data = pd.read_csv('test-p.csv')
# Extract the text from the test data
test_texts = test_data['text']
# Tokenize and pad the test data
test_sequences = tokenizer.texts_to_sequences(test_texts)
test_X = pad_sequences(test_sequences, maxlen=maxlen)
# Make predictions on the test data
predictions = model.predict(test_X)
# Convert the predictions to labels
predicted_labels = np.argmax(predictions, axis=1)
# Save the predictions to a CSV file
submission = pd.DataFrame({'id': test_data['id'], 'label': predicted_labels})
submission.to_csv('submission.csv', index=False)
In this updated code, we've modified the model architecture to include an additional dense layer with 64 units. The first dense layer now has 32 units instead of 512 as in the original code. We've also added a dropout layer after each dense layer for regularization.
The rest of the code remains the same as in the previous example. This code should work for your text classification problem, but you may need to experiment with different architectures and hyperparameters to find the best model for your dataset.
User
Please set the model layer size so that 8 classes can be classified effectively
Assistant
Sure, here's an example code snippet that uses a model architecture with more layers and larger layer sizes to effectively classify the 8 classes in your dataset:
python
from keras.models import Sequential
from keras.layers import Dense, Dropout, Embedding, GlobalMaxPooling1D
from keras.optimizers import Adam
from keras.utils import to_categorical
from keras.preprocessing.text import Tokenizer
from keras.preprocessing.sequence import pad_sequences
import pandas as pd
import numpy as np
# Load the training data
train_data = pd.read_csv('train-p.csv')
# Extract the text and labels from the training data
texts = train_data['text']
labels = train_data['label']
# Convert the labels to categorical
labels_categorical = to_categorical(labels)
# Define the maximum number of words to use in the model
max_words = 10000
# Create a tokenizer to tokenize the text data
tokenizer = Tokenizer(num_words=max_words)
tokenizer.fit_on_texts(texts)
sequences = tokenizer.texts_to_sequences(texts)
# Pad the sequences to a maximum length of 1000 words
maxlen = 1000
X = pad_sequences(sequences, maxlen=maxlen)
# Define the model architecture
model = Sequential()
model.add(Embedding(max_words, 128, input_length=maxlen))
model.add(GlobalMaxPooling1D())
model.add(Dense(256, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(128, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(64, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(8, activation='softmax'))
# Compile the model
model.compile(loss='categorical_crossentropy', optimizer=Adam(lr=0.001), metrics=['accuracy'])
# Train the model on the training data
model.fit(X, labels_categorical, batch_size=32, epochs=10, validation_split=0.2)
# Load the test data
test_data = pd.read_csv('test-p.csv')
# Extract the text from the test data
test_texts = test_data['text']
# Tokenize and pad the test data
test_sequences = tokenizer.texts_to_sequences(test_texts)
test_X = pad_sequences(test_sequences, maxlen=maxlen)
# Make predictions on the test data
predictions = model.predict(test_X)
# Convert the predictions to labels
predicted_labels = np.argmax(predictions, axis=1)
# Save the predictions to a CSV file
submission = pd.DataFrame({'id': test_data['id'], 'label': predicted_labels})
submission.to_csv('submission.csv', index=False)
User
Can you make it use tf to use gpu?
Assistant
Yes, you can use TensorFlow with GPU acceleration to train your model faster. Here's an updated code snippet that shows how to use TensorFlow with GPU acceleration:
python
import tensorflow as tf
from keras.models import Sequential
from keras.layers import Dense, Dropout, Embedding, GlobalMaxPooling1D
from keras.optimizers import Adam
from keras.utils import to_categorical
from keras.preprocessing.text import Tokenizer
from keras.preprocessing.sequence import pad_sequences
import pandas as pd
import numpy as np
# Specify the GPU device to use
physical_devices = tf.config.list_physical_devices('GPU')
tf.config.experimental.set_memory_growth(physical_devices[0], True)
# Load the training data
train_data = pd.read_csv('train-p.csv')
# Extract the text and labels from the training data
texts = train_data['text']
labels = train_data['label']
# Convert the labels to categorical
labels_categorical = to_categorical(labels)
# Define the maximum number of words to use in the model
max_words = 10000
# Create a tokenizer to tokenize the text data
tokenizer = Tokenizer(num_words=max_words)
tokenizer.fit_on_texts(texts)
sequences = tokenizer.texts_to_sequences(texts)
# Pad the sequences to a maximum length of 1000 words
maxlen = 1000
X = pad_sequences(sequences, maxlen=maxlen)
# Define the model architecture
model = Sequential()
model.add(Embedding(max_words, 128, input_length=maxlen))
model.add(GlobalMaxPooling1D())
model.add(Dense(256, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(128, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(64, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(8, activation='softmax'))
# Compile the model
model.compile(loss='categorical_crossentropy', optimizer=Adam(lr=0.001), metrics=['accuracy'])
# Train the model on the training data using the GPU
with tf.device('/GPU:0'):
model.fit(X, labels_categorical, batch_size=32, epochs=10, validation_split=0.2)
# Load the test data
test_data = pd.read_csv('test-p.csv')
# Extract the text from the test data
test_texts = test_data['text']
# Tokenize and pad the test data
test_sequences = tokenizer.texts_to_sequences(test_texts)
test_X = pad_sequences(test_sequences, maxlen=maxlen)
# Make predictions on the test data
with tf.device('/GPU:0'):
predictions = model.predict(test_X)
# Convert the predictions to labels
predicted_labels = np.argmax(predictions, axis=1)
# Save the predictions to a CSV file
submission = pd.DataFrame({'id': test_data['id'], 'label': predicted_labels})
submission.to_csv('submission.csv', index=False)
User
Can you improve the model more?
Assistant
Sure, here are some ways to potentially improve the model:
Increase the size of the training dataset: If you have more labeled training data, you can use it to train a more accurate model. One way to do this is to use data augmentation techniques, such as adding noise or rotating the text data.
Use pre-trained word embeddings: Instead of training an embedding layer from scratch, you can use pre-trained word embeddings such as Word2Vec or GloVe. This can help the model better capture the semantics of the text data.
Use a more complex neural network architecture: You can experiment with different architectures, such as using convolutional neural networks (CNNs) or recurrent neural networks (RNNs) with attention mechanisms. These architectures can better capture the spatial or temporal dependencies in the text data.
Hyperparameter tuning: You can experiment with different learning rates, dropout rates, batch sizes, and other hyperparameters to find the optimal settings for your model.
Here's an example code snippet that implements some of these ideas:
python
User
Go on from the last line please
Assistant
Apologies for that! Here's the full code snippet:
python
# Compile the model
model.compile(loss='categorical_crossentropy', optimizer=Adam(lr=0.001), metrics=['accuracy'])
# Train the model on the training data using the GPU
with tf.device('/GPU:0'):
model.fit(X, labels_categorical, batch_size=64, epochs=15, validation_split=0.2)
# Load the test data
test_data = pd.read_csv('test-p.csv')
# Extract the text from the test data
test_texts = test_data['text']
# Tokenize and pad the test data
test_sequences = tokenizer.texts_to_sequences(test_texts)
test_X = pad_sequences(test_sequences, maxlen=maxlen)
# Make predictions on the test data
with tf.device('/GPU:0'):
predictions = model.predict(test_X)
# Convert the predictions to labels
predicted_labels = np.argmax(predictions, axis=1)
# Save the predictions to a CSV file
submission = pd.DataFrame({'id': test_data['id'], 'label': predicted_labels})
submission.to_csv('submission.csv', index=False)
In this updated code, we've made several changes to the model architecture:
We've used pre-trained Word2Vec embeddings to initialize the embedding layer. The embeddings are non-trainable in this example, but you can experiment with fine-tuning them if you have a large amount of labeled data.
We've added a spatial dropout layer after the embedding layer to help prevent overfitting.
We've used a 1D convolutional layer with max pooling to extract features from the text data.
We've used a bidirectional LSTM layer with attention to capture the temporal dependencies in the text data.
We've added a global average pooling layer to compute the average of the features across all time steps.
We've reduced the batch size to 64 and increased the number of epochs to 15 to improve the model's convergence.
You can experiment with different architectures and hyperparameters to further improve the model's accuracy. Keep in mind that the optimal settings will depend on the characteristics of your dataset.
User
Can you add earlystops?
Assistant
Yes, adding early stopping can help prevent overfitting and improve the generalization performance of the model. Here's an updated code snippet that includes early stopping:
python
User
Go on from the last line please
Assistant
Sorry about that! Here's the full code snippet with the last line included:
python
# Save the predictions to a CSV file
submission = pd.DataFrame({'id': test_data['id'], 'label': predicted_labels})
submission.to_csv('submission.csv', index=False)
In this updated code, we added an early stopping callback to the fit method. The EarlyStopping callback monitors the validation loss, and stops the training process if the validation loss does not improve for a certain number of epochs (in this case, 3). This helps prevent overfitting and improves the generalization performance of the model.
You can experiment with different values for the patience parameter of the EarlyStopping callback to find the optimal settings for your model.
In the above code, we first load the training data into a pandas dataframe and extract the text and labels columns. We then convert the labels to categorical using the to_categorical function from Keras.
Next, we define the maximum number of words to use in the model, and create a Tokenizer object to tokenize the text data. We then use the Tokenizer object to convert the text data into sequences of word indices, and pad the sequences to a maximum length of 1000 words using the pad_sequences function from Keras.
After preprocessing the data, we define the model architecture using the Sequential API. In this example, we use a simple neural network with a dense hidden layer, a dropout layer for regularization, and a dense output layer with a softmax activation function.
We then compile the model using the categorical crossentropy loss function, the Adam optimizer, and accuracy as a metric.
Next, we train the model on the training data using the fit method, specifying the batch size, number of epochs, and validation split.
After training the model, we load the test data into a pandas dataframe and extract the text column. We then tokenize and pad the test data using the same tokenizer and maximum length as the training data.
Finally, we make predictions on the test data using the predict method of the model, convert the predictions to labels using the argmax function from NumPy, and save the predictions to a CSV
In this code, we've used an embedding layer to transform the text data into a dense representation that can be fed into a neural network. We've then added a GlobalMaxPooling1D layer to extract the most important features from the embedded data. This is followed by three dense layers with 256, 128, and 64 units respectively, with dropout layers for regularization.
The output layer is a dense layer with 8 units and a softmax activation function, which is appropriate for multiclass classification problems like this one.
You may need to experiment with different architectures and hyperparameters to find the best model for your dataset. This code should give you a good starting point for building an effective text classification model with Keras.
In this code, we first specify the GPU device to use for training and prediction using the tf.device context manager. We then load the training and test data as before, and define the model architecture using Keras.
After compiling the model, we train it on the training data using the fit method, wrapped inside a tf.device context to run the training on the GPU.
Finally, we load the test data and make predictions on it using the predict method, wrapped inside a tf.device context to run the predictions on the GPU. The predicted labels are then saved to a CSV file as before.
Note that in order to use GPU acceleration, you need to have a compatible GPU installed on your machine, and have the necessary software and drivers installed. You can check the TensorFlow documentation for more information
import tensorflow as tf
from keras.models import Sequential
from keras.layers import Dense, Dropout, Embedding, LSTM, SpatialDropout1D, Conv1D, MaxPooling1D, Flatten, Bidirectional, Attention, GlobalAveragePooling1D
from keras.optimizers import Adam
from keras.utils import to_categorical
from keras.preprocessing.text import Tokenizer
from keras.preprocessing.sequence import pad_sequences
from gensim.models import Word2Vec
import pandas as pd
import numpy as np
# Specify the GPU device to use
physical_devices = tf.config.list_physical_devices('GPU')
tf.config.experimental.set_memory_growth(physical_devices[0], True)
# Load the training data
train_data = pd.read_csv('train-p.csv')
# Extract the text and labels from the training data
texts = train_data['text']
labels = train_data['label']
# Convert the labels to categorical
labels_categorical = to_categorical(labels)
# Define the maximum number of words to use in the model
max_words = 100000
# Create a tokenizer to tokenize the text data
tokenizer = Tokenizer(num_words=max_words)
tokenizer.fit_on_texts(texts)
sequences = tokenizer.texts_to_sequences(texts)
# Pad the sequences to a maximum length of 1000 words
maxlen = 1000
X = pad_sequences(sequences, maxlen=maxlen)
# Load the pre-trained Word2Vec model
w2v_model = Word2Vec.load('word2vec.model')
# Create an embedding matrix from the pre-trained Word2Vec model
embedding_dim = 300
embedding_matrix = np.zeros((max_words, embedding_dim))
for word, i in tokenizer.word_index.items():
if i >= max_words:
break
if word in w2v_model.wv.vocab:
embedding_matrix[i] = w2v_model.wv[word]
# Define the model architecture
model = Sequential()
model.add(Embedding(max_words, embedding_dim, input_length=maxlen, weights=[embedding_matrix], trainable=False))
model.add(SpatialDropout1D(0.4))
model.add(Conv1D(64, 5, activation='relu'))
model.add(MaxPooling1D(pool_size=4))
model.add(Bidirectional(LSTM(128, dropout=0.2, recurrent_dropout=0.2, return_sequences=True)))
model.add(Attention())
model.add(GlobalAveragePooling1D())
model.add(Dense(8, activation='softmax'))
# Compile the model
model.compile(loss='categorical_crossentropy', optimizer=Adam(lr=0.001), metrics=['accuracy'])
# Train the model on the training data using the GPU
with tf.device('/GPU:0'):
model
import tensorflow as tf
from keras.models import Sequential
from keras.layers import Dense, Dropout, Embedding, LSTM, SpatialDropout1D, Conv1D, MaxPooling1D, Flatten, Bidirectional, Attention, GlobalAveragePooling1D
from keras.optimizers import Adam
from keras.utils import to_categorical
from keras.preprocessing.text import Tokenizer
from keras.preprocessing.sequence import pad_sequences
from gensim.models import Word2Vec
import pandas as pd
import numpy as np
from keras.callbacks import EarlyStopping
# Specify the GPU device to use
physical_devices = tf.config.list_physical_devices('GPU')
tf.config.experimental.set_memory_growth(physical_devices[0], True)
# Load the training data
train_data = pd.read_csv('train-p.csv')
# Extract the text and labels from the training data
texts = train_data['text']
labels = train_data['label']
# Convert the labels to categorical
labels_categorical = to_categorical(labels)
# Define the maximum number of words to use in the model
max_words = 100000
# Create a tokenizer to tokenize the text data
tokenizer = Tokenizer(num_words=max_words)
tokenizer.fit_on_texts(texts)
sequences = tokenizer.texts_to_sequences(texts)
# Pad the sequences to a maximum length of 1000 words
maxlen = 1000
X = pad_sequences(sequences, maxlen=maxlen)
# Load the pre-trained Word2Vec model
w2v_model = Word2Vec.load('word2vec.model')
# Create an embedding matrix from the pre-trained Word2Vec model
embedding_dim = 300
embedding_matrix = np.zeros((max_words, embedding_dim))
for word, i in tokenizer.word_index.items():
if i >= max_words:
break
if word in w2v_model.wv.vocab:
embedding_matrix[i] = w2v_model.wv[word]
# Define the model architecture
model = Sequential()
model.add(Embedding(max_words, embedding_dim, input_length=maxlen, weights=[embedding_matrix], trainable=False))
model.add(SpatialDropout1D(0.4))
model.add(Conv1D(64, 5, activation='relu'))
model.add(MaxPooling1D(pool_size=4))
model.add(Bidirectional(LSTM(128, dropout=0.2, recurrent_dropout=0.2, return_sequences=True)))
model.add(Attention())
model.add(GlobalAveragePooling1D())
model.add(Dense(8, activation='softmax'))
# Compile the model
model.compile(loss='categorical_crossentropy', optimizer=Adam(lr=0.001), metrics=['accuracy'])
# Define early stopping criteria
early_stopping = EarlyStopping(monitor='val_loss', patience=3)
# Train the model on the training data using the GPU
with tf.device('/GPU:0'):
model.fit(X, labels_categorical, batch_size=64, epochs=15, validation_split=0.2, callbacks=[early_stopping])
# Load the test data
test_data = pd.read_csv('test-p.csv')
# Extract the text from the test data
test_texts = test_data['text']
# Tokenize and pad the test data
test_sequences = tokenizer.texts_to_sequences(test_texts)
test_X = pad_sequences(test_sequences, maxlen=maxlen)
# Make predictions on the test data
with tf.device('/GPU:0'):
predictions = model.predict(test_X)
# Convert the predictions to labels
predicted_labels = np.argmax(predictions, axis=1)
# Save the predictions to a CSV file
submission = pd.DataFrame({'id