sunyilgdx / SIFRank_zh

Keyphrase or Keyword Extraction 基于预训练模型的中文关键词抽取方法(论文SIFRank: A New Baseline for Unsupervised Keyphrase Extraction Based on Pre-trained Language Model 的中文版代码)
417 stars 80 forks source link

index can't contain negative values #10

Closed RFHzhj closed 4 years ago

RFHzhj commented 4 years ago

Traceback (most recent call last): File "D:/algo/SIFRank_zh-master/embeddings/word_emb_elmo.py", line 38, in embs = elmo.get_tokenized_words_embeddings(sents) File "D:/algo/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 "D:/algo/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 "<__array_function__ internals>", line 6, in pad File "D:\Anaconda\envs\baidu\lib\site-packages\numpy\lib\arraypad.py", line 748, in pad pad_width = _as_pairs(pad_width, array.ndim, as_index=True) File "D:\Anaconda\envs\baidu\lib\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

求问大佬,这个报错是什么原因啊?

sunyilgdx commented 4 years ago

不清楚你有没有修改哈工大ELMo里的bug,#31

RFHzhj commented 4 years ago

已经按照您readme里面写的修改啦

RFHzhj commented 4 years ago

还麻烦问下,为啥下载了thulac以后没有thulac.models文件

RFHzhj commented 4 years ago

谢谢,问题已经解决了。求问有什么方法能提高推理速度吗

sunyilgdx commented 4 years ago

实际情况下可以提前计算单词的静态ELMo词向量,做成索引,可以大大加快速度 @RFHzhj

RFHzhj commented 4 years ago

实际情况下可以提前计算单词的静态ELMo词向量,做成索引,可以大大加快速度 @RFHzhj

谢谢大佬

zhangdeshan commented 3 years ago

实际情况下可以提前计算单词的静态ELMo词向量,做成索引,可以大大加快速度 @RFHzhj

谢谢大佬

谢谢,问题已经解决了。求问有什么方法能提高推理速度吗

我现在也遇到了这个问题,怎么解决的?能说说么?感谢

sunyilgdx commented 3 years ago

项目里面用文本分割切片和向量对齐的方法提高单个出入的推理速度,但还是绕不过用ELMo进行编码计算,可有以下几个方案: 1.实际情况下可以提前建立类似GloVe的“词-词向量”对应表,这样的速度已经比较快了,但是会存在OOV的问题;这个我在做数据集中的测试时用的这种方法,只要是单词表不变,就不会对结果有太大的影响 2.可以尝试停用LSTM层,只用char-Embedding层,效果也还可以 3.LSTM替换成transformer,AllenNLP官网是有英文模型的,这个我在实验中试过,速度提升了,但是效果变差

Sundyo commented 3 years ago

Traceback (most recent call last): File "D:/algo/SIFRank_zh-master/embeddings/word_emb_elmo.py", line 38, in embs = elmo.get_tokenized_words_embeddings(sents) File "D:/algo/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 "D:/algo/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 "<array_function internals>", line 6, in pad File "D:\Anaconda\envs\baidu\lib\site-packages\numpy\lib\arraypad.py", line 748, in pad pad_width = _as_pairs(pad_width, array.ndim, as_index=True) File "D:\Anaconda\envs\baidu\lib\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

求问大佬,这个报错是什么原因啊?

请问您是怎么解决这个报错的呀!?急,求解答!谢谢啦!