vesteinn commited on
Commit
b07f5e6
1 Parent(s): 91321d6

Added data

Browse files
Files changed (3) hide show
  1. README.md +4 -0
  2. swe-nerc.py +140 -0
  3. swe_nerc_v1.tsv +0 -0
README.md ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ This is a Swedish NE dataset, Swe-NERC v1. Please see https://hdl.handle.net/10794/121 for more information.
2
+
3
+ Included here is the manually tagged part.
4
+
swe-nerc.py ADDED
@@ -0,0 +1,140 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2020 HuggingFace Datasets Authors.
3
+ # Modified by Vésteinn Snæbjarnarson 2021
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+
18
+ # Lint as: python3
19
+
20
+
21
+
22
+
23
+
24
+
25
+ LABELS = [
26
+ "EVN",
27
+ "GRO",
28
+ "LOC",
29
+ "MNT",
30
+ "O",
31
+ "PRS",
32
+ "SMP",
33
+ "TME",
34
+ "WRK"
35
+ ]
36
+
37
+
38
+
39
+ import datasets
40
+
41
+
42
+ logger = datasets.logging.get_logger(__name__)
43
+
44
+
45
+ _CITATION = """\
46
+ @misc{swe-nerc,
47
+ title = {Swe-NERC},
48
+ author = {Ahrenberg, Lars ; Frid, Johan and Olsson, Leif-Jöran},
49
+ url = {https://hdl.handle.net/10794/121},
50
+ year = {2020} }
51
+ """
52
+
53
+ _DESCRIPTION = """\
54
+ The corpus consists of ca. 150.000 words of text.
55
+ """
56
+
57
+ _URL = "https://huggingface.co/datasets/vesteinn/swe-nerc/raw/main/"
58
+ _TRAINING_FILE = "swe_nerc_v1.tsv"
59
+
60
+
61
+ class SweNERCConfig(datasets.BuilderConfig):
62
+ """BuilderConfig for swe-nerc"""
63
+
64
+ def __init__(self, **kwargs):
65
+ """BuilderConfig for swe-nerc.
66
+ Args:
67
+ **kwargs: keyword arguments forwarded to super.
68
+ """
69
+ super(SweNERCConfig, self).__init__(**kwargs)
70
+
71
+
72
+ class SweNERC(datasets.GeneratorBasedBuilder):
73
+ """sosialurin-faroese-ner dataset."""
74
+
75
+ BUILDER_CONFIGS = [
76
+ SweNERCConfig(name="swe-nerc", version=datasets.Version("1.0"), description="swedish ner corpus"),
77
+ ]
78
+
79
+ def _info(self):
80
+ return datasets.DatasetInfo(
81
+ description=_DESCRIPTION,
82
+ features=datasets.Features(
83
+ {
84
+ "id": datasets.Value("string"),
85
+ "tokens": datasets.Sequence(datasets.Value("string")),
86
+ "ner_tags": datasets.Sequence(
87
+ datasets.features.ClassLabel(
88
+ names=LABELS
89
+ )
90
+ ),
91
+ }
92
+ ),
93
+ supervised_keys=None,
94
+ homepage="",
95
+ citation=_CITATION,
96
+ )
97
+
98
+ def _split_generators(self, dl_manager):
99
+ """Returns SplitGenerators."""
100
+ urls_to_download = {
101
+ "train": f"{_URL}{_TRAINING_FILE}",
102
+ }
103
+ downloaded_files = dl_manager.download_and_extract(urls_to_download)
104
+
105
+ return [
106
+ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}),
107
+ ]
108
+
109
+ def _generate_examples(self, filepath):
110
+ logger.info("⏳ Generating examples from = %s", filepath)
111
+ with open(filepath, encoding="utf-8") as f:
112
+ guid = 0
113
+ tokens = []
114
+ ner_tags = []
115
+ for line in f:
116
+ if line.startswith("-DOCSTART-") or line == "" or line == "\n":
117
+ if tokens:
118
+ yield guid, {
119
+ "id": str(guid),
120
+ "tokens": tokens,
121
+ "ner_tags": ner_tags,
122
+ }
123
+ guid += 1
124
+ tokens = []
125
+ ner_tags = []
126
+ else:
127
+ # tokens are tab separated
128
+ splits = line.split("\t")
129
+ tokens.append(splits[0])
130
+ try:
131
+ ner_tags.append(splits[1].rstrip())
132
+ except:
133
+ print(splits)
134
+ raise
135
+ # last example
136
+ yield guid, {
137
+ "id": str(guid),
138
+ "tokens": tokens,
139
+ "ner_tags": ner_tags,
140
+ }
swe_nerc_v1.tsv ADDED
The diff for this file is too large to render. See raw diff