运行涉及stanfordnlp.Pipeline的代码时出现断言错误

问题描述

我收到断言错误,无法弄清楚问题出在哪里。相同的代码行适用于另一个列表,但是当我尝试与此列表进行完全相同的操作时,它将引发断言错误。我正在使用standfordnp。

    negative_list = negative_df['tweet'].to_list()
    negative_list
    new_list=[]
    for line in negative_list:
        txt_list = nltk.word_tokenize(line)
        taggedList = nltk.pos_tag(txt_list)
        new_list.append(taggedList)
        #print(taggedList)
    new_list
    newwordList = []
    flag = 0
    for j in new_list:
      for i in range(0,len(j)-1):
        if(new_list[i][1]=="NN" and new_list[i+1][1]=="NN"):
            newwordList.append(new_list[i][0]+new_list[i+1][0])
            flag=1
        else:
            if (flag==1):
    
                flag=0
                continue
            newwordList.append(new_list[i][0])
            if (i==len(new_list)-2):
                newwordList.append(new_list[i+1][0])
    finaltxt = '\n '.join(' '.join(word) for word in newwordList) #print('\n'.join(''.join(elems) for elems in data))
    print(finaltxt)
    nlp = stanfordnlp.Pipeline()
    doc = nlp(finaltxt)
    dep_node = []
    for dep_edge in doc.sentences[0].dependencies:
        dep_node.append([dep_edge[2].text,dep_edge[0].index,dep_edge[1]])
    for i in range(0,len(dep_node)):
        if (int(dep_node[i][1]) != 0):
            dep_node[i][1] = newwordList[(int(dep_node[i][1]) - 1)]
    print(dep_node)
    
    **After this statement i am getting this error:**

    AssertionError                            Traceback (most recent call last)
<ipython-input-30-7f55b8388dd9> in <module>()
      1 nlp = stanfordnlp.Pipeline(pos_batch_size=4096)
----> 2 doc = nlp(finaltxt)
      3 dep_node = []
      4 for dep_edge in doc.sentences[0].dependencies:
      5     dep_node.append([dep_edge[2].text,dep_edge[1]])

4 frames
/usr/local/lib/python3.6/dist-packages/stanfordnlp/models/pos/data.py in __getitem__(self,key)
     89         batch_size = len(batch)
     90         batch = list(zip(*batch))
---> 91         assert len(batch) == 4096
     92 
     93         # sort sentences by lens for easy RNN operations

AssertionError: 

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)