LiyuanLucasLiu / LM-LSTM-CRF

Empower Sequence Labeling with Task-Aware Language Model
http://arxiv.org/abs/1709.04109
Apache License 2.0
846 stars 207 forks source link

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

Open xiaoxiaoAurora opened 5 years ago

xiaoxiaoAurora commented 5 years ago

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(pretrainedweight) 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)

Totoro-wen commented 5 years ago

Have you solved this problem.

wnismiddle commented 5 years ago

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.