我试图在本地运行以下句子压缩:https://github.com/zhaohengyang/Generate-Parallel-Data-for-Sentence-Compression
所以我复制了文件并用conda安装了所有的依赖项。我做了一些小的修改,比如从url读取数据,而不是从本地磁盘读取数据,并放置了他的并行数据_py代捆绑在我的单个py文件中。你知道吗
但是当我运行它时,我得到:
空间库无法将句子解析到树中。请忽略这对句子
----------------59-------------------
reducing sentence: This year the Venezuelan government plans to continue its pace of land expropriations in order to move towards what it terms ``agrarian socialism''.
reducing headline: Venezuelan government to continue pace of land expropriations for ``agrarian socialism''
Traceback (most recent call last):
File "/home/user/dev/projects/python-snippets/zhaohengyang/sentence-compression.py", line 701, in <module>
reduce_sentence(sample)
File "/home/user/dev/projects/python-snippets/zhaohengyang/sentence-compression.py", line 641, in reduce_sentence
sentence_info = parse_info(sentence)
File "/home/user/dev/projects/python-snippets/zhaohengyang/sentence-compression.py", line 616, in parse_info
heads = [index + item[0] for index, item in enumerate(doc.to_array([HEAD]))]
IndexError: invalid index to scalar variable.
我不知道如何解决这个问题,因为我是一个相当新的python用户。你知道吗
下面是我用来重现问题的完整代码:https://gist.github.com/avidanyum/3edfbc96ea22807445ab5307830d41db
失败的内部代码段:
def parse_info(sentence):
doc = nlp(sentence)
heads = [index + item[0] for index, item in enumerate(doc.to_array([HEAD]))]
现在我加载了nlp
:
import spacy
print('if you didnt run: python -m spacy download en')
import spacy.lang.en
nlp = spacy.load('en')
有关我的环境的更多信息:
/home/user/home/user/dev/anaconda3/envs/pymachine/bin/python --version
Python 2.7.15 :: Anaconda, Inc.
请注意,我正在Python3.6上运行Spacy2.0,但只是在一个示例语句上运行了一个快速测试:
我在运行您的代码时遇到一些错误,这两个错误都在您指定的行中:
这是因为
to_array
调用接受list
个string
对象。将其修复为:解决问题。您还将注意到,
enumerate
返回的item
是int
或scalar
类型,因此它没有索引属性。摆脱你的index[0]
这会解决你的问题。你知道吗没有错误的方法:
相关问题 更多 >
编程相关推荐