Make a base init in FeatureExtractionMixin (#11074)

This commit is contained in:
Sylvain Gugger 2021-04-05 18:02:28 -04:00 committed by GitHub
parent 04ceee7d24
commit 2199608ca6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 7 deletions

View File

@ -56,13 +56,7 @@ class SequenceFeatureExtractor(FeatureExtractionMixin):
self.padding_side = kwargs.pop("padding_side", "right")
self.return_attention_mask = kwargs.pop("return_attention_mask", True)
# Additional attributes without default values
for key, value in kwargs.items():
try:
setattr(self, key, value)
except AttributeError as err:
logger.error(f"Can't set {key} with value {value} for {self}")
raise err
super().__init__(**kwargs)
def pad(
self,

View File

@ -197,6 +197,16 @@ class FeatureExtractionMixin:
extractors.
"""
def __init__(self, **kwargs):
"""Set elements of `kwargs` as attributes."""
# Additional attributes without default values
for key, value in kwargs.items():
try:
setattr(self, key, value)
except AttributeError as err:
logger.error(f"Can't set {key} with value {value} for {self}")
raise err
@classmethod
def from_pretrained(
cls, pretrained_model_name_or_path: Union[str, os.PathLike], **kwargs