Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
transformers
Commits
c3527cfb
"vscode:/vscode.git/clone" did not exist on "3d291dea4acd0be1bd2f993a3b1cf8a9f971f3a1"
Commit
c3527cfb
authored
Nov 05, 2018
by
thomwolf
Browse files
ignore SQuAD targets outside of seq_length
parent
1b99cdf7
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
2 deletions
+8
-2
modeling.py
modeling.py
+8
-2
No files found.
modeling.py
View file @
c3527cfb
...
...
@@ -455,9 +455,15 @@ class BertForQuestionAnswering(nn.Module):
end_logits
=
end_logits
.
squeeze
(
-
1
)
if
start_positions
is
not
None
and
end_positions
is
not
None
:
start_positions
=
start_positions
.
squeeze
(
-
1
)
# If we are on multi-GPU, split add a dimension
# If we are on multi-GPU, split add a dimension - if not this is a no-op
start_positions
=
start_positions
.
squeeze
(
-
1
)
end_positions
=
end_positions
.
squeeze
(
-
1
)
loss_fct
=
CrossEntropyLoss
()
# sometimes the start/end positions are outside our model inputs, we ignore these terms
ignored_index
=
start_logits
.
size
(
1
)
+
1
start_positions
.
clamp_
(
0
,
ignored_index
)
end_positions
.
clamp_
(
0
,
ignored_index
)
loss_fct
=
CrossEntropyLoss
(
ignore_index
=
ignored_index
)
start_loss
=
loss_fct
(
start_logits
,
start_positions
)
end_loss
=
loss_fct
(
end_logits
,
end_positions
)
total_loss
=
(
start_loss
+
end_loss
)
/
2
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment