Skip to content

Commit

Permalink
add report codes
Browse files Browse the repository at this point in the history
  • Loading branch information
hyunwoongko committed Dec 18, 2019
1 parent 09c74b8 commit ef96e13
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 2 deletions.
6 changes: 4 additions & 2 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified __pycache__/train.cpython-36.pyc
Binary file not shown.
Binary file not shown.
5 changes: 5 additions & 0 deletions result/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"""
@author : Hyunwoong
@when : 2019-12-18
@homepage : https://github.com/gusdnd852
"""
11 changes: 11 additions & 0 deletions train.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,29 @@ def evaluate(model, iterator, criterion):


def run(total_epoch, best_loss):
train_losses, test_losses = [], []
for step in range(total_epoch):
start_time = time.time()
train_loss = train(model, train_iter, optimizer, criterion, clip)
valid_loss = evaluate(model, valid_iter, criterion)
end_time = time.time()

train_losses.append(train_loss)
test_losses.append(valid_loss)
epoch_mins, epoch_secs = epoch_time(start_time, end_time)

if valid_loss < best_loss:
best_loss = valid_loss
torch.save(model.state_dict(), 'saved/model-{0}.pt'.format(valid_loss))

f = open('result/train.txt', 'w')
f.write(str(train_losses))
f.close()

f = open('result/test.txt', 'w')
f.write(str(test_losses))
f.close()

print(f'Epoch: {step + 1} | Time: {epoch_mins}m {epoch_secs}s')
print(f'\tTrain Loss: {train_loss:.3f} | Train PPL: {math.exp(train_loss):7.3f}')
print(f'\t Val. Loss: {valid_loss:.3f} | Val. PPL: {math.exp(valid_loss):7.3f}')

0 comments on commit ef96e13

Please sign in to comment.