Skip to content

Instantly share code, notes, and snippets.

@vu-minh
vu-minh / text-processing.md
Last active September 28, 2021 21:19
Basic text processing with keras

Text processing using TF2 + keras

Summary notebook

Tokenizer:

  • tensorflow.keras.preprocessing.text.Tokenizer
    • limit vocabulary size with num_words=1000
    • deal with out of vocab: oov_token="<OOV>"
    • .fit_on_texts(input_texts)
  • can get the vocabulary (as a dict) by .word_index property
@vu-minh
vu-minh / dl-recipes.md
Last active September 28, 2021 15:10
DL models Recipes

Loss function

Binary Cross-Entropy

Using keras' binary_crossentropy for binary classification problems. Note to encode the class labels accordingly.

  • Model definition:
model = tf.keras.models.Sequential([
    ...
    tf.keras.layers.Dense(512, activation='relu'),
@vu-minh
vu-minh / keras-callback.py
Last active September 28, 2021 09:34
Simple keras Callback
class myCallback(tf.keras.callbacks.Callback):
def on_epoch_end(self, epoch, logs={}):
if logs.get('accuracy')>0.99:
print("\nReached 99% accuracy so cancelling training!")
self.model.stop_training = True