DeepKE icon indicating copy to clipboard operation
DeepKE copied to clipboard

DeepKE-cnSchema开箱即用版给出的离谱关系抽取结果

Open Daniel-ChenJH opened this issue 8 months ago • 8 comments

你好,我按here中的指示完成了DeepKE-cnSchema开箱即用版的环境配置。对于一些简短的句子,往往只有两个实体、关系词明确的情况下,程序可以正确预测其中的关系。但是对于稍长、实体略多的情况,这个关系抽取给出的结果比较离谱,而且置信度还挺高。

这里是我predict.yaml的内容,其中两个模型都用的是readme中Bert-wwm的模型。

text: '林忠钦,男,汉族,1957年12月6日出生,浙江省宁波市人,机械工程专家,中国工程院院士,教育部科技委先进制造学部主任。曾任上海交通大学校长、党委副书记。'
nerfp: '/home/cjh/domain/DeepKE/example/ner/standard/checkpoints'
refp: '/home/cjh/domain/DeepKE/example/re/standard/re_bert.pth'

这里句子稍长,我们来看看模型得到了什么,下面是log:

[2024-06-06 14:41:26,132][__main__][INFO] - {'YAS': '人物', 'TOJ': '影视作品', 'NGS': '目', 'QCV': '生物', 'OKB': 'Number', 'BQF': 'Date', 'CAR': '国家', 'ZFM': '网站', 'EMT': '网络小说', 'UER': '图书作品', 'QEE': '歌曲', 'UFT': '地点', 'GJS': '气候', 'SVA': '行政区', 'ANO': 'Text', 'KEJ': '历史人物', 'ZDI': '学校', 'CAT': '企业', 'GCK': '出版社', 'FQK': '书籍', 'BAK': '音乐专辑', 'RET': '城市', 'QZP': '景点', 'QAQ': '电视综艺', 'ZRE': '机构', 'TDZ': '作品', 'CVC': '语言', 'PMN': '学科专业'}
[2024-06-06 14:41:26,133][__main__][INFO] - {'祖籍': 'https://cnschema.openkg.cn/item/%E7%A5%96%E7%B1%8D', '父亲': 'https://cnschema.openkg.cn/item/%E7%88%B6%E4%BA%B2/11999902#viewPageContent', '总部地点': 'https://cnschema.openkg.cn/item/%E6%80%BB%E9%83%A8', '出生地': 'https://null.url.here', '目': 'https://cnschema.openkg.cn/item/%E7%9B%AE/7874912#viewPageContent', '面积': 'https://cnschema.openkg.cn/item/%E9%9D%A2%E7%A7%AF', '简称': 'https://cnschema.openkg.cn/item/%E7%AE%80%E7%A7%B0', '上映时间': 'https://null.url.here', '妻子': 'https://cnschema.openkg.cn/item/%E5%A6%BB%E5%AD%90/52626', '所属专辑': 'https://cnschema.openkg.cn/item/%E4%B8%93%E8%BE%91', '注册资本': 'https://cnschema.openkg.cn/item/%E6%B3%A8%E5%86%8C%E8%B5%84%E6%9C%AC', '首都': 'https://cnschema.openkg.cn/item/%E9%A6%96%E9%83%BD/26194', '导演': 'https://cnschema.openkg.cn/item/%E5%AF%BC%E6%BC%94/307826', '字': 'https://cnschema.openkg.cn/item/%E5%AD%97%E5%8F%B7', '身高': 'https://cnschema.openkg.cn/item/%E8%BA%AB%E9%AB%98', '出品公司': 'https://cnschema.openkg.cn/item/%E5%87%BA%E5%93%81%E4%BA%BA', '修业年限': 'https://cnschema.openkg.cn/item/%E4%BF%AE%E4%B8%9A%E5%B9%B4%E9%99%90', '出生日期': 'https://cnschema.openkg.cn/item/%E7%94%9F%E6%97%A5/2690537', '制片人': 'https://cnschema.openkg.cn/item/%E5%88%B6%E7%89%87%E4%BA%BA/18127#viewPageContent', '母亲': 'https://cnschema.openkg.cn/item/%E6%AF%8D%E4%BA%B2/5511#viewPageContent', '编剧': 'https://cnschema.openkg.cn/item/%E7%BC%96%E5%89%A7/1705096', '国籍': 'https://cnschema.openkg.cn/item/%E5%9B%BD%E7%B1%8D', '海拔': 'https://cnschema.openkg.cn/item/%E6%B5%B7%E6%8B%94/5754', '连载网站': 'https://null.url.here', '丈夫': 'https://cnschema.openkg.cn/item/%E4%B8%88%E5%A4%AB/4404', '朝代': 'https://cnschema.openkg.cn/item/%E6%9C%9D%E4%BB%A3', '民族': 'https://cnschema.openkg.cn/item/%E6%B0%91%E6%97%8F/665', '号': 'https://cnschema.openkg.cn/item/%E5%AD%97%E5%8F%B7', '出版社': 'https://cnschema.openkg.cn/item/%E5%87%BA%E7%89%88%E7%A4%BE', '主持人': 'https://cnschema.openkg.cn/item/%E4%B8%BB%E6%8C%81%E4%BA%BA/4690681', '专业代码': 'https://cnschema.openkg.cn/item/%E6%99%AE%E9%80%9A%E9%AB%98%E7%AD%89%E5%AD%A6%E6%A0%A1%E6%9C%AC%E7%A7%91%E4%B8%93%E4%B8%9A%E7%9B%AE%E5%BD%95?fromtitle=%E4%B8%93%E4%B8%9A%E4%BB%A3%E7%A0%81&fromid=7911485', '歌手': 'https://cnschema.openkg.cn/item/%E6%AD%8C%E6%89%8B/16693#viewPageContent', '作词': 'https://cnschema.openkg.cn/item/%E4%BD%9C%E8%AF%8D', '主角': 'https://cnschema.openkg.cn/item/%E4%B8%BB%E8%A7%92/32402', '董事长': 'https://cnschema.openkg.cn/item/%E8%91%A3%E4%BA%8B%E9%95%BF/356514', '成立日期': 'https://cnschema.openkg.cn/item/%E5%85%AC%E5%8F%B8%E6%88%90%E7%AB%8B/7163008', '毕业院校': 'https://cnschema.openkg.cn/item/%E9%99%A2%E6%A0%A1', '占地面积': 'https://cnschema.openkg.cn/item/%E5%8D%A0%E5%9C%B0%E9%9D%A2%E7%A7%AF', '官方语言': 'https://cnschema.openkg.cn/item/%E5%AE%98%E6%96%B9%E8%AF%AD%E8%A8%80', '邮政编码': 'https://cnschema.openkg.cn/item/%E9%82%AE%E6%94%BF%E7%BC%96%E7%A0%81', '人口数量': 'https://cnschema.openkg.cn/item/%E4%BA%BA%E5%8F%A3%E6%95%B0%E9%87%8F', '所在城市': 'https://cnschema.openkg.cn/item/%E5%9F%8E%E5%B8%82/33549', '作者': 'https://cnschema.openkg.cn/item/%E4%BD%9C%E8%80%85/144157', '作曲': 'https://cnschema.openkg.cn/item/%E4%BD%9C%E6%9B%B2', '气候': 'https://cnschema.openkg.cn/item/%E6%B0%94%E5%80%99/384697', '嘉宾': 'https://cnschema.openkg.cn/item/%E5%98%89%E5%AE%BE/963541', '主演': 'https://cnschema.openkg.cn/item/%E4%B8%BB%E6%BC%94', '改编自': 'https://cnschema.openkg.cn/item/%E6%94%B9%E7%BC%96/3495588#viewPageContent', '创始人': 'https://cnschema.openkg.cn/item/%E5%88%9B%E5%A7%8B%E4%BA%BA/36538'}
[2024-06-06 14:41:26,133][pytorch_transformers.modeling_utils][INFO] - loading configuration file /home/cjh/domain/DeepKE/example/ner/standard/checkpoints/config.json
[2024-06-06 14:41:26,134][pytorch_transformers.modeling_utils][INFO] - Model config {
  "architectures": [
    "BertForMaskedLM"
  ],
  "attention_probs_dropout_prob": 0.1,
  "directionality": "bidi",
  "finetuning_task": "ner",
  "hidden_act": "gelu",
  "hidden_dropout_prob": 0.1,
  "hidden_size": 768,
  "initializer_range": 0.02,
  "intermediate_size": 3072,
  "layer_norm_eps": 1e-12,
  "max_position_embeddings": 512,
  "model_type": "bert",
  "num_attention_heads": 12,
  "num_hidden_layers": 12,
  "num_labels": 60,
  "output_attentions": false,
  "output_hidden_states": false,
  "output_past": true,
  "pad_token_id": 0,
  "pooler_fc_size": 768,
  "pooler_num_attention_heads": 12,
  "pooler_num_fc_layers": 3,
  "pooler_size_per_head": 128,
  "pooler_type": "first_token_transform",
  "pruned_heads": {},
  "torchscript": false,
  "type_vocab_size": 2,
  "vocab_size": 21128
}

