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
babe4307
Commit
babe4307
authored
2 years ago
by
kreuzer
Browse files
Options
Downloads
Patches
Plain Diff
Aktualisieren models.py
parent
d4c8ca3d
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
+19
-11
19 additions, 11 deletions
models.py
with
19 additions
and
11 deletions
models.py
+
19
−
11
View file @
babe4307
...
...
@@ -4,6 +4,8 @@ from torch import nn
import
numpy
as
np
import
utils
#
import
sys
import
traceback
class
SummarisationModel
(
nn
.
Module
):
...
...
@@ -120,23 +122,29 @@ class ActorOnlySummarisationModel(SummarisationModel):
self
.
optimizer
.
zero_grad
()
for
datapoint
in
batch
:
# documents with empty content!
if
len
(
datapoint
.
raw_document
)
==
0
or
len
(
datapoint
.
raw_summary
)
==
0
:
print
(
"
Warning! This datapoint has an empty document or an empty summary
"
)
continue
_
,
probs
=
self
.
__call__
(
datapoint
.
document
)
try
:
# Prevent breakdown for inapt datapoints
# documents with empty content!
if
len
(
datapoint
.
raw_document
)
==
0
or
len
(
datapoint
.
raw_summary
)
==
0
:
print
(
"
Warning! This datapoint has an empty document or an empty summary
"
)
continue
o
=
datapoint
.
p_searchspace
@
torch
.
log
(
probs
)
+
datapoint
.
n_searchspace
@
torch
.
log
(
1
-
probs
)
_
,
probs
=
self
.
__call__
(
datapoint
.
document
)
idx_sampl
e
=
torch
.
argmax
(
o
)
o
=
datapoint
.
p_searchspac
e
@
torch
.
log
(
probs
)
+
datapoint
.
n_searchspace
@
torch
.
log
(
1
-
probs
)
loss
=
-
datapoint
.
top_rouge
[
idx_sample
]
*
o
[
idx_sample
]
idx_sample
=
torch
.
argmax
(
o
)
loss
.
backward
()
loss
=
-
datapoint
.
top_rouge
[
idx_sample
]
*
o
[
idx_sample
]
epoch_loss
+=
loss
.
item
()
epoch_rouge
+=
datapoint
.
top_rouge
[
idx_sample
]
loss
.
backward
()
epoch_loss
+=
loss
.
item
()
epoch_rouge
+=
datapoint
.
top_rouge
[
idx_sample
]
except
Exception
as
e
:
traceback
.
print_exception
(
*
sys
.
exc_info
())
continue
self
.
optimizer
.
step
()
...
...
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