SIFRank_zh icon indicating copy to clipboard operation
SIFRank_zh copied to clipboard

无法运行。。。ValueError: index can't contain negative values

Open zhangsirf opened this issue 2 years ago • 5 comments

2022-01-10 17:05:17,709 INFO: char embedding size: 6169 2022-01-10 17:05:17,918 INFO: word embedding size: 71222 2022-01-10 17:05:21,442 INFO: Model( (token_embedder): ConvTokenEmbedder( (word_emb_layer): EmbeddingLayer( (embedding): Embedding(71222, 100, padding_idx=3) ) (char_emb_layer): EmbeddingLayer( (embedding): Embedding(6169, 50, padding_idx=6166) ) (convolutions): ModuleList( (0): Conv1d(50, 32, kernel_size=(1,), stride=(1,)) (1): Conv1d(50, 32, kernel_size=(2,), stride=(1,)) (2): Conv1d(50, 64, kernel_size=(3,), stride=(1,)) (3): Conv1d(50, 128, kernel_size=(4,), stride=(1,)) (4): Conv1d(50, 256, kernel_size=(5,), stride=(1,)) (5): Conv1d(50, 512, kernel_size=(6,), stride=(1,)) (6): Conv1d(50, 1024, kernel_size=(7,), stride=(1,)) ) (highways): Highway( (_layers): ModuleList( (0): Linear(in_features=2048, out_features=4096, bias=True) (1): Linear(in_features=2048, out_features=4096, bias=True) ) ) (projection): Linear(in_features=2148, out_features=512, bias=True) ) (encoder): ElmobiLm( (forward_layer_0): LstmCellWithProjection( (input_linearity): Linear(in_features=512, out_features=16384, bias=False) (state_linearity): Linear(in_features=512, out_features=16384, bias=True) (state_projection): Linear(in_features=4096, out_features=512, bias=False) ) (backward_layer_0): LstmCellWithProjection( (input_linearity): Linear(in_features=512, out_features=16384, bias=False) (state_linearity): Linear(in_features=512, out_features=16384, bias=True) (state_projection): Linear(in_features=4096, out_features=512, bias=False) ) (forward_layer_1): LstmCellWithProjection( (input_linearity): Linear(in_features=512, out_features=16384, bias=False) (state_linearity): Linear(in_features=512, out_features=16384, bias=True) (state_projection): Linear(in_features=4096, out_features=512, bias=False) ) (backward_layer_1): LstmCellWithProjection( (input_linearity): Linear(in_features=512, out_features=16384, bias=False) (state_linearity): Linear(in_features=512, out_features=16384, bias=True) (state_projection): Linear(in_features=4096, out_features=512, bias=False) ) ) ) Model loaded succeed 2022-01-10 17:05:24,990 INFO: 1 batches, avg len: 77.5 Traceback (most recent call last): File "/Users/hellozhang/Desktop/dj/SIFRank_关键词提取/test/test.py", line 21, in keyphrases = SIFRank(text, SIF, zh_model, N=5,elmo_layers_weight=elmo_layers_weight) File "/Users/hellozhang/Desktop/dj/SIFRank_关键词提取/model/method.py", line 179, in SIFRank sent_embeddings, candidate_embeddings_list = SIF.get_tokenized_sent_embeddings(text_obj,if_DS=if_DS,if_EA=if_EA) File "/Users/hellozhang/Desktop/dj/SIFRank_关键词提取/embeddings/sent_emb_sif.py", line 48, in get_tokenized_sent_embeddings elmo_embeddings = self.word_embeddor.get_tokenized_words_embeddings(tokens_segmented) File "/Users/hellozhang/Desktop/dj/SIFRank_关键词提取/embeddings/word_emb_elmo.py", line 29, in get_tokenized_words_embeddings elmo_embedding = [np.pad(emb, pad_width=((0,0),(0,max_len-emb.shape[1]),(0,0)) , mode='constant') for emb in elmo_embedding] File "/Users/hellozhang/Desktop/dj/SIFRank_关键词提取/embeddings/word_emb_elmo.py", line 29, in elmo_embedding = [np.pad(emb, pad_width=((0,0),(0,max_len-emb.shape[1]),(0,0)) , mode='constant') for emb in elmo_embedding] File "<array_function internals>", line 6, in pad File "/Users/hellozhang/opt/anaconda3/envs/textrank/lib/python3.7/site-packages/numpy/lib/arraypad.py", line 748, in pad pad_width = _as_pairs(pad_width, array.ndim, as_index=True) File "/Users/hellozhang/opt/anaconda3/envs/textrank/lib/python3.7/site-packages/numpy/lib/arraypad.py", line 519, in _as_pairs raise ValueError("index can't contain negative values") ValueError: index can't contain negative values 请问 这个问题怎么处理啊

