DeepKE icon indicating copy to clipboard operation
DeepKE copied to clipboard

使用自己数据集,在进行数据处理(preprocess.py)时出现的问题

Open lelechallc opened this issue 4 years ago • 3 comments

Describe the question

A clear and concise description of what the question is. 使用自己数据集,在进行数据处理(preprocess.py)时出现中文句子分词后找不到给定的tail。 具体数据在下面展示: 请问这样的情况如何处理?? Traceback (most recent call last): File "run.py", line 51, in main preprocess(cfg) File "/data/luocheng_lin/myproject/deepke/DeepKE/src/deepke/relation_extraction/standard/tools/preprocess.py", line 217, in preprocess _serialize_sentence(train_data, serial, cfg) File "/data/luocheng_lin/myproject/deepke/DeepKE/src/deepke/relation_extraction/standard/tools/preprocess.py", line 99, in _serialize_sentence head_idx, tail_idx = d['tokens'].index('head'), d['tokens'].index('tail') ValueError: 'tail' is not in list

Set the environment variable HYDRA_FULL_ERROR=1 for a complete stack trace.

报错代码位置如下: DeepKE/src/deepke/relation_extraction/standard/tools/preprocess.py def _serialize_sentence(data: List[Dict], serial, cfg): """ 将句子分词 Args : data (List[Dict]) : 数据集合 serial (Class): Serializer类 cfg : 配置文件 """ for d in data: sent = d['sentence'].strip() if d['head'] in d['tail']: sent = sent.replace(d['tail'], ' tail ', 1).replace(d['head'], ' head ', 1) else: sent = sent.replace(d['head'], ' head ', 1).replace(d['tail'], ' tail ', 1) d['tokens'] = serial(sent, never_split=['head', 'tail'])###这里!!! head_idx, tail_idx = d['tokens'].index('head'), d['tokens'].index('tail') d['head_idx'], d['tail_idx'] = head_idx, tail_idx

数据如下: d: {'sentence': '11埃尔摩尔·史密斯毕业于肯塔基州立大学,在1971年第1轮第3位被布法罗勇敢者队(现洛杉矶快船队)选中,职业生涯曾效力于布法罗勇敢者队、洛杉矶湖人队、密尔沃基雄鹿队以及克里夫兰骑士队,1974年荣膺NBA盖帽王', 'relation': '简称', 'head': '洛杉矶快船队', 'head_offset': '43', 'tail': '快船', 'tail_offset': '46', 'rel2idx': 43, 'head_type': '机构', 'tail_type': 'Text'}

d['tokens']: ['11', '埃尔', '摩尔', '·', '史密斯', '毕业', '于', '肯塔基州', '立', '大学', ',', '在', '1971', '年', '第', '1', '轮', '第', '3', '位', '被', '布法罗', '勇敢者', '队', '(', '现', 'head', ')', '选中', ',', '职业生涯', '曾效力', '于', '布法罗', '勇敢��', '队', '、', '洛杉矶', '湖人队', '、', '密尔沃基', '雄鹿队', '以及', '克里夫兰', '骑士队', ',', '1974', '年', '荣膺', 'nba', '盖帽', '王']

Screenshots

lelechallc avatar Apr 29 '22 06:04 lelechallc

你好,你这个问题呢,是因为一个实体包含了另一个实体,才没找到tail,如果遇到这种问题,我建议把两个实体分开来,如上句中改为洛杉矶快船(快船)。

tlk1997 avatar Apr 29 '22 06:04 tlk1997

你好,你这个问题呢,是因为一个实体包含了另一个实体,才没找到tail,如果遇到这种问题,我建议把两个实体分开来,如上句中改为洛杉矶快船(快船)。 你好,你的意思是修改原本数据吗,但是这个数据量太大了,没法修改原数据的话,该模型是不是没法使用呢??

lelechallc avatar Apr 29 '22 12:04 lelechallc

你可以在preprocess.py里增加修改数据的代码,增加代码的目的就是将重合头围实体进行转换

tlk1997 avatar Apr 29 '22 12:04 tlk1997