Code callbacks and optional console output suppression while training #160
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I'm hoping to work on a GUI frontend app that will make using aitextgen more accessible, but I realized that to do that it would need to be able to interface more closely with aitextgen itself. To be able to accomplish this, I've started working on adding support for custom callbacks/hooks in aitextgen. This pull request adds some basic support for callbacks/hooks while training with
train()
, as well as options for suppressing some of the default console output.Custom callbacks
The user can pass a dictionary into the
train()
function as the argumentcallbacks
with lambdas or functions corresponding to the following keys:on_train_start()
: called when training beginson_train_end()
: called when training endson_batch_end(current_steps: int, total_steps: int, current_loss: int, avg_loss: int)
: called when a batch is completed, and passes the current and total steps along with the current and average loss to the functionon_sample_text_generated(texts: List[str])
: called when sample texts are generated, and passes the List of sample texts to the functionon_model_saved(current_steps: int, total_steps: int, output_dir: str)
: called when the model is saved during training, and passes the current and total steps along with the output directory to the functionSuppressing console output
If set to
False
, theprint_generated
andprint_saved
arguments fortrain()
will prevent generated text and "saving model" messages from being displayed in the console, respectively.Example script
I modified the Hello World Tutorial from the aitextgen website to test this functionality:
Once it got past setup, the output was: