Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
NN Projekt SS22
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Analyze
Contributor 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
kreuzer
NN Projekt SS22
Commits
0b2cb530
Commit
0b2cb530
authored
2 years ago
by
kreuzer
Browse files
Options
Downloads
Patches
Plain Diff
Aktualisieren models.py
parent
b8259f3f
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
models.py
+43
-0
43 additions, 0 deletions
models.py
with
43 additions
and
0 deletions
models.py
+
43
−
0
View file @
0b2cb530
...
...
@@ -82,6 +82,10 @@ class SummarisationModel(nn.Module):
epoch_rouge_l
=
running_rouge_l
/
len
(
dataset
)
return
epoch_rouge_1
,
epoch_rouge_2
,
epoch_rouge_l
def
validation
(
self
,
dataset
):
return
sum
(
self
.
test
(
dataset
))
/
3.0
...
...
@@ -164,6 +168,45 @@ class ActorOnlySummarisationModel(SummarisationModel):
# load best model weights
self
.
load_state_dict
(
best_model_wts
)
def
__init__
(
self
):
super
().
__init__
()
self
.
optimizer
=
torch
.
optim
.
Adam
(
self
.
parameters
(),
lr
=
0.001
)
def
epoch
(
self
,
dataloader
,
learning_rate
=
0.001
):
if
learning_rate
!=
0.001
:
self
.
optimizer
=
torch
.
optim
.
Adam
(
self
.
parameters
(),
lr
=
learning_rate
)
self
.
train
()
epoch_loss
=
0.0
epoch_rouge
=
0.0
for
batch
in
dataloader
:
self
.
optimizer
.
zero_grad
()
for
datapoint
in
batch
:
_
,
probs
=
self
.
__call__
(
datapoint
.
document
)
o
=
datapoint
.
p_searchspace
@
torch
.
log
(
probs
)
+
datapoint
.
n_searchspace
@
torch
.
log
(
1
-
probs
)
idx_sample
=
torch
.
argmax
(
o
)
loss
=
-
datapoint
.
top_rouge
[
idx_sample
]
*
o
[
idx_sample
]
loss
.
backward
()
epoch_loss
+=
loss
.
item
()
epoch_rouge
+=
datapoint
.
top_rouge
[
idx_sample
]
self
.
optimizer
.
step
()
return
epoch_loss
/
len
(
dataloader
.
dataset
),
epoch_rouge
/
len
(
dataloader
.
dataset
)
class
SummarisationModelWithCrossEntropyLoss
(
SummarisationModel
):
...
...
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