Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Projet Bachelor
Manage
Activity
Members
Plan
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
projet_2024
Projet Bachelor
Commits
d54f68da
Commit
d54f68da
authored
9 months ago
by
lucien.noel
Browse files
Options
Downloads
Plain Diff
merge
parents
02d4e0c4
4409bf57
Branches
Branches containing commit
No related tags found
Loading
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
main.py
+3
-1
3 additions, 1 deletion
main.py
musicgenerator.py
+7
-1
7 additions, 1 deletion
musicgenerator.py
with
10 additions
and
2 deletions
main.py
+
3
−
1
View file @
d54f68da
...
...
@@ -25,7 +25,7 @@ if __name__ == '__main__':
dropout
=
0.2
epochs
=
100
nb_log_epoch
=
5
nb_words
=
2
00
nb_words
=
1
00
temperature
=
1.0
print
(
"
device :
"
,
device
)
...
...
@@ -35,6 +35,7 @@ if __name__ == '__main__':
###############################################################################
corpus
=
data
.
Corpus
(
data_path
,
model_path
is
not
None
,
split_train_test_valid
)
train_data
=
data
.
batchify
(
corpus
.
train
,
batch_size
,
device
)
test_data
=
data
.
batchify
(
corpus
.
test
,
batch_size
,
device
)
val_data
=
data
.
batchify
(
corpus
.
valid
,
batch_size
,
device
)
###############################################################################
...
...
@@ -58,6 +59,7 @@ if __name__ == '__main__':
criterion
=
criterion
,
ntokens
=
ntokens
,
train_data
=
train_data
,
test_data
=
test_data
,
val_data
=
val_data
,
sequence_length
=
sequence_length
,
lr
=
learning_rate
,
...
...
This diff is collapsed.
Click to expand it.
musicgenerator.py
+
7
−
1
View file @
d54f68da
...
...
@@ -94,6 +94,7 @@ def train(model: MusicGenerator,
criterion
:
nn
.
NLLLoss
,
ntokens
:
int
,
train_data
:
torch
.
Tensor
,
test_data
:
torch
.
Tensor
,
val_data
:
torch
.
Tensor
,
sequence_length
:
int
,
lr
:
float
,
...
...
@@ -123,6 +124,12 @@ def train(model: MusicGenerator,
else
:
# Anneal the learning rate if no improvement has been seen in the validation dataset.
lr
/=
4.0
test_loss
=
evaluate
(
model
,
criterion
,
test_data
,
ntokens
,
sequence_length
)
print
(
'
=
'
*
89
)
print
(
'
| End of training | test loss {:5.2f} | test ppl {:8.2f}
'
.
format
(
test_loss
,
math
.
exp
(
test_loss
)))
print
(
'
=
'
*
89
)
except
KeyboardInterrupt
:
print
(
'
-
'
*
89
)
...
...
@@ -152,7 +159,6 @@ def __train(model: MusicGenerator,
loss
=
criterion
(
output
,
targets
)
loss
.
backward
()
# `clip_grad_norm` helps prevent the exploding gradient problem in RNNs / LSTMs.
clip
=
0.25
torch
.
nn
.
utils
.
clip_grad_norm_
(
model
.
parameters
(),
clip
)
for
p
in
model
.
parameters
():
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment