Skip to content

Commit 396568c

Browse files
committed
Give PadSequenceDataLoader the option to skip padding
1 parent 5317922 commit 396568c

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

hanlp/common/dataset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ def tensorize(raw_batch: Dict[str, Any], vocabs: VocabDict, pad_dict: Dict[str,
439439
if vocab:
440440
pad = vocab.safe_pad_token_idx
441441
dtype = torch.long
442-
elif pad_dict is not None and field in pad_dict:
442+
elif pad_dict is not None and pad_dict.get(field, None) is not None:
443443
pad = pad_dict[field]
444444
dtype = dtype_of(pad)
445445
elif field.endswith('_offset') or field.endswith('_id') or field.endswith(

0 commit comments

Comments
 (0)