Skip to content
This repository was archived by the owner on Dec 16, 2022. It is now read-only.

Commit eee15ca

Browse files
author
Pengcheng YIN
authored
Assign an empty mapping array to empty fields of NamespaceSwappingField (#4403)
1 parent aa2943e commit eee15ca

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515
- Fixed a bug with the sharded dataset reader where it would only read a fraction of the instances
1616
in distributed training.
1717
- Fixed checking equality of `ArrayField`s.
18+
- Fixed a bug where `NamespaceSwappingField` did not work correctly with `.empty_field()`.
1819

1920
### Added
2021

allennlp/data/fields/namespace_swapping_field.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ def as_tensor(self, padding_lengths: Dict[str, int]) -> torch.Tensor:
4949

5050
@overrides
5151
def empty_field(self) -> "NamespaceSwappingField":
52-
return NamespaceSwappingField([], self._target_namespace)
52+
empty_field = NamespaceSwappingField([], self._target_namespace)
53+
empty_field._mapping_array = []
54+
55+
return empty_field
5356

5457
def __len__(self):
5558
return len(self._source_tokens)

0 commit comments

Comments
 (0)