Created
November 6, 2022 13:55
-
-
Save rdisipio/a4103e968b43fa26aec41ba20390c2df to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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