import tensorflow as tf
# IMDB
(x_train, y_train), (x_test, y_test) = tf.keras.datasets.imdb.load_data()
print(x_train.shape, y_train.shape)
# (25000,), (25000,)
x_train = tf.keras.utils.pad_sequences(x_train, maxlen=20)
x_test = tf.keras.utils.pad_sequences(x_test, maxlen=20)
print(x_train.shape, y_train.shape)
# (25000, 20), (25000,)
X = tf.keras.Input(shape=[20])
H = tf.keras.layers.Embedding(88585, 28)(X)
H = tf.keras.layers.SimpleRNN(32, return_sequences=True)(H)
# Transformer::self-attentions
H1 = tf.keras.layers.MultiHeadAttention(2, 32)(H, H)
H = tf.keras.layers.BatchNormalization()(H + H1)
# Transformer::feed-forward
H1 = tf.keras.layers.Dense(32, activation='swish')(H)
H = tf.keras.layers.BatchNormalization()(H + H1)
H = tf.keras.layers.GlobalAveragePooling1D()(H)
Y = tf.keras.layers.Dense(1, activation="sigmoid")(H)
model = tf.keras.Model(X, Y)
model.compile(loss="binary_crossentropy", metrics="accuracy")










MultiHeadAttention(1, 2)(Q, K, V)

