永远坚定 2023-03-22 08:17 采纳率: 66.7%
浏览 34
已结题

spacy中文实体识别

在用annotations时,有一行总是报错,'tuple' object has no attribute 'get'哪位能帮忙看看,万分感谢

 for ent in annotations.get('entities'):
        ner.add_label(ent[2])


TRAIN_DATA = (“Higher School Certificate, Parramatta Marist High School, Westmead (1998)”,{“entities”:[(0,25,”degree”),(27,56,”school_name”),(58,66,”location”),(68,72,”date”)]}),

(“Bachelor of Business, University of Western Sydney (2005) “,{“entities”:[(0,20,”degree”),(22,43,”school_name”),(44,50,”location”),(52,56,”date”)]}),

(“20072010 BCA (Bachelor of Computer Application) from Khalsa college for women, Amritsar (Affiliated to Guru Nanak Dev University (G.N.D.U) India “,{“entities”:[(0,9,”date”),(12,50,”degree”),(54,78,”school_name”),(80,88,”location”)]}),

(“20102013 MCA (Masters in Computer Applications) from Amritsar College of Engineering, Amritsar (Affiliated to Punjab Technical University (P.T.U) India. “,{“entities”:[(0,9,”date”),(10,48,”degree”),(54,85,”school_name”),(87,95,”location”)]})

```

  • 写回答

2条回答 默认 最新

  • 元气少女缘结神 2023-03-22 09:19
    关注

    你的TRAIN_DATA加个[]如下所示,你可以先跑下下面的看是否一样OK:

    TRAIN_DATA = [
        ('Who is Shaka Khan?', {
            'entities': [(7, 17, 'PERSON')] 
        }),
        ('I like London and Berlin.', {
            'entities': [(7, 13, 'LOC'), (18, 24, 'LOC')]
        })
    ]
    for _, annotations in TRAIN_DATA:
            for ent in annotations.get('entities'):
                print('hello !')
    
    

    img

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 3月30日
  • 已采纳回答 3月22日
  • 创建了问题 3月22日