DocRED Document-Level Relation Extraction
Mark entities and link them with relations using span and span_link, plus an hf-relation model_training block. Sample documents are original and illustrative.
Get This Design
Clone or download from the repository
Quick start:
git clone https://github.com/davidjurgens/potato-showcase.git
cd potato-showcase/text/information-extraction/docred-document-relation-extraction
potato start config.yamlAbout this dataset
DocRED is a large-scale dataset for relation extraction across a whole document, built by Yao and nine co-authors and published at ACL 2019. The documents are Wikipedia introductions, and the labels name entities, the relations between entities, and the sentences that support each relation. The paper defines 96 relation types.
In the protocol, annotators work in four stages that cover distant labels, entity mentions and coreference, Wikidata linking, and relations with supporting evidence. In the last stage annotators review the recommended relations, remove the incorrect ones, and supplement omitted ones. The design shows a span scheme for the six entity types in the paper and a span_link scheme with six of the relation types, country, part of, creator, educated at, spouse, and publication date. In the multi-stage protocol, the recommend-then-review stage maps to the model_training writeback block, and chaining stages across different annotators would use data_files filter_by_prior_annotation. From Potato 2.15.0, the pre_annotation export format writes the answers of one stage as the predictions_file of the next stage; answers of the span_link schemes are left out.
The design leaves out supporting-evidence sentences, Wikidata links, and coreference merging, and uses 6 of the 96 relation types. Wikipedia text is CC BY-SA, so the ten sample documents are original sentences with invented places and people. The model_training block uses the hf-relation trainer, which learns to tag mentions and to classify pairs of spans from the annotators' own spans and links, then writes predicted spans and links onto documents without annotations for annotators to edit or delete. The trainer needs the train-text extra and does not use DocRED data.
- Relation types in the paper
- 96
- Annotation stages
- 4
- Relation types in this design
- 6
- Sample documents in this design
- 10 (original, illustrative)
Configuration File
This Potato config reproduces the annotation task. Save it as config.yaml and run potato start config.yaml to try it.
# yaml-language-server: $schema=https://potatoannotator.readthedocs.io/en/latest/schemas/potato-config.schema.json
# DocRED: A Large-Scale Document-Level Relation Extraction Dataset
# Yao, Ye, Li, Han, Lin, Liu, Liu, Huang, Zhou, and Sun. ACL 2019, Florence, pp. 764-777.
# DOI: 10.18653/v1/P19-1074 Anthology: https://aclanthology.org/P19-1074/
# Data: https://huggingface.co/datasets/thunlp/docred (the dataset card header reads license: mit)
# Code: https://github.com/thunlp/DocRED (MIT)
# The source documents are Wikipedia introductions, which are CC BY-SA, so no DocRED text is shipped. The ten documents below are
# original sentences written for this design and illustrative. The places and people in them are invented.
#
# Protocol (paper sec. 2.1): four stages, which are distant labels, entity mentions and coreference, Wikidata linking, and relations
# with supporting evidence. In the last stage annotators "review the recommendations, remove the incorrect relation instances and
# supplement omitted ones". Entity types (Stage 2): "person, location, organization, time, number and names of miscellaneous
# entities". There are 96 relation types, and the six used here (country, part of, creator, educated at, spouse, publication date)
# appear in the paper's own example figure.
#
# Multi-stage protocol: the recommend-then-review stage maps to model_training.writeback below. A trainer fitted on earlier labels
# writes its predicted spans and links onto documents without annotations, and the next annotator edits or deletes them. The entity,
# coreference, and Wikidata stages are not separate here. Chaining stages across different annotators would use
# data_files[].filter_by_prior_annotation, which this design does not set.
# From Potato 2.15.0, the pre_annotation export format (python -m potato.export --format pre_annotation)
# writes stage 1's answers as the next stage's predictions_file. Answers of the span_link schemes are left out
# with a warning.
#
# Adaptations:
# 1. Six of the 96 relation types are used.
# 2. Supporting-evidence sentences and Wikidata links are not collected, and coreference is not merged.
# 3. The abbreviations PER, LOC, ORG, TIME, NUM, and MISC are this config's. The paper uses the type words only.
#
# model_training uses the hf-relation trainer (potato/training/registry.py, kind relation, reached through span_link). It fits a
# tagger for mentions and a classifier for pairs of spans on the annotators' own spans and links. It needs
# pip install 'potato-annotation[train-text]'. Open /admin/training with the key below, pick hf-relation and the relations scheme,
# and click Train now. It does not use any DocRED data, and the labels come from the annotators of this study.
annotation_task_name: "Document-level relations between entities (DocRED labels)"
data_files:
- sample-data.json
item_properties:
id_key: id
text_key: text
task_dir: .
output_annotation_dir: annotation_output
export_annotation_format: jsonl
# Replace the admin key with your own value before a real study.
admin_api_key: "demo-admin-key"
annotation_schemes:
- annotation_type: span
name: entities
description: "Highlight every entity mention."
labels:
- {name: PER, tooltip: "person", color: "#3b82f6"}
- {name: LOC, tooltip: "location", color: "#f59e0b"}
- {name: ORG, tooltip: "organization", color: "#22c55e"}
- {name: TIME, tooltip: "time", color: "#8b5cf6"}
- {name: NUM, tooltip: "number", color: "#06b6d4"}
- {name: MISC, tooltip: "names of miscellaneous entities", color: "#ec4899"}
- annotation_type: span_link
name: relations
description: "Link the spans whose relation the document states."
span_schema: entities
link_types:
- {name: country, directed: true, allowed_source_labels: [LOC, ORG, MISC], allowed_target_labels: [LOC], color: "#dc2626"}
- {name: part_of, directed: true, allowed_source_labels: [LOC, ORG, MISC], allowed_target_labels: [LOC, ORG, MISC], color: "#8b5cf6"}
- {name: creator, directed: true, allowed_source_labels: [MISC], allowed_target_labels: [PER, ORG], color: "#14b8a6"}
- {name: educated_at, directed: true, allowed_source_labels: [PER], allowed_target_labels: [ORG], color: "#f97316"}
- {name: spouse, directed: false, allowed_source_labels: [PER], allowed_target_labels: [PER], color: "#ec4899"}
- {name: publication_date, directed: true, allowed_source_labels: [MISC], allowed_target_labels: [TIME], color: "#06b6d4"}
visual_display: {enabled: true, arc_position: above, show_labels: true}
model_training:
enabled: true
writeback:
schemas: [relations]
include_unlabeled: true
min_confidence: 0.6
user_config:
allow_all_users: true
annotation_instructions: |
Mark each entity mention, then link two mentions when the document itself states the relation. Do not use outside knowledge.
Sample Data
[
{
"id": "dr_001",
"text": "Marlow Quay is a harbor town in Veldmark, a province of Norland. The town was founded in 1612."
},
{
"id": "dr_002",
"text": "Ines Varga studied at the University of Brelm. She married the sculptor Tomas Reyne in 1954, and her novel The Glass Orchard was published in 1961."
}
]
// ... and 8 more itemsGet This Design
Clone or download from the repository
Quick start:
git clone https://github.com/davidjurgens/potato-showcase.git
cd potato-showcase/text/information-extraction/docred-document-relation-extraction
potato start config.yamlDataset & paper
Yao et al., ACL 2019
- Paper DOI
- 10.18653/v1/P19-1074
Citation (BibTeX)
@inproceedings{yao-etal-2019-docred,
title = "{D}oc{RED}: A Large-Scale Document-Level Relation Extraction Dataset",
author = "Yao, Yuan and Ye, Deming and Li, Peng and Han, Xu and Lin, Yankai and Liu, Zhenghao and Liu, Zhiyuan and Huang, Lixin and Zhou, Jie and Sun, Maosong",
editor = "Korhonen, Anna and Traum, David and M{\`a}rquez, Llu{\'i}s",
booktitle = "Proceedings of the 57th Annual Meeting of the {A}ssociation for {C}omputational {L}inguistics",
month = jul,
year = "2019",
address = "Florence, Italy",
publisher = "Association for Computational Linguistics",
url = "https://aclanthology.org/P19-1074/",
doi = "10.18653/v1/P19-1074",
pages = "764--777"
}Details
Annotation Types
Domain
Use Cases
Tags
Found an issue or want to improve this design?
Open an Issue(opens in a new tab)Related Designs
CrossRE: Cross-Domain Relation Extraction
Cross-domain relation extraction across 6 domains (news, politics, science, music, literature, AI). Annotators identify entities and label 17 relation types between entity pairs, enabling study of domain transfer in relation extraction.
MultiTACRED Multilingual Relation Extraction Dataset
MultiTACRED machine-translates the TACRED relation extraction dataset into 12 languages, keeping 41 TAC relation types plus no_relation. This Potato config reproduces the entity-pair relation task.
REDFM: Filtered and Multilingual Relation Extraction
Multilingual relation extraction across 7 human-revised languages (Arabic, Chinese, English, French, German, Italian, Spanish) derived from Wikidata. Annotators verify entity spans and label relations using Wikidata relation types. The larger automatically-annotated SREDFM dataset covers 18 languages and 400 relation types.