zhangsirf avatar Jan 10 '22 09:01 zhangsirf

同问

yinchunlin avatar Mar 02 '22 09:03 yinchunlin

Traceback (most recent call last): File "test.py", line 16, in keyphrases = SIFRank(text, SIF, zh_model, N=15,elmo_layers_weight=elmo_layers_weight) File "/home/SIFRank_zh-master/model/method.py", line 179, in SIFRank sent_embeddings, candidate_embeddings_list = SIF.get_tokenized_sent_embeddings(text_obj,if_DS=if_DS,if_EA=if_EA) File "/home/SIFRank_zh-master/embeddings/sent_emb_sif.py", line 48, in get_tokenized_sent_embeddings elmo_embeddings = self.word_embeddor.get_tokenized_words_embeddings(tokens_segmented) File "/home/SIFRank_zh-master/embeddings/word_emb_elmo.py", line 29, in get_tokenized_words_embeddings elmo_embedding = [np.pad(emb, pad_width=((0,0),(0,max_len-emb.shape[1]),(0,0)) , mode='constant') for emb in elmo_embedding] File "/home/SIFRank_zh-master/embeddings/word_emb_elmo.py", line 29, in elmo_embedding = [np.pad(emb, pad_width=((0,0),(0,max_len-emb.shape[1]),(0,0)) , mode='constant') for emb in elmo_embedding] File "/usr/local/python3/lib/python3.6/site-packages/numpy/lib/arraypad.py", line 1295, in pad pad_width = _validate_lengths(narray, pad_width) File "/usr/local/python3/lib/python3.6/site-packages/numpy/lib/arraypad.py", line 1086, in _validate_lengths raise ValueError(fmt % (number_elements,)) ValueError: ((0, 0), (0, -1), (0, 0)) cannot contain negative values.

yinchunlin avatar Mar 02 '22 09:03 yinchunlin

可否产看一下是否是相似问题issue

sunyilgdx avatar Mar 03 '22 07:03 sunyilgdx