[2024-06-06 14:41:26,134][pytorch_transformers.modeling_utils][INFO] - loading weights file /home/cjh/domain/DeepKE/example/ner/standard/checkpoints/pytorch_model.bin
[2024-06-06 14:41:28,036][pytorch_transformers.tokenization_utils][INFO] - Model name '/home/cjh/domain/DeepKE/example/ner/standard/checkpoints' not found in model shortcut name list (bert-base-uncased, bert-large-uncased, bert-base-cased, bert-large-cased, bert-base-multilingual-uncased, bert-base-multilingual-cased, bert-base-chinese, bert-base-german-cased, bert-large-uncased-whole-word-masking, bert-large-cased-whole-word-masking, bert-large-uncased-whole-word-masking-finetuned-squad, bert-large-cased-whole-word-masking-finetuned-squad, bert-base-cased-finetuned-mrpc). Assuming '/home/cjh/domain/DeepKE/example/ner/standard/checkpoints' is a path or url to a directory containing tokenizer files.
[2024-06-06 14:41:28,037][pytorch_transformers.tokenization_utils][INFO] - loading file /home/cjh/domain/DeepKE/example/ner/standard/checkpoints/vocab.txt
[2024-06-06 14:41:28,037][pytorch_transformers.tokenization_utils][INFO] - loading file /home/cjh/domain/DeepKE/example/ner/standard/checkpoints/added_tokens.json
[2024-06-06 14:41:28,037][pytorch_transformers.tokenization_utils][INFO] - loading file /home/cjh/domain/DeepKE/example/ner/standard/checkpoints/special_tokens_map.json
[2024-06-06 14:41:28,037][pytorch_transformers.tokenization_utils][INFO] - loading file /home/cjh/domain/DeepKE/example/ner/standard/checkpoints/tokenizer_config.json
[2024-06-06 14:41:28,053][__main__][INFO] - 林忠钦,男,汉族,1957年12月6日出生,浙江省宁波市人,机械工程专家,中国工程院院士,教育部科技委先进制造学部主任。曾任上海交通大学校长、党委副书记。
[2024-06-06 14:41:28,183][__main__][INFO] - [('林', 'B-YAS'), ('忠', 'I-YAS'), ('钦', 'I-YAS'), ('汉', 'B-ANO'), ('族', 'I-ANO'), ('1', 'B-BQF'), ('9', 'I-BQF'), ('5', 'I-BQF'), ('7', 'I-BQF'), ('年', 'I-BQF'), ('1', 'I-BQF'), ('2', 'I-BQF'), ('月', 'I-BQF'), ('6', 'I-BQF'), ('日', 'I-BQF'), ('浙', 'B-UFT'), ('江', 'I-UFT'), ('省', 'I-UFT'), ('宁', 'I-UFT'), ('波', 'I-UFT'), ('市', 'I-UFT'), ('中', 'B-CAR'), ('国', 'I-CAR')]
[2024-06-06 14:41:28,184][__main__][INFO] - {'林忠钦': '人物', '汉族': 'Text', '1957年12月6日': 'Date', '浙江省宁波市': '地点', '中国': '国家'}
[2024-06-06 14:41:28,184][preprocess][INFO] - use bert tokenizer...
[2024-06-06 14:41:30,245][__main__][INFO] - "林忠钦" 和 "汉族" 在句中关系为:"民族",置信度为1.00。
[2024-06-06 14:41:30,258][__main__][INFO] - {
  "@context": {
    "民族": "https://cnschema.openkg.cn/item/%E6%B0%91%E6%97%8F/665"
  },
  "@id": "林忠钦",
  "民族": {
    "@id": "汉族"
  }
}
[2024-06-06 14:41:30,259][preprocess][INFO] - use bert tokenizer...
[2024-06-06 14:41:31,145][__main__][INFO] - "林忠钦" 和 "1957年12月6日" 在句中关系为:"出生日期",置信度为1.00。
[2024-06-06 14:41:31,145][__main__][INFO] - {
  "@context": {
    "出生日期": "https://cnschema.openkg.cn/item/%E7%94%9F%E6%97%A5/2690537"
  },
  "@id": "林忠钦",
  "出生日期": {
    "@id": "1957年12月6日"
  }
}
[2024-06-06 14:41:31,146][preprocess][INFO] - use bert tokenizer...
[2024-06-06 14:41:31,440][__main__][INFO] - "林忠钦" 和 "浙江省宁波市" 在句中关系为:"出生地",置信度为0.99。
[2024-06-06 14:41:31,441][__main__][INFO] - {
  "@context": {
    "出生地": "https://null.url.here"
  },
  "@id": "林忠钦",
  "出生地": {
    "@id": "浙江省宁波市"
  }
}
[2024-06-06 14:41:31,441][preprocess][INFO] - use bert tokenizer...
[2024-06-06 14:41:31,731][__main__][INFO] - "林忠钦" 和 "中国" 在句中关系为:"国籍",置信度为0.99。
[2024-06-06 14:41:31,731][__main__][INFO] - {
  "@context": {
    "国籍": "https://cnschema.openkg.cn/item/%E5%9B%BD%E7%B1%8D"
  },
  "@id": "林忠钦",
  "国籍": {
    "@id": "中国"
  }
}
[2024-06-06 14:41:31,732][preprocess][INFO] - use bert tokenizer...
[2024-06-06 14:41:32,005][__main__][INFO] - "汉族" 和 "1957年12月6日" 在句中关系为:"出生日期",置信度为0.97。
[2024-06-06 14:41:32,005][__main__][INFO] - {
  "@context": {
    "出生日期": "https://cnschema.openkg.cn/item/%E7%94%9F%E6%97%A5/2690537"
  },
  "@id": "汉族",
  "出生日期": {
    "@id": "1957年12月6日"
  }
}
[2024-06-06 14:41:32,006][preprocess][INFO] - use bert tokenizer...
[2024-06-06 14:41:32,272][__main__][INFO] - "汉族" 和 "浙江省宁波市" 在句中关系为:"民族",置信度为0.55。
[2024-06-06 14:41:32,273][preprocess][INFO] - use bert tokenizer...
[2024-06-06 14:41:32,537][__main__][INFO] - "汉族" 和 "中国" 在句中关系为:"民族",置信度为0.55。
[2024-06-06 14:41:32,537][preprocess][INFO] - use bert tokenizer...
[2024-06-06 14:41:32,846][__main__][INFO] - "1957年12月6日" 和 "浙江省宁波市" 在句中关系为:"出生日期",置信度为0.97。
[2024-06-06 14:41:32,847][__main__][INFO] - {
  "@context": {
    "出生日期": "https://cnschema.openkg.cn/item/%E7%94%9F%E6%97%A5/2690537"
  },
  "@id": "1957年12月6日",
  "出生日期": {
    "@id": "浙江省宁波市"
  }
}
[2024-06-06 14:41:32,847][preprocess][INFO] - use bert tokenizer...
[2024-06-06 14:41:33,219][__main__][INFO] - "1957年12月6日" 和 "中国" 在句中关系为:"出生日期",置信度为0.92。
[2024-06-06 14:41:33,220][__main__][INFO] - {
  "@context": {
    "出生日期": "https://cnschema.openkg.cn/item/%E7%94%9F%E6%97%A5/2690537"
  },
  "@id": "1957年12月6日",
  "出生日期": {
    "@id": "中国"
  }
}
[2024-06-06 14:41:33,220][preprocess][INFO] - use bert tokenizer...
[2024-06-06 14:41:33,526][__main__][INFO] - "浙江省宁波市" 和 "中国" 在句中关系为:"出生地",置信度为0.84。
[2024-06-06 14:41:33,527][__main__][INFO] - {
  "@context": {
    "出生地": "https://null.url.here"
  },
  "@id": "浙江省宁波市",
  "出生地": {
    "@id": "中国"
  }
}

可以看到,这里实体提取分割的结果很好,准确的完成了五个实体({'林忠钦': '人物', '汉族': 'Text', '1957年12月6日': 'Date', '浙江省宁波市': '地点', '中国': '国家'})的分割。但是关系抽取很离谱,到后面输出“ "浙江省宁波市" 和 "中国" 在句中关系为:"出生地",置信度为0.84。”、“"汉族" 和 "浙江省宁波市" 在句中关系为:"民族",置信度为0.55。”、“"1957年12月6日" 和 "浙江省宁波市" 在句中关系为:"出生日期",置信度为0.97。”等等,详见log,并且这些错误的关系提取有时候还有非常高的置信度,甚至有点像将实体胡乱组合的结果。

我不知道怎么样才能让这个模型对于关系预测更加准确、不会出现这些奇怪的关系,有人可以提供任何帮助吗?感谢!

Daniel-ChenJH avatar Jun 06 '24 07:06 Daniel-ChenJH