Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Customizable loss history for approximator #217

Open
jerrymhuang opened this issue Oct 15, 2024 · 0 comments
Open

Customizable loss history for approximator #217

jerrymhuang opened this issue Oct 15, 2024 · 0 comments
Assignees
Labels
feature New feature or request

Comments

@jerrymhuang
Copy link
Collaborator

Currently, the approximator only stores one set of losses for each training epoch. One has to implement and explicitly call a custom callback (based on Keras' base Callback class) in order to visualize the finer-grained loss trajectory across more training steps.

Here is an example of such workaround implementation where the loss function is recorded across all training steps:

class DetailedLossTrajectory(keras.callbacks.Callback):
    def __init__(self):
        super().__init__()
        self.training_losses = []
        self.validation_losses = []

    def on_train_batch_end(self, batch, logs=None):
        # 'logs' is a dictionary containing loss and other metrics
        training_loss = logs.get('loss')
        self.training_losses.append(training_loss)
        
    def on_test_batch_end(self, batch, logs=None):
        validation_loss = logs.get('loss')
        self.validation_losses.append(validation_loss)

It needs to be instantiated and called upon training:

# ...

detailed_loss = DetailedLossTrajectory()

history = approximator.fit(
    epochs=10,
    dataset=training_dataset,
    validation_data=validation_dataset,
    callbacks=[detailed_loss]
)

Ideally, we should provide an interface that allows the user to access a more detailed loss trajectory by default, and provide them the ability to control the level of detail (i.e., recording loss every n-th training steps).

@jerrymhuang jerrymhuang self-assigned this Oct 17, 2024
@paul-buerkner paul-buerkner added the feature New feature or request label Nov 21, 2024
@jerrymhuang jerrymhuang moved this from Future to Todo in bayesflow development Dec 2, 2024
@jerrymhuang jerrymhuang moved this from Todo to In Progress in bayesflow development Dec 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
Status: In Progress
Development

No branches or pull requests

2 participants