Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
chenpangpang
transformers
Commits
e8fe6b71
Commit
e8fe6b71
authored
Feb 11, 2019
by
thomwolf
Browse files
adapting transfo tokenizer to transposed inputs
parent
884ca81d
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
4 deletions
+7
-4
pytorch_pretrained_bert/tokenization_transfo_xl.py
pytorch_pretrained_bert/tokenization_transfo_xl.py
+7
-4
No files found.
pytorch_pretrained_bert/tokenization_transfo_xl.py
View file @
e8fe6b71
...
@@ -356,7 +356,10 @@ class LMOrderedIterator(object):
...
@@ -356,7 +356,10 @@ class LMOrderedIterator(object):
data
=
self
.
data
[
beg_idx
:
end_idx
]
data
=
self
.
data
[
beg_idx
:
end_idx
]
target
=
self
.
data
[
i
+
1
:
i
+
1
+
seq_len
]
target
=
self
.
data
[
i
+
1
:
i
+
1
+
seq_len
]
return
data
,
target
,
seq_len
data_out
=
data
.
transpose
(
0
,
1
).
contiguous
().
to
(
self
.
device
)
target_out
=
target
.
transpose
(
0
,
1
).
contiguous
().
to
(
self
.
device
)
return
data_out
,
target_out
,
seq_len
def
get_fixlen_iter
(
self
,
start
=
0
):
def
get_fixlen_iter
(
self
,
start
=
0
):
for
i
in
range
(
start
,
self
.
data
.
size
(
0
)
-
1
,
self
.
bptt
):
for
i
in
range
(
start
,
self
.
data
.
size
(
0
)
-
1
,
self
.
bptt
):
...
@@ -440,10 +443,10 @@ class LMShuffledIterator(object):
...
@@ -440,10 +443,10 @@ class LMShuffledIterator(object):
if
not
valid_batch
:
if
not
valid_batch
:
return
return
data
=
data
.
to
(
self
.
device
)
data
_out
=
data
.
transpose
(
0
,
1
).
contiguous
().
to
(
self
.
device
)
target
=
target
.
to
(
self
.
device
)
target
_out
=
target
.
transpose
(
0
,
1
).
contiguous
().
to
(
self
.
device
)
yield
data
,
target
,
self
.
bptt
yield
data
_out
,
target
_out
,
self
.
bptt
n_retain
=
min
(
data
.
size
(
0
),
self
.
ext_len
)
n_retain
=
min
(
data
.
size
(
0
),
self
.
ext_len
)
if
n_retain
>
0
:
if
n_retain
>
0
:
...
...
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