Created
December 4, 2020 13:43
-
-
Save Sirsirious/d62e119c38ca92ee7de9f262eaf523dc 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
from trax.supervised import training | |
import os | |
# Training task. | |
train_task = training.TrainTask( | |
labeled_data=train_batches_stream, | |
loss_layer=tl.CrossEntropyLoss(), | |
optimizer=trax.optimizers.Adam(0.01), | |
n_steps_per_checkpoint=200, #This will print the results at every 200 training steps. | |
) | |
# Evaluaton task. | |
eval_task = training.EvalTask( | |
labeled_data=eval_batches_stream, | |
metrics=[tl.CrossEntropyLoss(), tl.Accuracy()], | |
n_eval_batches=20 | |
) | |
# This is to set the checkpoints dir. We use a default colab dir, which is in /root/output_dir/. | |
# The model will be saved as model.pkl.gz | |
output_dir = os.path.expanduser('~/output_dir/') | |
!rm -rf {output_dir} | |
training_loop = training.Loop(sentiment_analysis_model, | |
train_task, | |
eval_tasks=[eval_task], | |
output_dir=output_dir) | |
# Run 2000 steps (batches). | |
training_loop.run(2000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment