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
7da3ef24
Commit
7da3ef24
authored
Nov 12, 2019
by
Xu Hongshen
Browse files
add is_impossible tensor to model inputs during fine-tuning xlnet on squad2.0
parent
74ce8de7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
1 deletion
+4
-1
examples/run_squad.py
examples/run_squad.py
+4
-1
No files found.
examples/run_squad.py
View file @
7da3ef24
...
@@ -147,6 +147,8 @@ def train(args, train_dataset, model, tokenizer):
...
@@ -147,6 +147,8 @@ def train(args, train_dataset, model, tokenizer):
if
args
.
model_type
in
[
'xlnet'
,
'xlm'
]:
if
args
.
model_type
in
[
'xlnet'
,
'xlm'
]:
inputs
.
update
({
'cls_index'
:
batch
[
5
],
inputs
.
update
({
'cls_index'
:
batch
[
5
],
'p_mask'
:
batch
[
6
]})
'p_mask'
:
batch
[
6
]})
if
args
.
version_2_with_negative
:
inputs
.
update
({
'is_impossible'
:
batch
[
7
]})
outputs
=
model
(
**
inputs
)
outputs
=
model
(
**
inputs
)
loss
=
outputs
[
0
]
# model outputs are always tuple in transformers (see doc)
loss
=
outputs
[
0
]
# model outputs are always tuple in transformers (see doc)
...
@@ -339,9 +341,10 @@ def load_and_cache_examples(args, tokenizer, evaluate=False, output_examples=Fal
...
@@ -339,9 +341,10 @@ def load_and_cache_examples(args, tokenizer, evaluate=False, output_examples=Fal
else
:
else
:
all_start_positions
=
torch
.
tensor
([
f
.
start_position
for
f
in
features
],
dtype
=
torch
.
long
)
all_start_positions
=
torch
.
tensor
([
f
.
start_position
for
f
in
features
],
dtype
=
torch
.
long
)
all_end_positions
=
torch
.
tensor
([
f
.
end_position
for
f
in
features
],
dtype
=
torch
.
long
)
all_end_positions
=
torch
.
tensor
([
f
.
end_position
for
f
in
features
],
dtype
=
torch
.
long
)
all_is_impossible
=
torch
.
tensor
([
1.0
if
f
.
is_impossible
==
True
else
0.0
for
f
in
features
],
dtype
=
torch
.
float
)
dataset
=
TensorDataset
(
all_input_ids
,
all_input_mask
,
all_segment_ids
,
dataset
=
TensorDataset
(
all_input_ids
,
all_input_mask
,
all_segment_ids
,
all_start_positions
,
all_end_positions
,
all_start_positions
,
all_end_positions
,
all_cls_index
,
all_p_mask
)
all_cls_index
,
all_p_mask
,
all_is_impossible
)
if
output_examples
:
if
output_examples
:
return
dataset
,
examples
,
features
return
dataset
,
examples
,
features
...
...
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