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
d83d2957
Unverified
Commit
d83d2957
authored
Sep 27, 2019
by
Thomas Wolf
Committed by
GitHub
Sep 27, 2019
Browse files
Merge pull request #1337 from mgrankin/fastdataset
faster dataset building
parents
f6de0003
f71a4577
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
2 additions
and
3 deletions
+2
-3
examples/run_lm_finetuning.py
examples/run_lm_finetuning.py
+2
-3
No files found.
examples/run_lm_finetuning.py
View file @
d83d2957
...
...
@@ -74,9 +74,8 @@ class TextDataset(Dataset):
tokenized_text
=
tokenizer
.
convert_tokens_to_ids
(
tokenizer
.
tokenize
(
text
))
while
len
(
tokenized_text
)
>=
block_size
:
# Truncate in block of block_size
self
.
examples
.
append
(
tokenizer
.
add_special_tokens_single_sequence
(
tokenized_text
[:
block_size
]))
tokenized_text
=
tokenized_text
[
block_size
:]
for
i
in
range
(
0
,
len
(
tokenized_text
)
-
block_size
+
1
,
block_size
):
# Truncate in block of block_size
self
.
examples
.
append
(
tokenizer
.
add_special_tokens_single_sentence
(
tokenized_text
[
i
:
i
+
block_size
]))
# 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
# 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