Hassan Shavarani
commited on
Commit
•
207e462
1
Parent(s):
280be02
Upload 5 files
Browse files- .gitattributes +2 -0
- README.md +11 -3
- data.jsonl +3 -0
- enes.json +0 -0
- entity_annotations.json +3 -0
- example_data_reader.py +108 -0
.gitattributes
CHANGED
@@ -53,3 +53,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
53 |
*.jpg filter=lfs diff=lfs merge=lfs -text
|
54 |
*.jpeg filter=lfs diff=lfs merge=lfs -text
|
55 |
*.webp filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
53 |
*.jpg filter=lfs diff=lfs merge=lfs -text
|
54 |
*.jpeg filter=lfs diff=lfs merge=lfs -text
|
55 |
*.webp filter=lfs diff=lfs merge=lfs -text
|
56 |
+
data.jsonl filter=lfs diff=lfs merge=lfs -text
|
57 |
+
entity_annotations.json filter=lfs diff=lfs merge=lfs -text
|
README.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
This dataset was originally created in August 2018 and was published in Multi-class Multilingual Classification of Wikipedia Articles Using Extended Named Entity Tag Set in LREC'20 (https://aclanthology.org/2020.lrec-1.150.pdf).
|
2 |
+
|
3 |
+
|
4 |
+
Description of the data files
|
5 |
+
=============================
|
6 |
+
* `enes.json`: This file contains the annotation classes originally provided in the 'Extended Named Entity Hierarchy'. You can find more information about this in the 'Extended Named Entity Hierarchy' (http://www.lrec-conf.org/proceedings/lrec2002/pdf/120.pdf)
|
7 |
+
* `entity_annotations.json`: This file includes hand annotations for Japanese Wikipedia pages along with Wikipedia page IDs of equivalent pages in English, French, German, and Farsi Wikipedia (wherever an equivalent page has been available).
|
8 |
+
* `data.jsonl`: This standalone JSONL format file combines the information from `enes.json` and `entity_annotations.json` with downloaded Wikipedia articles. The articles were downloaded from Wikipedia during the last week of April 2024.
|
9 |
+
* `example_data_reader.py`: This Python script provides an example data reader aimed at expediting the process of parsing and utilizing the data files.
|
10 |
+
|
11 |
+
If you have any questions or need assistance, feel free to reach out to Hassan S. Shavarani (sshavara@sfu.ca).
|
data.jsonl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:84d6045a9fa1fadab72d39b449b7835d930b831c887982c1085e392067902e87
|
3 |
+
size 2608111439
|
enes.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
entity_annotations.json
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:7e8cd16d2e6ee2512253d9ffb16bf114c49aae1689bb9f5ce854e662989b49f7
|
3 |
+
size 101316621
|
example_data_reader.py
ADDED
@@ -0,0 +1,108 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
Example data reader for the annotated SHINRA-5LDS
|
3 |
+
Created May 2, 2024.
|
4 |
+
Copyright Hassan S. Shavarani
|
5 |
+
"""
|
6 |
+
import json
|
7 |
+
import datetime
|
8 |
+
from zipfile import ZipFile
|
9 |
+
from tqdm import tqdm
|
10 |
+
from collections import namedtuple
|
11 |
+
|
12 |
+
ENELabel = namedtuple('ENELabel', ['level_id', 'name'])
|
13 |
+
|
14 |
+
|
15 |
+
class ENEAnnotation:
|
16 |
+
def __init__(self, ann):
|
17 |
+
self.ene_id = ann['ene_id']
|
18 |
+
self.representative_name = ann['representative_name']
|
19 |
+
self._id = int(ann['_id'])
|
20 |
+
self.original_level = ann['original_level']
|
21 |
+
self.values = {x['level']: ENELabel(x['level_id'], x['name']) for x in ann['entities']}
|
22 |
+
|
23 |
+
class SHINRAAnnotation:
|
24 |
+
def __init__(self, annotation):
|
25 |
+
self.lang = annotation['lang'] # this value is always equal to 'ja' since all original annotations have been assigned in Japanese
|
26 |
+
self.annotator = annotation['annotator']
|
27 |
+
self.annotation_date = datetime.datetime.strptime(annotation['date'], '%Y-%m-%d %H:%M:%S')
|
28 |
+
self.raw_flag = annotation['raw_flag']
|
29 |
+
self.type = annotation['type']
|
30 |
+
self.annotation_confidence = annotation['probability_score']
|
31 |
+
self.labels = ENEAnnotation(annotation['ene_id'])
|
32 |
+
|
33 |
+
|
34 |
+
class SHINRAArticle:
|
35 |
+
def __init__(self, article):
|
36 |
+
self.title = article['title']
|
37 |
+
self.content = article['content']
|
38 |
+
self.url = article['url']
|
39 |
+
self.page_id = article['page_id']
|
40 |
+
self.links = article['links']
|
41 |
+
self.summary = article['summary']
|
42 |
+
self.categories = article['categories']
|
43 |
+
|
44 |
+
class SHINRARecord:
|
45 |
+
def __init__(self, record):
|
46 |
+
self.annotation_id = record['annotation_id']
|
47 |
+
self.ene_level_ids = {
|
48 |
+
"0": record['ene_level_ids']['level0'],
|
49 |
+
"1": record['ene_level_ids']['level1'],
|
50 |
+
"2": record['ene_level_ids']['level2'],
|
51 |
+
"3": record['ene_level_ids']['level3']
|
52 |
+
}
|
53 |
+
self.ene_label_verified = record['ene_label_verified']
|
54 |
+
self.annotations = [SHINRAAnnotation(x) for x in record['annotations'] if x['annotator'] == 'HAND']
|
55 |
+
self.articles = {x['language']: SHINRAArticle(x) for x in record['annotation_articles']}
|
56 |
+
|
57 |
+
@property
|
58 |
+
def latest_annotation(self):
|
59 |
+
return max(self.annotations, key=lambda x: x.annotation_date)
|
60 |
+
|
61 |
+
class SHINRA5LDS:
|
62 |
+
"""
|
63 |
+
Size of the SHINRA-5LDS dataset (considering only the hand annotated records):
|
64 |
+
ja: 118635 records
|
65 |
+
en: 52445 records
|
66 |
+
fr: 34432 records
|
67 |
+
de: 29808 records
|
68 |
+
fa: 14058 records
|
69 |
+
"""
|
70 |
+
def __init__(self, zip_file_path, lang):
|
71 |
+
self.zip_file_path = zip_file_path
|
72 |
+
self.data = None
|
73 |
+
self.lang = lang
|
74 |
+
|
75 |
+
def _load_data(self):
|
76 |
+
zip_ref = ZipFile(self.zip_file_path, 'r')
|
77 |
+
self.data = zip_ref.open('data.jsonl')
|
78 |
+
|
79 |
+
def __iter__(self):
|
80 |
+
if self.data is None or len(self.data) == 0:
|
81 |
+
self._load_data()
|
82 |
+
return self
|
83 |
+
|
84 |
+
def __next__(self):
|
85 |
+
try:
|
86 |
+
while True:
|
87 |
+
next_line = self.data.readline()
|
88 |
+
if not next_line:
|
89 |
+
self.data.close()
|
90 |
+
self.data = None
|
91 |
+
raise IndexError
|
92 |
+
record = SHINRARecord(json.loads(next_line))
|
93 |
+
if not record.annotations: # the annotation is machine generated
|
94 |
+
continue
|
95 |
+
if self.lang in record.articles:
|
96 |
+
break
|
97 |
+
return record.articles[self.lang], record.latest_annotation
|
98 |
+
except IndexError:
|
99 |
+
raise StopIteration
|
100 |
+
except Exception as e:
|
101 |
+
print(f"Error: {e}")
|
102 |
+
return self.__next__()
|
103 |
+
|
104 |
+
if __name__ == "__main__":
|
105 |
+
for article, annotation in tqdm(SHINRA5LDS('SHINRA-5LDS.zip', 'en')):
|
106 |
+
print('='*80)
|
107 |
+
print(article.title, annotation.labels.values)
|
108 |
+
print('='*80)
|