Dadmatech / DadmaTools

DadmaTools is a Persian NLP tools developed by Dadmatech Co.
Apache License 2.0
179 stars 39 forks source link

Error on loading parsbert #31

Closed imani closed 2 years ago

imani commented 2 years ago

Hi I have an issue while loading models with python3.9:

RuntimeError Traceback (most recent call last) Input In [31], in 1 import dadmatools.pipeline.language as language 3 pips = 'tok,lem,pos,dep,chunk,cons' ----> 4 nlp = language.Pipeline(pips) 5 def dadmatokenize(text): 6 doc = nlp(text)

File ~/repos/Nasim/nasim_venv/lib/python3.9/site-packages/dadmatools/pipeline/language.py:216, in Pipeline.new(cls, pipeline) 215 def new(cls, pipeline): --> 216 language = NLP('fa', pipeline) 217 nlp = language.nlp 218 return nlp

File ~/repos/Nasim/nasim_venv/lib/python3.9/site-packages/dadmatools/pipeline/language.py:71, in NLP.init(self, lang, pipelines) 69 if 'dep' or 'chunk' in pipelines: 70 global depparser_model ---> 71 depparser_model = dp.load_model() 72 self.nlp.add_pipe('dependancyparser') 74 if 'pos' or 'chunk' in pipelines:

File ~/repos/Nasim/nasim_venv/lib/python3.9/site-packages/dadmatools/models/dependancy_parser.py:148, in load_model() 145 config['target_dir'] = prefix + config['target_dir'] 146 config['embeddings']['BertEmbeddings-0']['bert_model_or_path'] = prefix + config['embeddings-saved-dir'] --> 148 student=create_model(config) 149 base_path=Path(config['target_dir'])/config['model_name'] 151 return student

File ~/repos/Nasim/nasim_venv/lib/python3.9/site-packages/dadmatools/models/dependancy_parser.py:120, in create_model(config) 118 tagger = tagger.load(base_path / "final-model.pt") 119 elif (base_path).exists(): --> 120 tagger = tagger.load(base_path) 121 else: 122 assert 0, str(base_path)+ ' not exist!'

File ~/repos/Nasim/nasim_venv/lib/python3.9/site-packages/dadmatools/models/flair/nn.py:105, in Model.load(cls, model, device) 102 # load_big_file is a workaround by https://github.com/highway11git to load models on some Mac/Windows setups 103 # see https://github.com/zalandoresearch/flair/issues/351 104 f = flair.file_utils.load_big_file(str(model_file)) --> 105 state = torch.load(f, map_location=device) 107 model = cls._init_model_with_state_dict(state, testing = device=='cpu') 109 model.eval()

File ~/repos/Nasim/nasim_venv/lib/python3.9/site-packages/torch/serialization.py:600, in load(f, map_location, pickle_module, **pickle_load_args) 595 if _is_zipfile(opened_file): 596 # The zipfile reader is going to advance the current file position. 597 # If we want to actually tail call to torch.jit.load, we need to 598 # reset back to the original position. 599 orig_position = opened_file.tell() --> 600 with _open_zipfile_reader(opened_file) as opened_zipfile: 601 if _is_torchscript_zip(opened_zipfile): 602 warnings.warn("'torch.load' received a zip file that looks like a TorchScript archive" 603 " dispatching to 'torch.jit.load' (call 'torch.jit.load' directly to" 604 " silence this warning)", UserWarning)

File ~/repos/Nasim/nasim_venv/lib/python3.9/site-packages/torch/serialization.py:242, in _open_zipfile_reader.init(self, name_or_buffer) 241 def init(self, name_or_buffer) -> None: --> 242 super(_open_zipfile_reader, self).init(torch._C.PyTorchFileReader(name_or_buffer))

RuntimeError: PytorchStreamReader failed reading zip archive: failed finding central directory

roetezadi commented 2 years ago

Hi, Please run your code with python3.8 or python3.7 (we are still working on python3.9). If you still get the same error please let us know. Make sure you also download the latest version (1.3.10). If you are working on GPU please take a look at https://pytorch.org/get-started/previous-versions/ to find the right version of pytorch for your system.

imani commented 2 years ago

Thanks, finally I could load the model successfully. The issue was with the copied "postagger.pt" file in the Dadmatools saved_models directory. It wasn’t copied properly and the file size was smaller (only 117 MB instead of 639 MB).