LM-LSTM-CRF icon indicating copy to clipboard operation
LM-LSTM-CRF copied to clipboard

train_w.py Error, TypeError: can't convert np.ndarray of type numpy.object_

Open xiaoxiaoAurora opened this issue 6 years ago • 2 comments

Hi, Liyuan, I encountered the following problem while running train_w.py, Traceback (most recent call last): File "/workspace/train.py", line 117, in shrink_to_corpus=args.shrink_embedding) File "/workspace/models/utils.py", line 457, in load_embedding_wlm embedding_tensor_1 = torch.FloatTensor(pretrained_weight) TypeError: can't convert np.ndarray of type numpy.object_. The only supported types are: double, float, float16, int64, int32, and uint8.

And ,at the line 457, my coding as follows: (1)
if not shrink_to_corpus: pretrained_weight = np.asarray(outdoc_embedding_array) embedding_tensor_1 = torch.from_numpy(pretrained_weight) word_emb_len = embedding_tensor_0.size(1) assert(word_emb_len == emb_len)

(2) if not shrink_to_corpus: embedding_tensor_1 = torch.Tensor(np.asarray(outdoc_embedding_array)) word_emb_len = embedding_tensor_0.size(1) assert(word_emb_len == emb_len)

xiaoxiaoAurora avatar Dec 06 '18 10:12 xiaoxiaoAurora

Have you solved this problem.

Totoro-wen avatar May 05 '19 01:05 Totoro-wen

I have encountered this problem before, but I just changed the embedding file. The first line of the original embedding file shows vocab size and dimension, and the replaced file does not. I don't know if this will help you.

wnismiddle avatar May 05 '19 07:05 wnismiddle