使用fastnlp的时候,由于使用的pytorch==1.6.0,而fastnlp版本较低,出现以下问题:
Traceback (most recent call last):
File "train_zen_cn.py", line 175, in <module>
data_bundle, embed, bi_embed, tencent_words_embed, train_feature_data, dev_feature_data, test_feature_data, feature2id, id2feature = load_data()
File "/home/.../fastNLP/core/utils.py", line 155, in wrapper
results = func(*args, **kwargs)
File "train_zen_cn.py", line 145, in load_data
embed = StaticEmbedding(data_bundle.get_vocab('chars'),
File "/home/.../fastNLP/embeddings/static_embedding.py", line 154, in __init__
embedding = self._load_with_vocab(model_path, vocab=vocab, init_method=init_method)
File "/home/.../fastNLP/embeddings/static_embedding.py", line 266, in _load_with_vocab
self.register_buffer('words_to_words', torch.full((len(vocab), ), fill_value=unknown_idx), dtype=torch.long())
RuntimeError: Providing a bool or integral fill value without setting the optional `dtype` or `out` arguments is currently unsupported. In PyTorch 1.7, when `dtype` and `out` are not set a bool fill value will return a tensor of torch.bool dtype, and an integral fill value will return a tensor of torch.long dtype.
需要做出以下修改
# self.register_buffer('words_to_words', torch.full((len(vocab), ), fill_value=unknown_idx).long())
self.register_buffer('words_to_words', torch.full((len(vocab), ), fill_value=unknown_idx, dtype=torch.long))