From 64a917bc0ce42f83477964fbde25f7c794264ba2 Mon Sep 17 00:00:00 2001 From: yangheng95 Date: Wed, 12 Oct 2022 10:46:30 +0100 Subject: [PATCH] 1.16.19a0 --- pyabsa/__init__.py | 2 +- pyabsa/core/apc/models/ensembler.py | 2 +- pyabsa/core/apc/prediction/sentiment_classifier.py | 8 ++++---- pyabsa/core/atepc/prediction/aspect_extractor.py | 10 +++++----- .../__bert__/dataset_utils/data_utils_for_inference.py | 2 +- pyabsa/core/tad/prediction/tad_classifier.py | 8 ++++---- .../__bert__/dataset_utils/data_utils_for_inference.py | 2 +- pyabsa/core/tc/prediction/text_classifier.py | 8 ++++---- 8 files changed, 21 insertions(+), 21 deletions(-) diff --git a/pyabsa/__init__.py b/pyabsa/__init__.py index d638d58ad..31f0c4cf7 100644 --- a/pyabsa/__init__.py +++ b/pyabsa/__init__.py @@ -7,7 +7,7 @@ # Copyright (C) 2021. All Rights Reserved. -__version__ = '1.16.18' +__version__ = '1.16.19a0' __name__ = 'pyabsa' diff --git a/pyabsa/core/apc/models/ensembler.py b/pyabsa/core/apc/models/ensembler.py index 210a058b4..210838ef1 100644 --- a/pyabsa/core/apc/models/ensembler.py +++ b/pyabsa/core/apc/models/ensembler.py @@ -80,7 +80,7 @@ def __init__(self, opt, load_dataset=True, **kwargs): if hasattr(APCModelList, models[i].__name__): try: - if kwargs.pop('offline', False): + if kwargs.get('offline', False): self.tokenizer = AutoTokenizer.from_pretrained(find_cwd_dir(self.opt.pretrained_bert.split('/')[-1]), do_lower_case='uncased' in self.opt.pretrained_bert) self.bert = AutoModel.from_pretrained(find_cwd_dir(self.opt.pretrained_bert.split('/')[-1])) if not self.bert else self.bert # share the underlying bert between models else: diff --git a/pyabsa/core/apc/prediction/sentiment_classifier.py b/pyabsa/core/apc/prediction/sentiment_classifier.py index 58ce78f4b..c455fd090 100644 --- a/pyabsa/core/apc/prediction/sentiment_classifier.py +++ b/pyabsa/core/apc/prediction/sentiment_classifier.py @@ -74,7 +74,7 @@ def __init__(self, model_arg=None, cal_perplexity=False, **kwargs): with open(config_path, mode='rb') as f: self.opt = pickle.load(f) - self.opt.device = get_device(kwargs.pop('auto_device', True))[0] + self.opt.device = get_device(kwargs.get('auto_device', True))[0] if state_dict_path or model_path: if state_dict_path: @@ -85,7 +85,7 @@ def __init__(self, model_arg=None, cal_perplexity=False, **kwargs): with open(tokenizer_path, mode='rb') as f: if hasattr(APCModelList, self.opt.model.__name__): try: - if kwargs.pop('offline', False): + if kwargs.get('offline', False): self.tokenizer = AutoTokenizer.from_pretrained(find_cwd_dir(self.opt.pretrained_bert.split('/')[-1]), do_lower_case='uncased' in self.opt.pretrained_bert) else: self.tokenizer = AutoTokenizer.from_pretrained(self.opt.pretrained_bert, do_lower_case='uncased' in self.opt.pretrained_bert) @@ -109,7 +109,7 @@ def __init__(self, model_arg=None, cal_perplexity=False, **kwargs): self.tokenizer = tokenizer - if kwargs.pop('verbose', False): + if kwargs.get('verbose', False): print('Config used in Training:') print_args(self.opt) @@ -153,7 +153,7 @@ def __init__(self, model_arg=None, cal_perplexity=False, **kwargs): # torch.backends.cudnn.benchmark = False self.opt.initializer = self.opt.initializer - self.opt.eval_batch_size = kwargs.pop('eval_batch_size', 128) + self.opt.eval_batch_size = kwargs.get('eval_batch_size', 128) if self.cal_perplexity: try: diff --git a/pyabsa/core/atepc/prediction/aspect_extractor.py b/pyabsa/core/atepc/prediction/aspect_extractor.py index e2d2362e5..2bd79d14d 100644 --- a/pyabsa/core/atepc/prediction/aspect_extractor.py +++ b/pyabsa/core/atepc/prediction/aspect_extractor.py @@ -59,10 +59,10 @@ def __init__(self, model_arg=None, **kwargs): with open(config_path, mode='rb') as f: self.opt = pickle.load(f) - self.opt.device = get_device(kwargs.pop('auto_device', True))[0] + self.opt.device = get_device(kwargs.get('auto_device', True))[0] if state_dict_path: try: - if kwargs.pop('offline', False): + if kwargs.get('offline', False): bert_base_model = AutoModel.from_pretrained(find_cwd_dir(self.opt.pretrained_bert.split('/')[-1])) else: bert_base_model = AutoModel.from_pretrained(self.opt.pretrained_bert) @@ -76,7 +76,7 @@ def __init__(self, model_arg=None, **kwargs): self.model = torch.load(model_path, map_location='cpu') self.model.opt = self.opt try: - if kwargs.pop('offline', False): + if kwargs.get('offline', False): self.tokenizer = AutoTokenizer.from_pretrained(find_cwd_dir(self.opt.pretrained_bert.split('/')[-1])) else: self.tokenizer = AutoTokenizer.from_pretrained(self.opt.pretrained_bert, do_lower_case='uncased' in self.opt.pretrained_bert) @@ -102,7 +102,7 @@ def __init__(self, model_arg=None, **kwargs): # np.random.seed(self.opt.seed) # torch.manual_seed(self.opt.seed) - if kwargs.pop('verbose', False): + if kwargs.get('verbose', False): print('Config used in Training:') print_args(self.opt) @@ -112,7 +112,7 @@ def __init__(self, model_arg=None, **kwargs): self.opt.gradient_accumulation_steps)) self.eval_dataloader = None - self.opt.eval_batch_size = kwargs.pop('eval_batch_size', 128) + self.opt.eval_batch_size = kwargs.get('eval_batch_size', 128) self.to(self.opt.device) diff --git a/pyabsa/core/tad/classic/__bert__/dataset_utils/data_utils_for_inference.py b/pyabsa/core/tad/classic/__bert__/dataset_utils/data_utils_for_inference.py index a980dd9da..4659563dd 100644 --- a/pyabsa/core/tad/classic/__bert__/dataset_utils/data_utils_for_inference.py +++ b/pyabsa/core/tad/classic/__bert__/dataset_utils/data_utils_for_inference.py @@ -14,7 +14,7 @@ class Tokenizer4Pretraining: def __init__(self, max_seq_len, opt, **kwargs): - if kwargs.pop('offline', False): + if kwargs.get('offline', False): self.tokenizer = AutoTokenizer.from_pretrained(find_cwd_dir(opt.pretrained_bert.split('/')[-1]), do_lower_case='uncased' in opt.pretrained_bert) else: diff --git a/pyabsa/core/tad/prediction/tad_classifier.py b/pyabsa/core/tad/prediction/tad_classifier.py index ad989b77f..a0c4a4efc 100644 --- a/pyabsa/core/tad/prediction/tad_classifier.py +++ b/pyabsa/core/tad/prediction/tad_classifier.py @@ -125,12 +125,12 @@ def __init__(self, model_arg=None, cal_perplexity=False, **kwargs): with open(config_path, mode='rb') as f: self.opt = pickle.load(f) - self.opt.device = get_device(kwargs.pop('auto_device', True))[0] + self.opt.device = get_device(kwargs.get('auto_device', True))[0] if state_dict_path or model_path: if hasattr(BERTTADModelList, self.opt.model.__name__): if state_dict_path: - if kwargs.pop('offline', False): + if kwargs.get('offline', False): self.bert = AutoModel.from_pretrained( find_cwd_dir(self.opt.pretrained_bert.split('/')[-1])) else: @@ -172,7 +172,7 @@ def __init__(self, model_arg=None, cal_perplexity=False, **kwargs): self.tokenizer = tokenizer - if kwargs.pop('verbose', False): + if kwargs.get('verbose', False): print('Config used in Training:') print_args(self.opt) @@ -184,7 +184,7 @@ def __init__(self, model_arg=None, cal_perplexity=False, **kwargs): raise KeyError('The checkpoint you are loading is not from classifier model.') self.infer_dataloader = None - self.opt.eval_batch_size = kwargs.pop('eval_batch_size', 128) + self.opt.eval_batch_size = kwargs.get('eval_batch_size', 128) # if self.opt.seed is not None: # random.seed(self.opt.seed) diff --git a/pyabsa/core/tc/classic/__bert__/dataset_utils/data_utils_for_inference.py b/pyabsa/core/tc/classic/__bert__/dataset_utils/data_utils_for_inference.py index c6cd1fcd9..ab4d04df2 100644 --- a/pyabsa/core/tc/classic/__bert__/dataset_utils/data_utils_for_inference.py +++ b/pyabsa/core/tc/classic/__bert__/dataset_utils/data_utils_for_inference.py @@ -14,7 +14,7 @@ class Tokenizer4Pretraining: def __init__(self, max_seq_len, opt, **kwargs): - if kwargs.pop('offline', False): + if kwargs.get('offline', False): self.tokenizer = AutoTokenizer.from_pretrained(find_cwd_dir(opt.pretrained_bert.split('/')[-1]), do_lower_case='uncased' in opt.pretrained_bert) else: diff --git a/pyabsa/core/tc/prediction/text_classifier.py b/pyabsa/core/tc/prediction/text_classifier.py index da3a9bc72..ddb98a911 100644 --- a/pyabsa/core/tc/prediction/text_classifier.py +++ b/pyabsa/core/tc/prediction/text_classifier.py @@ -74,12 +74,12 @@ def __init__(self, model_arg=None, cal_perplexity=False, **kwargs): with open(config_path, mode='rb') as f: self.opt = pickle.load(f) - self.opt.device = get_device(kwargs.pop('auto_device', True))[0] + self.opt.device = get_device(kwargs.get('auto_device', True))[0] if state_dict_path or model_path: if hasattr(BERTTCModelList, self.opt.model.__name__): if state_dict_path: - if kwargs.pop('offline', False): + if kwargs.get('offline', False): self.bert = AutoModel.from_pretrained( find_cwd_dir(self.opt.pretrained_bert.split('/')[-1])) else: @@ -121,7 +121,7 @@ def __init__(self, model_arg=None, cal_perplexity=False, **kwargs): self.tokenizer = tokenizer - if kwargs.pop('verbose', False): + if kwargs.get('verbose', False): print('Config used in Training:') print_args(self.opt) @@ -139,7 +139,7 @@ def __init__(self, model_arg=None, cal_perplexity=False, **kwargs): self.dataset = GloVeTCDataset(tokenizer=self.tokenizer, opt=self.opt) self.infer_dataloader = None - self.opt.eval_batch_size = kwargs.pop('eval_batch_size', 128) + self.opt.eval_batch_size = kwargs.get('eval_batch_size', 128) # if self.opt.seed is not None: # random.seed(self.opt.seed)