Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
srush committed Sep 3, 2019
1 parent 970c3e1 commit eea389c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions torch_struct/data/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ def SubTokenizedField(tokenizer):
FIELD.is_target = False
return FIELD

def TokenBucket(train):
def TokenBucket(train, batch_size):
def batch_size_fn(x, _, size):
return size + max(len(x.word[0]), 5)
return torchtext.data.BucketIterator(train,
train=True,
sort=False,
sort_within_batch=True,
shuffle=True,
batch_size=1500,
batch_size=batch_size,
sort_key=lambda x: len(x.word[0]),
repeat=True,
batch_size_fn=batch_size_fn,
Expand Down
4 changes: 2 additions & 2 deletions torch_struct/deptree.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ def deptree_fromseq(sequence, lengths=None):
if lengths is None:
lengths = torch.LongTensor([N] * batch)
labels = torch.zeros(batch, N + 1, N + 1).long()
for n in range(1, N):
labels[torch.arange(batch), sequence[:, n], n] = 1
for n in range(1, N+1):
labels[torch.arange(batch), sequence[:, n-1], n] = 1
for b in range(batch):
labels[b, lengths[b]+1:, :] = 0
labels[b, :, lengths[b]+1:] = 0
Expand Down

0 comments on commit eea389c

Please sign in to comment.