Skip to content

Commit

Permalink
Remove verbosity of training and prediction (no logging)
Browse files Browse the repository at this point in the history
Import and use metrics from Keras when compiling the model
Use model.export instead of save_model
  • Loading branch information
mostafa committed May 17, 2024
1 parent 8750a49 commit 1f73f3c
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions training/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
from tensorflow.keras.preprocessing.sequence import pad_sequences
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Embedding, LSTM, Dense
from tensorflow.keras.models import save_model
from tensorflow.keras.metrics import Accuracy, Recall, Precision, F1Score
from sklearn.model_selection import train_test_split
from sklearn.metrics import (
accuracy_score,
Expand Down Expand Up @@ -86,13 +86,22 @@
model.add(Embedding(MAX_WORDS, 128, input_length=MAX_LEN))
model.add(LSTM(64, dropout=0.2, recurrent_dropout=0.2))
model.add(Dense(1, activation="sigmoid"))
model.compile(loss="binary_crossentropy", optimizer="adam", metrics=["accuracy"])
model.compile(
loss="binary_crossentropy",
optimizer="adam",
metrics=[
Accuracy(),
Recall(),
Precision(),
F1Score(),
],
)

# Train model
model.fit(X_train, y_train, epochs=11, batch_size=32)
model.fit(X_train, y_train, epochs=11, batch_size=32, verbose=0)

# Predict test set
y_pred = model.predict(X_test)
y_pred = model.predict(X_test, verbose=0)
y_pred_classes = np.argmax(y_pred, axis=1)

# Calculate model performance indicators
Expand All @@ -111,4 +120,4 @@
print("ROC: {:.2f}%".format(tp / (tp + fn) * 100))

# Save model as SavedModel format
save_model(model, sys.argv[2])
model.export(sys.argv[2])

0 comments on commit 1f73f3c

Please sign in to comment.