FeedRef2022 / FeedRef2022.py
cynthiachan's picture
update
037e9e6
# 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 json
import datasets
logger = datasets.logging.get_logger(__name__)
_CITATION = """\
"""
_DESCRIPTION = """\
"""
_URL = "https://huggingface.co/datasets/cynthiachan/feedref2022/resolve/main/FeedRef2022.zip"
_TRAINING_FILE = "train.json"
_DEV_FILE = "valid.json"
_TEST_FILE = "test.json"
class FeedRef2022Config(datasets.BuilderConfig):
"""BuilderConfig for FeedRef2022"""
def __init__(self, **kwargs):
"""BuilderConfig for FeedRef2022.
Args:
**kwargs: keyword arguments forwarded to super.
"""
super(FeedRef2022Config, self).__init__(**kwargs)
class FeedRef2022(datasets.GeneratorBasedBuilder):
"""FeedRef2022 dataset."""
BUILDER_CONFIGS = [
FeedRef2022Config(name="FeedRef2022", version=datasets.Version("1.0.0"), description="FeedRef2022 dataset"),
]
def _info(self):
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=datasets.Features(
{
"id": datasets.Value("string"),
"tokens": datasets.Sequence(datasets.Value("string")),
"ner_tags": datasets.Sequence(
datasets.features.ClassLabel(
names=[
"O",
"B-attackID",
"I-attackID",
"B-bitcoinAddr",
"I-bitcoinAddr",
"B-cve",
"I-cve",
"B-defenderThreat",
"I-defenderThreat",
"B-domain",
"I-domain",
"B-email",
"I-email",
"B-md5",
"I-md5",
"B-sha1",
"I-sha1",
"B-sha256",
"I-sha256",
"B-filepath",
"I-filepath",
"B-hostname",
"I-hostname",
"B-ipv4",
"I-ipv4",
"B-ipv6",
"I-ipv6",
"B-fingerprint",
"I-fingerprint",
"B-uri",
"I-uri",
"B-url",
"I-url",
"B-yara",
"I-yara"
]
)
),
}
),
# supervised_keys=None,
# homepage="https://www.aclweb.org/anthology/W03-0419/",
# citation=_CITATION,
)
def _split_generators(self, dl_manager):
"""Returns SplitGenerators."""
downloaded_file = dl_manager.download_and_extract(_URL)
data_files = {
"train": os.path.join(downloaded_file, _TRAINING_FILE),
"dev": os.path.join(downloaded_file, _DEV_FILE),
"test": os.path.join(downloaded_file, _TEST_FILE),
}
return [
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": data_files["train"]}),
datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": data_files["dev"]}),
datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": data_files["test"]}),
]
def _generate_examples(self, filepath):
logger.info("⏳ Generating examples from = %s", filepath)
id = 0
with open(filepath, encoding="utf-8") as f:
data = json.load(f)
for sentence in data["data"]:
yield id, {
"id": id,
"tokens": sentence["tokens"],
"ner_tags": sentence["ner_tags"]
}
id+=1