undertheseanlp / underthesea

Underthesea - Vietnamese NLP Toolkit
http://undertheseanlp.com
GNU General Public License v3.0
1.38k stars 273 forks source link

KeyError: 'reduce_ex_hook' #520

Open Daocuong-main opened 2 years ago

Daocuong-main commented 2 years ago

Mình đang thử câu lệnh dependency_parse nhưng có vẻ như bị lỗi đâu đó trong mã nguồn thì phải. sentence2 = 'Tối 29/11, Việt Nam thêm 2 ca mắc Covid-19' dependency_parse(sentence2)

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_18288/1804237079.py in <module>
----> 1 dependency_parse(sentence2)

D:\Anaconda3\envs\opencv\lib\site-packages\underthesea\__init__.py in dependency_parse(*args, **kwargs)
     50 def dependency_parse(*args, **kwargs):
     51     from underthesea.pipeline.dependency_parse import dependency_parse
---> 52     return dependency_parse(*args, **kwargs)
     53 
     54 

D:\Anaconda3\envs\opencv\lib\site-packages\underthesea\pipeline\dependency_parse\__init__.py in dependency_parse(text)
     15     sentence = word_tokenize(text)
     16     parser = init_parser()
---> 17     dataset = parser.predict([sentence])
     18     results = dataset.sentences[0].values
     19     results = list(zip(results[1], results[6], results[7]))

D:\Anaconda3\envs\opencv\lib\site-packages\torch\autograd\grad_mode.py in decorate_context(*args, **kwargs)
     26         def decorate_context(*args, **kwargs):
     27             with self.__class__():
---> 28                 return func(*args, **kwargs)
     29         return cast(F, decorate_context)
     30 

D:\Anaconda3\envs\opencv\lib\site-packages\underthesea\models\dependency_parser.py in predict(self, data, buckets, batch_size, pred, prob, tree, proj)
    196         logger.debug('Loading the data')
    197         dataset = Dataset(self.transform, data)
--> 198         dataset.build(batch_size, buckets)
    199         logger.debug(f'\n{dataset}')
    200 

D:\Anaconda3\envs\opencv\lib\site-packages\underthesea\utils\sp_data.py in build(self, batch_size, n_buckets, shuffle, distributed)
     91         self.lengths = [len(i) for i in self.fields[next(iter(self.fields))]]
     92         self.buckets = dict(zip(*kmeans(self.lengths, n_buckets)))
---> 93         self.loader = DataLoader(dataset=self,
     94                                  batch_sampler=Sampler(buckets=self.buckets,
     95                                                        batch_size=batch_size,

D:\Anaconda3\envs\opencv\lib\site-packages\underthesea\utils\sp_data.py in __init__(self, *args, **kwargs)
    105 
    106     def __init__(self, *args, **kwargs):
--> 107         super().__init__(*args, **kwargs)
    108 
    109     def __iter__(self):

D:\Anaconda3\envs\opencv\lib\site-packages\torch\utils\data\dataloader.py in __init__(self, dataset, batch_size, shuffle, sampler, batch_sampler, num_workers, collate_fn, pin_memory, drop_last, timeout, worker_init_fn, multiprocessing_context, generator, prefetch_factor, persistent_workers)
    198         # samplers first, so that they don't learn that this combo doesn't work
    199         # after spending time fixing the custom sampler errors.
--> 200         if isinstance(dataset, IterableDataset):
    201             self._dataset_kind = _DatasetKind.Iterable
    202             # NOTE [ Custom Samplers and IterableDataset ]

D:\Anaconda3\envs\opencv\lib\typing.py in __instancecheck__(cls, instance)
   1015             return True
   1016         if cls._is_protocol:
-> 1017             if all(hasattr(instance, attr) and
   1018                     # All *methods* can be blocked by setting them to None.
   1019                     (not callable(getattr(cls, attr, None)) or

D:\Anaconda3\envs\opencv\lib\typing.py in <genexpr>(.0)
   1015             return True
   1016         if cls._is_protocol:
-> 1017             if all(hasattr(instance, attr) and
   1018                     # All *methods* can be blocked by setting them to None.
   1019                     (not callable(getattr(cls, attr, None)) or

D:\Anaconda3\envs\opencv\lib\site-packages\underthesea\utils\sp_data.py in __getattr__(self, name)
     62         if name in self.__dict__:
     63             return self.__dict__[name]
---> 64         return [getattr(sentence, name) for sentence in self.sentences]
     65 
     66     def __setattr__(self, name, value):

D:\Anaconda3\envs\opencv\lib\site-packages\underthesea\utils\sp_data.py in <listcomp>(.0)
     62         if name in self.__dict__:
     63             return self.__dict__[name]
---> 64         return [getattr(sentence, name) for sentence in self.sentences]
     65 
     66     def __setattr__(self, name, value):

D:\Anaconda3\envs\opencv\lib\site-packages\underthesea\transforms\conll.py in __getattr__(self, name)
    109             return self.__dict__[name]
    110         else:
--> 111             return self.values[self.maps[name]]
    112 
    113     def __setattr__(self, name, value):

KeyError: 'reduce_ex_hook'

Thông tin kỹ thuật:

rain1024 commented 2 years ago

@Daocuong-main Hôm nay mình vừa mới test, đúng là module dependency_parse hiện tại đang bị lỗi với pytorch version > 1.7.

Nếu bạn muốn sử dụng module này, hãy cài pytorch version 1.7 nhé.

Mình sẽ hỗ trợ những phiên bản pytorch mới hơn trong thời gian tới.

Thanks