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

Track_Loss_In_Learner_File #77

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project uses [Semantic Versioning](http://semver.org/).

# [3.2.1] - 2022-12-19
### Added
- Return a dictionary of epoch numbers and corresponding losses to better automatically track training

# [3.2.0] - 2022-03-08
### Added
- Added an `import_model` method to the class BertForMultiTaskClassification in multi_task_bert.py that allows a file that was created with `export` to be easily imported
Expand Down
2 changes: 1 addition & 1 deletion octopod/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '3.2.0'
__version__ = '3.2.1'
6 changes: 6 additions & 0 deletions octopod/learner.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ def fit(

self.model = self.model.to(device)

training_record = {}

current_best_loss = np.iinfo(np.intp).max

pbar = master_bar(range(num_epochs))
Expand Down Expand Up @@ -151,6 +153,8 @@ def fit(

current_loss = self.loss_function_dict[task_type](output[task_type], y)

training_record[epoch] = current_loss

optimizer.zero_grad()
current_loss.backward()
optimizer.step()
Expand Down Expand Up @@ -202,6 +206,8 @@ def fit(
self.model.load_state_dict(best_model_wts)
print(f'Epoch {best_model_epoch} best model saved with loss of {current_best_loss}')

return training_record

def _calculate_overall_loss(self):
return sum(self.smooth_training_loss_dict.values()) / len(self.smooth_training_loss_dict)

Expand Down