File size: 5,657 Bytes
26a2ef3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# coding=utf-8
# Copyright 2020 HuggingFace Datasets Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Lint as: python3
"""Introduction to the CoNLL-2003 Shared Task: Language-Independent Named Entity Recognition"""
import os
import datasets
logger = datasets.logging.get_logger(__name__)
_CITATION = """\
@inproceedings{derczynski-kjeldsen-2019-bornholmsk,
title = "Bornholmsk Natural Language Processing: Resources and Tools",
author = "Derczynski, Leon and
Kjeldsen, Alex Speed",
booktitle = "Proceedings of the 22nd Nordic Conference on Computational Linguistics",
month = sep # "{--}" # oct,
year = "2019",
address = "Turku, Finland",
publisher = {Link{\"o}ping University Electronic Press},
url = "https://aclanthology.org/W19-6138",
pages = "338--344",
abstract = {This paper introduces language processing resources and tools for Bornholmsk, a language spoken on the island of Bornholm, with roots in Danish and closely related to Scanian. This presents an overview of the language and available data, and the first NLP models for this living, minority Nordic language. Sammenfattnijng p{\aa} borrijnholmst: D{\ae}jnna artikkelijn introduserer naturspr{\aa}gsresurser {\aa} varktoi for borrijnholmst, ed spr{\aa}g a d{\ae}r snakkes p{\aa} {\"o}n Borrijnholm me r{\o}dder i danst {\aa} i n{\ae}r familia me sk{\aa}nst. Artikkelijn gjer ed {\^a}uersyn {\^a}uer spr{\aa}ged {\aa} di datan som fijnnes, {\aa} di fosste NLP mod{\ae}llarna for d{\ae}tta l{\ae}wenes nordiska minnret{\^a}lsspr{\aa}ged.},
}
"""
_DESCRIPTION = """\
This corpus introduces language processing resources and tools for Bornholmsk, a language spoken on the island of Bornholm, with roots in Danish and closely related to Scanian.
Sammenfattnijng på borrijnholmst: Dæjnna artikkelijn introduserer natursprågsresurser å varktoi for borrijnholmst, ed språg a dær snakkes på ön Borrijnholm me rødder i danst å i nær familia me skånst.
"""
_URL_BASE = "https://github.com/StrombergNLP/bornholmsk/blob/0bdb51bf7522c1d154bcc9c54f6ffd4c5125a121/parallel."
class BornholmskConfig(datasets.BuilderConfig):
"""BuilderConfig for Bornholmsk"""
def __init__(self, **kwargs):
"""BuilderConfig Bornholmsk.
Args:
**kwargs: keyword arguments forwarded to super.
"""
super(BornholmskConfig, self).__init__(**kwargs)
class Bornholmsk(datasets.GeneratorBasedBuilder):
"""Bornholmsk dataset."""
BUILDER_CONFIGS = [
BornholmskConfig(name="Bornholmsk", version=datasets.Version("1.0.0"), description="Bornholmsk text"),
]
def _info(self):
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=datasets.Features(
{
"id": datasets.Value("string"),
"da_bornholm": datasets.Value("string"),
"da": datasets.Value("string"),
}
),
supervised_keys=None,
homepage="https://github.com/StrombergNLP/bornholmsk",
citation=_CITATION,
)
def _split_generators(self, dl_manager):
"""Returns SplitGenerators."""
downloaded_files = {}
for lang in ('da', 'da-bornholm'):
for partition in ('train', 'val', 'test'):
part = f"{lang}.{partition}"
downloaded_files[part] = dl_manager.download_and_extract(_URL_BASE + part)
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={"filepath":
{
'da': downloaded_files['da.train'],
'da-bornholm':downloaded_files['da-bornholm.train']
}
}
),
datasets.SplitGenerator(
name=datasets.Split.VALIDATION,
gen_kwargs={"filepath":
{
'da': downloaded_files['da.val'],
'da-bornholm':downloaded_files['da-bornholm.val']
}
}
),
datasets.SplitGenerator(
name=datasets.Split.TEST,
gen_kwargs={"filepath":
{
'da': downloaded_files['da.test'],
'da-bornholm':downloaded_files['da-bornholm.test']
}
}
),
]
def _generate_examples(self, filepath):
logger.info("⏳ Generating examples from = %s and %s", (filepath['da'], filepath['da-bornholm']))
guid = 0
with open(filepath['da-bornholm'], encoding="utf-8") as f_da:
with open(filepath['da'], encoding="utf-8") as f_bo:
bo = f_bo.readlines()
da = f_da.readlines()
for instance in zip(bo, da):
yield guid, {
"id": str(guid),
"da_bornholm": instance[0],
"da": instance[1],
}
guid += 1
|