Datasets:

Modalities:
Text
ArXiv:
Libraries:
Datasets
ngrislain commited on
Commit
aa8f517
·
1 Parent(s): 19fe58a
Files changed (2) hide show
  1. README.md +4 -0
  2. phee.py +119 -0
README.md ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ # PHEE dataset
2
+
3
+ This dataset is port of https://github.com/ZhaoyueSun/PHEE,
4
+ the data used in: [``PHEE: A Dataset for Pharmacovigilance Event Extraction from Text``](https://arxiv.org/abs/2210.12560/)
phee.py ADDED
@@ -0,0 +1,119 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """PHEE: A Dataset for Pharmacovigilance Event Extraction from Text"""
2
+
3
+
4
+ import json
5
+
6
+ import datasets
7
+ from datasets.tasks import LanguageModeling
8
+
9
+
10
+ logger = datasets.logging.get_logger(__name__)
11
+
12
+
13
+ _CITATION = """\
14
+ @misc{sun2022phee,
15
+ title={PHEE: A Dataset for Pharmacovigilance Event Extraction from Text},
16
+ author={Zhaoyue Sun and Jiazheng Li and Gabriele Pergola and Byron C. Wallace and Bino John and Nigel Greene and Joseph Kim and Yulan He},
17
+ year={2022},
18
+ eprint={2210.12560},
19
+ archivePrefix={arXiv},
20
+ primaryClass={cs.CL}
21
+ }
22
+ """
23
+
24
+ _DESCRIPTION = """\
25
+ Data and Code for [``PHEE: A Dataset for Pharmacovigilance Event Extraction from Text``](https://arxiv.org/abs/2210.12560/)\
26
+ """
27
+
28
+ _URL = "https://raw.githubusercontent.com/ZhaoyueSun/PHEE/ceea192bc1f1da306980c39e53767176b1f8caec/data/json/"
29
+ _URLS = {
30
+ "train": _URL + "train.json",
31
+ "test": _URL + "test.json",
32
+ "dev": _URL + "dev.json",
33
+ }
34
+
35
+
36
+ class PHEEConfig(datasets.BuilderConfig):
37
+ """BuilderConfig for PHEE."""
38
+
39
+ def __init__(self, **kwargs):
40
+ """BuilderConfig for PHEE.
41
+
42
+ Args:
43
+ **kwargs: keyword arguments forwarded to super.
44
+ """
45
+ super(PHEEConfig, self).__init__(**kwargs)
46
+
47
+
48
+ class PHEE(datasets.GeneratorBasedBuilder):
49
+ """PHEE: A Dataset for Pharmacovigilance Event Extraction from Text"""
50
+
51
+ BUILDER_CONFIGS = [
52
+ PHEEConfig(
53
+ name="json",
54
+ version=datasets.Version("1.0.0", ""),
55
+ description="processed structured data",
56
+ ),
57
+ ]
58
+
59
+ def _info(self):
60
+ return datasets.DatasetInfo(
61
+ description=_DESCRIPTION,
62
+ homepage="https://github.com/ZhaoyueSun/PHEE",
63
+ features=datasets.Features(
64
+ {
65
+ "id": datasets.Value("string"),
66
+ "context": datasets.Value("string"),
67
+ "is_mult_event": datasets.Value("bool"),
68
+ "annotations": [
69
+ {
70
+ "events": [
71
+ {
72
+ "event_id": datasets.Value("string"),
73
+ "event_type": datasets.Value("string"),
74
+ "event_data": datasets.Value("string"),
75
+ }
76
+ ]
77
+ }
78
+ ],
79
+ }
80
+ ),
81
+ citation=_CITATION,
82
+ task_templates=[
83
+ LanguageModeling(
84
+ text_column="context",
85
+ )
86
+ ],
87
+ )
88
+
89
+ def _split_generators(self, dl_manager):
90
+ downloaded_files = dl_manager.download_and_extract(_URLS)
91
+
92
+ return [
93
+ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}),
94
+ datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": downloaded_files["test"]}),
95
+ datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files["dev"]}),
96
+ ]
97
+
98
+ def _generate_examples(self, filepath):
99
+ """This function returns the examples parsed from json."""
100
+ logger.info("generating examples from = %s", filepath)
101
+ with open(filepath, encoding="utf-8") as f:
102
+ for key, line in enumerate(f):
103
+ obs = json.loads(line)
104
+ yield key, {
105
+ "id": obs["id"],
106
+ "context": obs["context"],
107
+ "is_mult_event": obs["is_mult_event"],
108
+ "annotations": [
109
+ {
110
+ "events": [
111
+ {
112
+ "event_id": event["event_id"],
113
+ "event_type": event["event_type"],
114
+ "event_data": json.dumps(event),
115
+ }
116
+ for event in annotation["events"]]
117
+ }
118
+ for annotation in obs["annotations"]],
119
+ }