This repository was archived by the owner on Dec 16, 2022. It is now read-only.
File tree 3 files changed +30
-3
lines changed
allennlp/data/dataset_readers
tests/data/dataset_readers
3 files changed +30
-3
lines changed Original file line number Diff line number Diff line change @@ -14,9 +14,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
14
14
15
15
### Fixed
16
16
17
- - Fixed issue with GradientDescentTrainer when constructed with validation_data_loader== None and learning_rate_scheduler!=None.
17
+ - Fixed issue with ` GradientDescentTrainer ` when constructed with ` validation_data_loader=None ` and ` learning_rate_scheduler!=None ` .
18
18
- Fixed a bug when removing all handlers in root logger.
19
-
19
+ - ` ShardedDatasetReader ` now inherits parameters from ` base_reader ` when required.
20
20
21
21
## [ v1.2.2] ( https://github.com/allenai/allennlp/releases/tag/v1.2.2 ) - 2020-11-17
22
22
Original file line number Diff line number Diff line change @@ -30,13 +30,23 @@ class ShardedDatasetReader(DatasetReader):
30
30
31
31
Registered as a `DatasetReader` with name "sharded".
32
32
33
+ This class accepts all additional parameters of any `DatasetReader` class via `**kwargs`.
34
+ We give priority to the values set in the constructor for the instance of this class.
35
+ Optionally, we will automatically inherit attributes from the `base_reader` when required.
36
+
33
37
# Parameters
34
38
35
39
base_reader : `DatasetReader`
36
40
Reader with a read method that accepts a single file.
37
41
"""
38
42
39
43
def __init__ (self , base_reader : DatasetReader , ** kwargs ) -> None :
44
+ # ShardedDatasetReader is a wrapper for the original base_reader so some of the parameters like 'lazy'
45
+ # can be safely inherited. However, ShardedDatasetReader is a class instance of a DatasetReader as well.
46
+ # So we give priority to the parameters for the current instance stored in 'kwargs'.
47
+ # If not present, we check the ones in the base reader
48
+ kwargs ["lazy" ] = kwargs .get ("lazy" , base_reader .lazy )
49
+
40
50
super ().__init__ (manual_distributed_sharding = True , ** kwargs )
41
51
42
52
if util .is_distributed ():
Original file line number Diff line number Diff line change 1
- from collections import Counter
2
1
import glob
3
2
import os
4
3
import tarfile
4
+ from collections import Counter
5
5
from typing import Tuple
6
6
7
7
import pytest
@@ -91,3 +91,20 @@ def test_sharded_read_glob(self):
91
91
92
92
def test_sharded_read_archive (self ):
93
93
self .read_and_check_instances (str (self .archive_filename ))
94
+
95
+ def test_attributes_inheritance (self ):
96
+ # current reader has lazy set to true
97
+ base_reader = SequenceTaggingDatasetReader (lazy = True )
98
+ reader = ShardedDatasetReader (base_reader = base_reader )
99
+
100
+ assert (
101
+ reader .lazy
102
+ ), "The ShardedDatasetReader didn't inherit the 'lazy' attribute from base_reader"
103
+
104
+ def test_set_attributes_main (self ):
105
+ base_reader = SequenceTaggingDatasetReader (lazy = True )
106
+ reader = ShardedDatasetReader (base_reader = base_reader , lazy = False )
107
+
108
+ assert (
109
+ not reader .lazy
110
+ ), "The ShardedDatasetReader inherited the 'lazy' attribute from base_reader. It should be False"
You can’t perform that action at this time.
0 commit comments