2022-01-10 17:05:17,709 INFO: char embedding size: 6169 2022-01-10 17:05:17,918 INFO: word embedding size: 71222 2022-01-10 17:05:21,442 INFO: Model( (token_embedder): ConvTokenEmbedder( (word_emb_layer): EmbeddingLayer( (embedding): Embedding(71222, 100, padding_idx=3) ) (char_emb_layer): EmbeddingLayer( (embedding): Embedding(6169, 50, padding_idx=6166) ) (convolutions): ModuleList( (0): Conv1d(50, 32, kernel_size=(1,), stride=(1,)) (1): Conv1d(50, 32, kernel_size=(2,), stride=(1,)) (2): Conv1d(50, 64, kernel_size=(3,), stride=(1,)) (3): Conv1d(50, 128, kernel_size=(4,), stride=(1,)) (4): Conv1d(50, 256, kernel_size=(5,), stride=(1,)) (5): Conv1d(50, 512, kernel_size=(6,), stride=(1,)) (6): Conv1d(50, 1024, kernel_size=(7,), stride=(1,)) ) (highways): Highway( (_layers): ModuleList( (0): Linear(in_features=2048, out_features=4096, bias=True) (1): Linear(in_features=2048, out_features=4096, bias=True) ) ) (projection): Linear(in_features=2148, out_features=512, bias=True) ) (encoder): ElmobiLm( (forward_layer_0): LstmCellWithProjection( (input_linearity): Linear(in_features=512, out_features=16384, bias=False) (state_linearity): Linear(in_features=512, out_features=16384, bias=True) (state_projection): Linear(in_features=4096, out_features=512, bias=False) ) (backward_layer_0): LstmCellWithProjection( (input_linearity): Linear(in_features=512, out_features=16384, bias=False) (state_linearity): Linear(in_features=512, out_features=16384, bias=True) (state_projection): Linear(in_features=4096, out_features=512, bias=False) ) (forward_layer_1): LstmCellWithProjection( (input_linearity): Linear(in_features=512, out_features=16384, bias=False) (state_linearity): Linear(in_features=512, out_features=16384, bias=True) (state_projection): Linear(in_features=4096, out_features=512, bias=False) ) (backward_layer_1): LstmCellWithProjection( (input_linearity): Linear(in_features=512, out_features=16384, bias=False) (state_linearity): Linear(in_features=512, out_features=16384, bias=True) (state_projection): Linear(in_features=4096, out_features=512, bias=False) ) ) ) Model loaded succeed 2022-01-10 17:05:24,990 INFO: 1 batches, avg len: 77.5 Traceback (most recent call last): File "/Users/hellozhang/Desktop/dj/SIFRank_关键词提取/test/test.py", line 21, in keyphrases = SIFRank(text, SIF, zh_model, N=5,elmo_layers_weight=elmo_layers_weight) File "/Users/hellozhang/Desktop/dj/SIFRank_关键词提取/model/method.py", line 179, in SIFRank sent_embeddings, candidate_embeddings_list = SIF.get_tokenized_sent_embeddings(text_obj,if_DS=if_DS,if_EA=if_EA) File "/Users/hellozhang/Desktop/dj/SIFRank_关键词提取/embeddings/sent_emb_sif.py", line 48, in get_tokenized_sent_embeddings elmo_embeddings = self.word_embeddor.get_tokenized_words_embeddings(tokens_segmented) File "/Users/hellozhang/Desktop/dj/SIFRank_关键词提取/embeddings/word_emb_elmo.py", line 29, in get_tokenized_words_embeddings elmo_embedding = [np.pad(emb, pad_width=((0,0),(0,max_len-emb.shape[1]),(0,0)) , mode='constant') for emb in elmo_embedding] File "/Users/hellozhang/Desktop/dj/SIFRank_关键词提取/embeddings/word_emb_elmo.py", line 29, in elmo_embedding = [np.pad(emb, pad_width=((0,0),(0,max_len-emb.shape[1]),(0,0)) , mode='constant') for emb in elmo_embedding] File "<array_function internals>", line 6, in pad File "/Users/hellozhang/opt/anaconda3/envs/textrank/lib/python3.7/site-packages/numpy/lib/arraypad.py", line 748, in pad pad_width = _as_pairs(pad_width, array.ndim, as_index=True) File "/Users/hellozhang/opt/anaconda3/envs/textrank/lib/python3.7/site-packages/numpy/lib/arraypad.py", line 519, in _as_pairs raise ValueError("index can't contain negative values") ValueError: index can't contain negative values 请问 这个问题怎么处理啊

需要同时修改哈工大的elmoformanylangs源码中的elmo.py就能解决

Kozon2015 avatar Apr 12 '22 07:04 Kozon2015

Traceback (most recent call last): File "test.py", line 16, in keyphrases = SIFRank(text, SIF, zh_model, N=15,elmo_layers_weight=elmo_layers_weight) File "/home/SIFRank_zh-master/model/method.py", line 179, in SIFRank sent_embeddings, candidate_embeddings_list = SIF.get_tokenized_sent_embeddings(text_obj,if_DS=if_DS,if_EA=if_EA) File "/home/SIFRank_zh-master/embeddings/sent_emb_sif.py", line 48, in get_tokenized_sent_embeddings elmo_embeddings = self.word_embeddor.get_tokenized_words_embeddings(tokens_segmented) File "/home/SIFRank_zh-master/embeddings/word_emb_elmo.py", line 29, in get_tokenized_words_embeddings elmo_embedding = [np.pad(emb, pad_width=((0,0),(0,max_len-emb.shape[1]),(0,0)) , mode='constant') for emb in elmo_embedding] File "/home/SIFRank_zh-master/embeddings/word_emb_elmo.py", line 29, in elmo_embedding = [np.pad(emb, pad_width=((0,0),(0,max_len-emb.shape[1]),(0,0)) , mode='constant') for emb in elmo_embedding] File "/usr/local/python3/lib/python3.6/site-packages/numpy/lib/arraypad.py", line 1295, in pad pad_width = _validate_lengths(narray, pad_width) File "/usr/local/python3/lib/python3.6/site-packages/numpy/lib/arraypad.py", line 1086, in _validate_lengths raise ValueError(fmt % (number_elements,)) ValueError: ((0, 0), (0, -1), (0, 0)) cannot contain negative values.

需要同时修改哈工大的elmoformanylangs源码中的elmo.py就能解决

Kozon2015 avatar Apr 12 '22 07:04 Kozon2015