FatmaZahraZ commited on
Commit
0dfd3aa
·
1 Parent(s): 67184a1

Upload JobDecriptionsEntityRecognition.py

Browse files
Files changed (1) hide show
  1. JobDecriptionsEntityRecognition.py +167 -0
JobDecriptionsEntityRecognition.py ADDED
@@ -0,0 +1,167 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ # coding: utf-8
3
+
4
+ # In[ ]:
5
+
6
+
7
+ # coding=utf-8
8
+ # Copyright 2020 HuggingFace Datasets Authors.
9
+ #
10
+ # Licensed under the Apache License, Version 2.0 (the "License");
11
+ # you may not use this file except in compliance with the License.
12
+ # You may obtain a copy of the License at
13
+ #
14
+ # http://www.apache.org/licenses/LICENSE-2.0
15
+ #
16
+ # Unless required by applicable law or agreed to in writing, software
17
+ # distributed under the License is distributed on an "AS IS" BASIS,
18
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
+ # See the License for the specific language governing permissions and
20
+ # limitations under the License.
21
+
22
+ # Lint as: python3
23
+ """Introduction to the CoNLL-2003 Shared Task: Language-Independent Named Entity Recognition"""
24
+
25
+ import os
26
+
27
+ import datasets
28
+
29
+
30
+ logger = datasets.logging.get_logger(__name__)
31
+
32
+
33
+ _CITATION = """@inproceedings{tjong-kim-sang-de-meulder-2003-introduction,
34
+ title = "Introduction to the {C}o{NLL}-2003 Shared Task: Language-Independent Named Entity Recognition",
35
+ author = "Tjong Kim Sang, Erik F. and
36
+ De Meulder, Fien",
37
+ booktitle = "Proceedings of the Seventh Conference on Natural Language Learning at {HLT}-{NAACL} 2003",
38
+ year = "2003",
39
+ url = "https://www.aclweb.org/anthology/W03-0419",
40
+ pages = "142--147",
41
+ }
42
+ """
43
+
44
+ _DESCRIPTION = """The shared task of CoNLL-2003 concerns language-independent named entity recognition. We will concentrate on
45
+ four types of named entities: persons, locations, organizations and names of miscellaneous entities that do
46
+ not belong to the previous three groups.
47
+ The CoNLL-2003 shared task data files contain four columns separated by a single space. Each word has been put on
48
+ a separate line and there is an empty line after each sentence. The first item on each line is a word, the second
49
+ a part-of-speech (POS) tag, the third a syntactic chunk tag and the fourth the named entity tag. The chunk tags
50
+ and the named entity tags have the format I-TYPE which means that the word is inside a phrase of type TYPE. Only
51
+ if two phrases of the same type immediately follow each other, the first word of the second phrase will have tag
52
+ B-TYPE to show that it starts a new phrase. A word with tag O is not part of a phrase. Note the dataset uses IOB2
53
+ tagging scheme, whereas the original dataset uses IOB1.
54
+ For more details see https://www.clips.uantwerpen.be/conll2003/ner/ and https://www.aclweb.org/anthology/W03-0419
55
+ """
56
+
57
+ _URL = "https://huggingface.co/datasets/FatmaZahraZ/JobDecriptionsEntityRecognition/resolve/main/Data.zip"
58
+ _TRAINING_FILE = "Train.txt"
59
+ _DEV_FILE = "validation.txt"
60
+ _TEST_FILE = "test.txt"
61
+
62
+
63
+ class Conll2003Config(datasets.BuilderConfig):
64
+ """BuilderConfig for Conll2003"""
65
+
66
+ def __init__(self, **kwargs):
67
+ """BuilderConfig forConll2003.
68
+ Args:
69
+ **kwargs: keyword arguments forwarded to super.
70
+ """
71
+ super(Conll2003Config, self).__init__(**kwargs)
72
+
73
+
74
+ class Conll2003(datasets.GeneratorBasedBuilder):
75
+
76
+ """Conll2003 dataset."""
77
+
78
+ BUILDER_CONFIGS = [
79
+ Conll2003Config(name="JobDecriptionsEntityRecognition", version=datasets.Version("1.0.0"), description="Conll2003 dataset"),
80
+ ]
81
+
82
+ def _info(self):
83
+ return datasets.DatasetInfo(
84
+ description=_DESCRIPTION,
85
+ features=datasets.Features(
86
+ {
87
+ "id": datasets.Value("string"),
88
+ "tokens": datasets.Sequence(datasets.Value("string")),
89
+ "ner_tags": datasets.Sequence(
90
+ datasets.features.ClassLabel(
91
+ names=[
92
+ "O",
93
+ "B-PER",
94
+ "I-PER",
95
+ "B-ORG",
96
+ "I-ORG",
97
+ "B-LOC",
98
+ "I-LOC",
99
+ "B-MISC",
100
+ "I-MISC",
101
+ "B-MET",
102
+ "I-MET",
103
+ "B-CONT",
104
+ "I-CONT",
105
+ "B-EDU",
106
+ "I-EDU",
107
+ "B-CER",
108
+ "I-CER",
109
+ "B-EXP",
110
+ "I-EXP",
111
+ "B-SAL",
112
+ "I-SAL",
113
+ ]
114
+ )
115
+ ),
116
+ }
117
+ ),
118
+ supervised_keys=None,
119
+ homepage="",
120
+ citation=_CITATION,
121
+ )
122
+
123
+ def _split_generators(self, dl_manager):
124
+ """Returns SplitGenerators."""
125
+ downloaded_file = dl_manager.download_and_extract(_URL)
126
+ data_files = {
127
+ "Train": os.path.join(downloaded_file, _TRAINING_FILE),
128
+ "dev": os.path.join(downloaded_file, _DEV_FILE),
129
+ "test": os.path.join(downloaded_file, _TEST_FILE),
130
+ }
131
+
132
+ return [
133
+ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": data_files["train"]}),
134
+ datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": data_files["dev"]}),
135
+ datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": data_files["test"]}),
136
+ ]
137
+
138
+ def _generate_examples(self, filepath):
139
+ logger.info("⏳ Generating examples from = %s", filepath)
140
+ with open(filepath, encoding="utf-8") as f:
141
+ guid = 0
142
+ tokens = []
143
+ ner_tags = []
144
+ for line in f:
145
+ if line.startswith("-DOCSTART-") or line == "" or line == "\n":
146
+ if tokens:
147
+ yield guid, {
148
+ "id": str(guid),
149
+ "tokens": tokens,
150
+ "ner_tags": ner_tags,
151
+ }
152
+ guid += 1
153
+ tokens = []
154
+ ner_tags = []
155
+ else:
156
+ # conll2003 tokens are space separated
157
+ splits = line.split(" ")
158
+ tokens.append(splits[0])
159
+ ner_tags.append(splits[1].rstrip())
160
+ # last example
161
+ if tokens:
162
+ yield guid, {
163
+ "id": str(guid),
164
+ "tokens": tokens,
165
+ "ner_tags": ner_tags,
166
+ }
167
+