网站做301跳转的方法,云计算运维工程师,嘉兴网站制作网站建设,乐清在线网引言
RAMS数据集#xff08;RAMS#xff1a;Richly Annotated Multilingual Schema-guided Event Structure#xff09;由约翰斯霍普金斯大学于2020年发布#xff0c;是一个以新闻为基础的事件抽取数据集。它标注了9,124个事件#xff0c;涵盖了139种不同的事件类型和65种…引言
RAMS数据集RAMSRichly Annotated Multilingual Schema-guided Event Structure由约翰斯·霍普金斯大学于2020年发布是一个以新闻为基础的事件抽取数据集。它标注了9,124个事件涵盖了139种不同的事件类型和65种元素角色类型。事件类型涉及多个领域如
生命事件life冲突事件conflict灾难事件disaster司法事件justice联络事件contact政府事件government
而元素角色类型包括如
地点place参与者participant目的地destination起源origin受害者victim被告人defendant
这个数据集非常适合用于事件抽取、自然语言处理任务特别是对事件结构、事件角色的识别和分类。
一、特点features
事件类型多样化涵盖多个领域增强了事件抽取任务的广泛性和复杂性。角色标注详细为每个事件详细标注了不同的角色为构建事件图、进行因果推理等任务提供了丰富的上下文信息。结构化标注不仅仅提供文本还为每个事件及其参与者标注了详细的语义信息使其适用于高层次的文本分析。
二、下载download
可以通过访问官方下载网站进行最新和历史数据集的下载。也可以通过访问我的主页提供的数据集来进行下载。
三、数据集database
3.1 数据
数据被分成 train/dev/test 三个文件 每个数据文件的每一行包含一个 json 字符串 每个 json 包含
ent_spans开始和结束包含索引以及事件/参数/角色字符串。evt_triggers开始和结束包括索引以及事件类型字符串。sentences文档文本gold_evt_links遵循上述格式的三元组事件、论点、角色source_url文本来源split它属于哪个数据分割doc_key它对应于哪个单独的文件 添加到所有文件前面
所有其他字段都是多余的以允许 RAMS 的未来迭代。
格式化之后的一条数据train.jsonlines的第1行如下展示
{rel_triggers: [],gold_rel_links: [],doc_key: nw_RC000462ebb18ca0b29222d5e557fa31072af8337e3a0910dca8b5b62f,ent_spans: [[42,43,[[evt090arg02victim,1.0]]],[85,88,[[evt090arg01killer,1.0]]],[26,26,[[evt090arg04place,1.0]]]],language_id: eng,source_url: https://www.washingtonpost.com/news/powerpost/paloma/daily-202/2016/06/17/daily-202-more-republicans-ditch-trump-conclude-he-cannot-win/5763a1e0981b92a22d0f8a36/,evt_triggers: [[69,69,[[life.die.deathcausedbyviolentevents,1.0]]]],split: train,sentences: [[Transportation,officials,are,urging,carpool,and,teleworking,as,options,to,combat,an,expected,flood,of,drivers,on,the,road,.],[(,Paul,Duggan,)],[--,A,Baltimore,prosecutor,accused,a,police,detective,of,\u201c,sabotaging,\u201d,investigations,related,to,the,death,of,Freddie,Gray,,,accusing,him,of,fabricating,notes,to,suggest,that,the,state,\u2019s,medical,examiner,believed,the,manner,of,death,was,an,accident,rather,than,a,homicide,.],[The,heated,exchange,came,in,the,chaotic,sixth,day,of,the,trial,of,Baltimore,Officer,Caesar,Goodson,Jr.,,,who,drove,the,police,van,in,which,Gray,suffered,a,fatal,spine,injury,in,2015,.],[(,Derek,Hawkins,and,Lynh,Bui,)]],gold_evt_links: [[[69,69],[85,88],evt090arg01killer],[[69,69],[42,43],evt090arg02victim],[[69,69],[26,26],evt090arg04place]]
} 1. sentences
文档内容被分为多个句子 句子1Transportation officials are urging carpool and teleworking as options to combat an expected flood of drivers on the road.句子2(Paul Duggan)句子3A Baltimore prosecutor accused a police detective of ‘sabotaging’ investigations related to the death of Freddie Gray.句子4The heated exchange came in the chaotic sixth day of the trial of Baltimore Officer Caesar Goodson Jr.
2. evt_triggers事件触发器
[69, 69] 对应的词是句子3中的 homicide标注事件类型为 life.die.deathcausedbyviolentevents与暴力事件导致的死亡相关。
3. ent_spans实体标注开始和结束索引以及事件角色
[42, 43] 对应的词是句子3中的 Freddie Gray角色为 victim受害者。[85, 88] 对应的词是句子4中的 Caesar Goodson Jr.角色为 killer凶手。[26, 26] 对应的词是句子3中的 Baltimore角色为 place地点。
4. gold_evt_links事件-论点-角色三元组
第一个三元组触发词 homicide论点是 Caesar Goodson Jr.角色是 killer。第二个三元组触发词 homicide论点是 Freddie Gray角色是 victim。第三个三元组触发词 homicide论点是 Baltimore角色是 place。
5. source_url
文档来源是https://www.washingtonpost.com/news/powerpost/paloma/daily-202/2016/06/17/daily-202-more-republicans-ditch-trump-conclude-he-cannot-win/5763a1e0981b92a22d0f8a36/
6. split
样本属于 训练集train。
7. doc_key
对应的文档ID为 nw_RC000462ebb18ca0b29222d5e557fa31072af8337e3a0910dca8b5b62f该ID用于唯一标识文档。
四、数据处理
import jsondef load_data(file_path):data []with open(file_path, r) as f:for line in f:data.append(json.loads(line))return datadef save_to_json(data, file_path):with open(file_path, w) as f:json.dump(data, f, indent4)def extract_event_data(entry):sentences [ .join(s) for s in entry[sentences]]text [item for sublist in entry[sentences] for item in sublist]# text entry[sentences]# text .join(sentences)# 处理实体ent_spans [(span[0], span[1], span[2][0][0]) for span in entry[ent_spans]]# 处理事件触发词evt_triggers [(trigger[0], trigger[1], trigger[2][0][0]) for trigger in entry[evt_triggers]]# 处理事件-论点链接evt_links entry[gold_evt_links]return text, ent_spans, evt_triggers, evt_linksdef prepare_training_data(entries):dataset []for entry in entries:text, ent_spans, evt_triggers, evt_links extract_event_data(entry)# 生成训练样本dataset.append({text: text,entities: ent_spans,triggers: evt_triggers,links: evt_links})return datasetif __name__ __main__:train_data load_data(./train.jsonlines)training_dataset prepare_training_data(train_data)save_to_json(training_dataset, train.json)print(training_dataset[0])4.1 加载并解析数据
首先加载JSON格式的数据文件并解析其中的字段。
import jsondef load_data(file_path):data []with open(file_path, r) as f:for line in f:data.append(json.loads(line))return datatrain_data load_data(train.json)4.2 数据预处理
将文档中的句子、事件触发词、角色和实体进行标注与转换以便用于事件抽取模型。我们可以提取句子、事件触发词及角色信息。
def extract_event_data(entry):sentences [ .join(s) for s in entry[sentences]]text .join(sentences)# 处理实体ent_spans [(span[0], span[1], span[2][0][0]) for span in entry[ent_spans]]# 处理事件触发词evt_triggers [(trigger[0], trigger[1], trigger[2][0][0]) for trigger in entry[evt_triggers]]# 处理事件-论点链接evt_links entry[gold_evt_links]return text, ent_spans, evt_triggers, evt_links# 示例提取
for entry in train_data:text, ent_spans, evt_triggers, evt_links extract_event_data(entry)print(f文本: {text})print(f实体: {ent_spans})print(f事件触发词: {evt_triggers})print(f事件-论点链接: {evt_links})4.3 生成模型输入
为了进行事件抽取常见的输入是文本与相应的事件触发器和角色。我们可以构建一个数据集将文本标注为序列标注任务或使用分类任务标注事件触发词和论点。
def prepare_training_data(entries):dataset []for entry in entries:text, ent_spans, evt_triggers, evt_links extract_event_data(entry)# 生成训练样本dataset.append({text: text,entities: ent_spans,triggers: evt_triggers,links: evt_links})return datasettraining_dataset prepare_training_data(train_data)