from keras.layers import Dense, Flatten from keras.layers import Conv2D, MaxPooling2D, Input from keras.models import Model # Define input shape input_shape = (28, 28, 1) # Define input layer input_layer = Input(shape=input_shape) # Define convolutional layers conv1 = Conv2D(32, kernel_size=(3, 3), activation='relu')(input_layer) conv2 = Conv2D(64, kernel_size=(3, 3), activation='relu')(conv1) # Define pooling layer pooling = MaxPooling2D(pool_size=(2, 2))(conv2) # Flatten output of pooling layer flatten = Flatten()(pooling) # Define output layer output_layer = Dense(1, activation='sigmoid')(flatten) # Define model with input and output layers model = Model(inputs=input_layer, outputs=output_layer)
from keras.layers import Dense, Embedding, LSTM, Input from keras.models import Model # Define input shape input_shape = (None,) # Define input layer input_layer = Input(shape=input_shape) # Define embedding layer embedding_layer = Embedding(input_dim=max_features, output_dim=embedding_dim, input_length=maxlen)(input_layer) # Define LSTM layer lstm_layer = LSTM(128)(embedding_layer) # Define output layer output_layer = Dense(1, activation='sigmoid')(lstm_layer) # Define model with input and output layers model = Model(inputs=input_layer, outputs=output_layer)The package library used in these examples is Keras.