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
2d042274
"...composable_kernel.git" did not exist on "e83439adaac50558e86873de520ea5b27224438c"
Commit
2d042274
authored
Aug 20, 2019
by
Lysandre
Browse files
Sequence special token handling for BERT and RoBERTa
parent
a690edab
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
2 deletions
+8
-2
examples/run_lm_finetuning.py
examples/run_lm_finetuning.py
+8
-2
No files found.
examples/run_lm_finetuning.py
View file @
2d042274
...
@@ -71,9 +71,15 @@ class TextDataset(Dataset):
...
@@ -71,9 +71,15 @@ class TextDataset(Dataset):
text
=
f
.
read
()
text
=
f
.
read
()
tokenized_text
=
tokenizer
.
convert_tokens_to_ids
(
tokenizer
.
tokenize
(
text
))
tokenized_text
=
tokenizer
.
convert_tokens_to_ids
(
tokenizer
.
tokenize
(
text
))
tokenized_text
=
tokenizer
.
add_special_tokens_single_sentence
(
tokenized_text
)
while
len
(
tokenized_text
)
>=
block_size
:
# Truncate in block of block_size
while
len
(
tokenized_text
)
>=
block_size
:
# Truncate in block of block_size
self
.
examples
.
append
(
tokenized_text
[:
block_size
])
if
isinstance
(
tokenizer
,
(
BertTokenizer
,
RobertaTokenizer
)):
tokenized_text
=
tokenized_text
[
block_size
:]
self
.
examples
.
append
(
tokenizer
.
add_special_tokens_single_sentence
(
tokenized_text
[:
block_size
-
2
]))
tokenized_text
=
tokenized_text
[
block_size
-
2
:]
else
:
self
.
examples
.
append
(
tokenized_text
[:
block_size
])
tokenized_text
=
tokenized_text
[
block_size
:]
# Note that we are loosing the last truncated example here for the sake of simplicity (no padding)
# Note that we are loosing the last truncated example here for the sake of simplicity (no padding)
# If your dataset is small, first you should loook for a bigger one :-) and second you
# If your dataset is small, first you should loook for a bigger one :-) and second you
# can change this behavior by adding (model specific) padding.
# can change this behavior by adding (model specific) padding.
...
...
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