Skip to content

Instantly share code, notes, and snippets.

@firobeid
Created August 16, 2022 01:10
Show Gist options
  • Select an option

  • Save firobeid/712b2b950ac2e3f89a8829015f07151d to your computer and use it in GitHub Desktop.

Select an option

Save firobeid/712b2b950ac2e3f89a8829015f07151d to your computer and use it in GitHub Desktop.
def direction_model():
model = Sequential(name = 'RNNStocks')
model.add(Embedding(input_dim = 185, output_dim = 256,batch_input_shape=[None, None],
mask_zero = True, name ='EmbedLayer'))
model.add(Bidirectional(LSTM(1024,
return_sequences=False,stateful=False,
recurrent_initializer='glorot_uniform'), merge_mode ='concat',name = 'BiLSTM'))
#final state encodes full representation of a single passed headine
model.add(BatchNormalization(name='BatchNormal')) #After RNN(S-shape activation-f(x) / Before ReLU(Non-Gaussian))
# model.add(tf.keras.layers.Masking(mask_value=0))
model.add(Dense(512, name = 'FullConnected', kernel_initializer='he_normal'))
model.add(tf.keras.layers.LeakyReLU()) #controls vanishing gradients:f(x) = a * (exp(x) - 1.) for x < 0 ; f(x) = x for x >= 0
model.add(BatchNormalization(name='BatchNormal2'))
model.add(Dense(1, activation='sigmoid',name='Output'))
model.compile(optimizer=tf.optimizers.Adadelta(learning_rate = 1e-04), loss=tf.keras.losses.BinaryCrossentropy(from_logits=True),
metrics=['accuracy', tf.keras.metrics.AUC(name='AUC')])
return model
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment