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
f54a5bd3
Commit
f54a5bd3
authored
Feb 10, 2020
by
Lysandre
Committed by
Julien Chaumond
Feb 12, 2020
Browse files
Raise error when using an mlm flag for a clm model + correct TextDataset
parent
569897ce
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
0 deletions
+9
-0
examples/run_language_modeling.py
examples/run_language_modeling.py
+9
-0
No files found.
examples/run_language_modeling.py
View file @
f54a5bd3
...
@@ -86,6 +86,9 @@ MODEL_CLASSES = {
...
@@ -86,6 +86,9 @@ MODEL_CLASSES = {
class
TextDataset
(
Dataset
):
class
TextDataset
(
Dataset
):
def
__init__
(
self
,
tokenizer
:
PreTrainedTokenizer
,
args
,
file_path
:
str
,
block_size
=
512
):
def
__init__
(
self
,
tokenizer
:
PreTrainedTokenizer
,
args
,
file_path
:
str
,
block_size
=
512
):
assert
os
.
path
.
isfile
(
file_path
)
assert
os
.
path
.
isfile
(
file_path
)
block_size
=
block_size
-
(
tokenizer
.
max_len
-
tokenizer
.
max_len_single_sentence
)
directory
,
filename
=
os
.
path
.
split
(
file_path
)
directory
,
filename
=
os
.
path
.
split
(
file_path
)
cached_features_file
=
os
.
path
.
join
(
cached_features_file
=
os
.
path
.
join
(
directory
,
args
.
model_type
+
"_cached_lm_"
+
str
(
block_size
)
+
"_"
+
filename
directory
,
args
.
model_type
+
"_cached_lm_"
+
str
(
block_size
)
+
"_"
+
filename
...
@@ -195,6 +198,12 @@ def _rotate_checkpoints(args, checkpoint_prefix="checkpoint", use_mtime=False) -
...
@@ -195,6 +198,12 @@ def _rotate_checkpoints(args, checkpoint_prefix="checkpoint", use_mtime=False) -
def
mask_tokens
(
inputs
:
torch
.
Tensor
,
tokenizer
:
PreTrainedTokenizer
,
args
)
->
Tuple
[
torch
.
Tensor
,
torch
.
Tensor
]:
def
mask_tokens
(
inputs
:
torch
.
Tensor
,
tokenizer
:
PreTrainedTokenizer
,
args
)
->
Tuple
[
torch
.
Tensor
,
torch
.
Tensor
]:
""" Prepare masked tokens inputs/labels for masked language modeling: 80% MASK, 10% random, 10% original. """
""" Prepare masked tokens inputs/labels for masked language modeling: 80% MASK, 10% random, 10% original. """
if
tokenizer
.
mask_token
is
None
:
raise
ValueError
(
"This tokenizer does not have a mask token which is necessary for masked language modeling. Remove the --mlm flag if you want to use this tokenizer."
)
labels
=
inputs
.
clone
()
labels
=
inputs
.
clone
()
# We sample a few tokens in each sequence for masked-LM training (with probability args.mlm_probability defaults to 0.15 in Bert/RoBERTa)
# We sample a few tokens in each sequence for masked-LM training (with probability args.mlm_probability defaults to 0.15 in Bert/RoBERTa)
probability_matrix
=
torch
.
full
(
labels
.
shape
,
args
.
mlm_probability
)
probability_matrix
=
torch
.
full
(
labels
.
shape
,
args
.
mlm_probability
)
...
...
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