FuYanzhe2 / Name-Entity-Recognition

Lstm-crf,Lattice-CRF,bert-ner及近年ner相关论文follow
564 stars 195 forks source link

您好,我看了您的命名实体识别的代码,发现在评估代码的时候会出现,utf8错误,如果更改evesteps值为1,有结果但为nan,还有就是 out of index 怎么解决呀 #15

Open yt-liang opened 4 years ago

yt-liang commented 4 years ago

您好,我看了您的命名实体识别的代码,发现在评估代码的时候会出现,utf8错误,如果更改evesteps值为1,有结果但为nan,还有就是 out of index 怎么解决呀

Heaven-zhw commented 4 years ago

问一下,您说的out of index 是predict输出成文件部分的列表越界错误吗?作者好像在代码里加了注释说他也不清楚为什么。我测试了一下,发现它有的把CLS和SEP都预测错了,导致解码失败。我觉得可以强制规定预测的第一个元素就是[CLS],最后一个元素就是[SEP]。

yt-liang commented 4 years ago

问一下,您说的out of index 是predict输出成文件部分的列表越界错误吗?作者好像在代码里加了注释说他也不清楚为什么。我测试了一下,发现它有的把CLS和SEP都预测错了,导致解码失败。我觉得可以强制规定预测的第一个元素就是[CLS],最后一个元素就是[SEP]。

您好,您解决了吗,就是预测的时候,出现out of index。具体怎么改能指导一下吗?方便的话可以qq联系吗(642516257,微信同号)

Heaven-zhw commented 4 years ago

问一下,您说的out of index 是predict输出成文件部分的列表越界错误吗?作者好像在代码里加了注释说他也不清楚为什么。我测试了一下,发现它有的把CLS和SEP都预测错了,导致解码失败。我觉得可以强制规定预测的第一个元素就是[CLS],最后一个元素就是[SEP]。

您好,您解决了吗,就是预测的时候,出现out of index。具体怎么改能指导一下吗?方便的话可以qq联系吗(642516257,微信同号)

OK

cjwen15 commented 3 years ago

问一下,您说的out of index 是predict输出成文件部分的列表越界错误吗?作者好像在代码里加了注释说他也不清楚为什么。我测试了一下,发现它有的把CLS和SEP都预测错了,导致解码失败。我觉得可以强制规定预测的第一个元素就是[CLS],最后一个元素就是[SEP]。

您好,您解决了吗,就是预测的时候,出现out of index。具体怎么改能指导一下吗?方便的话可以qq联系吗(642516257,微信同号)

OK

您好,可以把方法po出来吗?具体怎么改呢?

Heaven-zhw commented 3 years ago

问一下,您说的out of index 是predict输出成文件部分的列表越界错误吗?作者好像在代码里加了注释说他也不清楚为什么。我测试了一下,发现它有的把CLS和SEP都预测错了,导致解码失败。我觉得可以强制规定预测的第一个元素就是[CLS],最后一个元素就是[SEP]。

您好,您解决了吗,就是预测的时候,出现out of index。具体怎么改能指导一下吗?方便的话可以qq联系吗(642516257,微信同号)

OK

您好,可以把方法po出来吗?具体怎么改呢?

# 预测样本和实体写一起写文件
with open(output_predict_file,"w",encoding="utf-8") as f:
    for example, prediction in zip(predict_examples,result):
        item_id=0
        line=""
        line_token=str(example.text_a).split(' ')
        label_token=str(example.label).split(' ')
        if len(line_token)!=len(label_token):
            tf.logging.info(example.text_a)
            tf.logging.info(example.label)

        for i,id in np.ndenumerate(prediction) :
            # 填充的部分舍弃
            if id ==0:
                continue
            cur_label=id2label[id]

            # CLS和SEP舍弃
            if cur_label in ["[CLS]","[SEP]"]:
                continue
            # i[0]是prediction的索引,,第一个元素如不是[CLS],强制规定为[CLS],跳过
            if i[0]==0 and cur_label!="[CLS]":
                print("c",i[0],line_token)
                continue
            # 最后一个元素(或是填充前的最后一个元素)如不是[SEP],强制规定为[SEP],跳过
            if i[0]+1>=len(prediction) or prediction[i[0]+1]==0:
                if cur_label!="[SEP]":
                    print("s",i[0], line_token)
                    continue
            try:
                line+=line_token[item_id]+" "+label_token[item_id]+" "+ cur_label + '\n'
                #line += line_token[item_id] + " " + cur_label + '\n'
            except Exception as e:
                tf.logging.info(e)
                tf.logging.info(example.text_a)
                tf.logging.info(example.label)
                line=""
                break
            item_id+=1

        f.write(line+"\n")

我这里把作者的result_to_pair函数的内容直接写在with open里面了,一些变量名字可能和作者的不一样,方法比较笨,但至少不报错了

cjwen15 commented 3 years ago

问一下,您说的out of index 是predict输出成文件部分的列表越界错误吗?作者好像在代码里加了注释说他也不清楚为什么。我测试了一下,发现它有的把CLS和SEP都预测错了,导致解码失败。我觉得可以强制规定预测的第一个元素就是[CLS],最后一个元素就是[SEP]。

您好,您解决了吗,就是预测的时候,出现out of index。具体怎么改能指导一下吗?方便的话可以qq联系吗(642516257,微信同号)

OK

您好,可以把方法po出来吗?具体怎么改呢?

# 预测样本和实体写一起写文件
with open(output_predict_file,"w",encoding="utf-8") as f:
    for example, prediction in zip(predict_examples,result):
        item_id=0
        line=""
        line_token=str(example.text_a).split(' ')
        label_token=str(example.label).split(' ')
        if len(line_token)!=len(label_token):
            tf.logging.info(example.text_a)
            tf.logging.info(example.label)

        for i,id in np.ndenumerate(prediction) :
            # 填充的部分舍弃
            if id ==0:
                continue
            cur_label=id2label[id]

            # CLS和SEP舍弃
            if cur_label in ["[CLS]","[SEP]"]:
                continue
            # i[0]是prediction的索引,,第一个元素如不是[CLS],强制规定为[CLS],跳过
            if i[0]==0 and cur_label!="[CLS]":
                print("c",i[0],line_token)
                continue
            # 最后一个元素(或是填充前的最后一个元素)如不是[SEP],强制规定为[SEP],跳过
            if i[0]+1>=len(prediction) or prediction[i[0]+1]==0:
                if cur_label!="[SEP]":
                    print("s",i[0], line_token)
                    continue
            try:
                line+=line_token[item_id]+" "+label_token[item_id]+" "+ cur_label + '\n'
                #line += line_token[item_id] + " " + cur_label + '\n'
            except Exception as e:
                tf.logging.info(e)
                tf.logging.info(example.text_a)
                tf.logging.info(example.label)
                line=""
                break
            item_id+=1

        f.write(line+"\n")

我这里把作者的result_to_pair函数的内容直接写在with open里面了,一些变量名字可能和作者的不一样,方法比较笨,但至少不报错了

感谢!!我现在就去试一下!