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
4dd5cf22
Unverified
Commit
4dd5cf22
authored
Jun 05, 2020
by
Sylvain Gugger
Committed by
GitHub
Jun 05, 2020
Browse files
Fix argument label (#4792)
* Fix argument label * Fix test
parent
3723f30a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
3 additions
and
3 deletions
+3
-3
src/transformers/data/data_collator.py
src/transformers/data/data_collator.py
+1
-1
tests/test_trainer.py
tests/test_trainer.py
+2
-2
No files found.
src/transformers/data/data_collator.py
View file @
4dd5cf22
...
@@ -91,7 +91,7 @@ class DataCollatorForLanguageModeling(DataCollator):
...
@@ -91,7 +91,7 @@ class DataCollatorForLanguageModeling(DataCollator):
batch
=
self
.
_tensorize_batch
(
examples
)
batch
=
self
.
_tensorize_batch
(
examples
)
if
self
.
mlm
:
if
self
.
mlm
:
inputs
,
labels
=
self
.
mask_tokens
(
batch
)
inputs
,
labels
=
self
.
mask_tokens
(
batch
)
return
{
"input_ids"
:
inputs
,
"
masked_lm_
labels"
:
labels
}
return
{
"input_ids"
:
inputs
,
"labels"
:
labels
}
else
:
else
:
return
{
"input_ids"
:
batch
,
"labels"
:
batch
}
return
{
"input_ids"
:
batch
,
"labels"
:
batch
}
...
...
tests/test_trainer.py
View file @
4dd5cf22
...
@@ -74,14 +74,14 @@ class DataCollatorIntegrationTest(unittest.TestCase):
...
@@ -74,14 +74,14 @@ class DataCollatorIntegrationTest(unittest.TestCase):
batch
=
data_collator
.
collate_batch
(
examples
)
batch
=
data_collator
.
collate_batch
(
examples
)
self
.
assertIsInstance
(
batch
,
dict
)
self
.
assertIsInstance
(
batch
,
dict
)
self
.
assertEqual
(
batch
[
"input_ids"
].
shape
,
torch
.
Size
((
31
,
107
)))
self
.
assertEqual
(
batch
[
"input_ids"
].
shape
,
torch
.
Size
((
31
,
107
)))
self
.
assertEqual
(
batch
[
"
masked_lm_
labels"
].
shape
,
torch
.
Size
((
31
,
107
)))
self
.
assertEqual
(
batch
[
"labels"
].
shape
,
torch
.
Size
((
31
,
107
)))
dataset
=
TextDataset
(
tokenizer
,
file_path
=
PATH_SAMPLE_TEXT
,
block_size
=
512
,
overwrite_cache
=
True
)
dataset
=
TextDataset
(
tokenizer
,
file_path
=
PATH_SAMPLE_TEXT
,
block_size
=
512
,
overwrite_cache
=
True
)
examples
=
[
dataset
[
i
]
for
i
in
range
(
len
(
dataset
))]
examples
=
[
dataset
[
i
]
for
i
in
range
(
len
(
dataset
))]
batch
=
data_collator
.
collate_batch
(
examples
)
batch
=
data_collator
.
collate_batch
(
examples
)
self
.
assertIsInstance
(
batch
,
dict
)
self
.
assertIsInstance
(
batch
,
dict
)
self
.
assertEqual
(
batch
[
"input_ids"
].
shape
,
torch
.
Size
((
2
,
512
)))
self
.
assertEqual
(
batch
[
"input_ids"
].
shape
,
torch
.
Size
((
2
,
512
)))
self
.
assertEqual
(
batch
[
"
masked_lm_
labels"
].
shape
,
torch
.
Size
((
2
,
512
)))
self
.
assertEqual
(
batch
[
"labels"
].
shape
,
torch
.
Size
((
2
,
512
)))
@
require_torch
@
require_torch
...
...
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