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
OpenDAS
Fairseq
Commits
a7d0bd0e
Commit
a7d0bd0e
authored
Jul 02, 2018
by
alexeib
Committed by
Myle Ott
Jul 25, 2018
Browse files
fix token block rotation
parent
0e9e7f7b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
5 deletions
+9
-5
fairseq/data/token_block_dataset.py
fairseq/data/token_block_dataset.py
+9
-5
No files found.
fairseq/data/token_block_dataset.py
View file @
a7d0bd0e
...
@@ -76,14 +76,18 @@ class TokenBlockDataset(torch.utils.data.Dataset):
...
@@ -76,14 +76,18 @@ class TokenBlockDataset(torch.utils.data.Dataset):
def
__getitem__
(
self
,
index
):
def
__getitem__
(
self
,
index
):
s
,
e
=
self
.
slice_indices
[
index
]
s
,
e
=
self
.
slice_indices
[
index
]
item
=
torch
.
LongTensor
(
self
.
tokens
[
s
:
e
])
item
=
torch
.
LongTensor
(
self
.
tokens
[
s
:
e
])
if
self
.
include_targets
:
if
self
.
include_targets
:
if
e
==
self
.
total_size
:
# target is the sentence, for source, rotate item one token to the left (would start with eos)
return
item
[:
-
1
],
item
[
1
:]
if
s
==
0
:
source
=
np
.
concatenate
([
self
.
tokens
[
-
1
:],
self
.
tokens
[
0
:
e
-
1
]])
else
:
else
:
return
item
,
torch
.
LongTensor
(
self
.
tokens
[
s
+
1
:
e
+
1
])
source
=
self
.
tokens
[
s
-
1
:
e
-
1
]
else
:
return
item
return
torch
.
LongTensor
(
source
),
item
return
item
def
__len__
(
self
):
def
__len__
(
self
):
return
len
(
self
.
slice_indices
)
return
len
(
self
.
slice_indices
)
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