Giter VIP home page Giter VIP logo

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

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

from name-entity-recognition.

Comments (6)

Heaven-zhw avatar Heaven-zhw commented on May 18, 2024

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

from name-entity-recognition.

yt-liang avatar yt-liang commented on May 18, 2024

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

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

from name-entity-recognition.

Heaven-zhw avatar Heaven-zhw commented on May 18, 2024

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

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

OK

from name-entity-recognition.

cjwen15 avatar cjwen15 commented on May 18, 2024

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

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

OK

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

from name-entity-recognition.

Heaven-zhw avatar Heaven-zhw commented on May 18, 2024

问一下,您说的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里面了,一些变量名字可能和作者的不一样,方法比较笨,但至少不报错了

from name-entity-recognition.

cjwen15 avatar cjwen15 commented on May 18, 2024

问一下,您说的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里面了,一些变量名字可能和作者的不一样,方法比较笨,但至少不报错了

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

from name-entity-recognition.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.