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
e6a710f6
Commit
e6a710f6
authored
Nov 02, 2018
by
VictorSanh
Browse files
device
parent
3ebf1a13
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
1 addition
and
1 deletion
+1
-1
modeling_pytorch.py
modeling_pytorch.py
+1
-1
No files found.
modeling_pytorch.py
View file @
e6a710f6
...
@@ -492,7 +492,7 @@ class BertForQuestionAnswering(nn.Module):
...
@@ -492,7 +492,7 @@ class BertForQuestionAnswering(nn.Module):
def
compute_loss
(
logits
,
positions
):
def
compute_loss
(
logits
,
positions
):
max_position
=
positions
.
max
().
item
()
max_position
=
positions
.
max
().
item
()
one_hot
=
torch
.
FloatTensor
(
batch_size
,
max
(
max_position
,
seq_length
)
+
1
).
zero_
()
one_hot
=
torch
.
FloatTensor
(
batch_size
,
max
(
max_position
,
seq_length
)
+
1
,
device
=
input_ids
.
device
).
zero_
()
one_hot
=
one_hot
.
scatter
(
1
,
positions
,
1
)
one_hot
=
one_hot
.
scatter
(
1
,
positions
,
1
)
one_hot
=
one_hot
[:,
:
seq_length
]
one_hot
=
one_hot
[:,
:
seq_length
]
log_probs
=
nn
.
functional
.
log_softmax
(
logits
,
dim
=
-
1
).
view
(
batch_size
,
seq_length
)
log_probs
=
nn
.
functional
.
log_softmax
(
logits
,
dim
=
-
1
).
view
(
batch_size
,
seq_length
)
...
...
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