Skip to content

Instantly share code, notes, and snippets.

@rdisipio
Created November 6, 2022 13:55
Show Gist options
  • Save rdisipio/a4103e968b43fa26aec41ba20390c2df to your computer and use it in GitHub Desktop.
Save rdisipio/a4103e968b43fa26aec41ba20390c2df to your computer and use it in GitHub Desktop.
embed_dim = 16
batch_size = 32
n_epochs = 20
import tensorflow as tf
from tensorflow.keras.layers import Conv1D, Flatten, Dense, Dropout
model2 = tf.keras.models.Sequential([
QuantizedFeaturesEmbedding(n_features, n_bins, embed_dim),
Dropout(0.2),
Conv1D(filters=1, kernel_size=3),
Flatten(),
Dense(2, activation='softmax')
])
loss2 = tf.keras.losses.BinaryCrossentropy(from_logits=False)
metrics2 = [tf.keras.metrics.BinaryAccuracy()]
model2.compile(optimizer='adam',
loss=loss2,
metrics=metrics2)
model2(X_qt[:batch_size]) # build the model, inputs are int32
X_train = tf.data.Dataset.from_tensor_slices(X_train)
y_train = tf.data.Dataset.from_tensor_slices(y_train)
X_test = tf.data.Dataset.from_tensor_slices(X_test)
y_test = tf.data.Dataset.from_tensor_slices(y_test)
ds_train = tf.data.Dataset.zip((X_train, y_train)).shuffle(buffer_size=1024).batch(batch_size=batch_size, drop_remainder=True)
ds_test = tf.data.Dataset.zip((X_test, y_test)).batch(batch_size=batch_size, drop_remainder=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment