Created
February 2, 2021 08:01
-
-
Save RayWilliam46/9beb3d93a76f96693aa83c718d3561f8 to your computer and use it in GitHub Desktop.
Unfreeze DistilBERT embedding layer and train all weights
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
FT_EPOCHS = 4 | |
BATCH_SIZE = 64 | |
NUM_STEPS = len(X_train.index) | |
# Unfreeze distilBERT layers and make available for training | |
for layer in distilBERT.layers: | |
layer.trainable = True | |
# Recompile model after unfreezing | |
model.compile(optimizer=tf.keras.optimizers.Adam(lr=2e-5), | |
loss=focal_loss(), | |
metrics=['accuracy']) | |
# Train the model | |
train_history2 = model.fit( | |
x = [X_train_ids, X_train_attention], | |
y = y_train.to_numpy(), | |
epochs = FT_EPOCHS, | |
batch_size = BATCH_SIZE, | |
steps_per_epoch = NUM_STEPS, | |
validation_data = ([X_valid_ids, X_valid_attention], y_valid.to_numpy()), | |
verbose=2 | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment