BUSTER / BUSTER.py
azugarini's picture
Upload BUSTER.py
3ec852c
raw history blame
No virus
3.96 kB
# coding=utf-8
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
#
# 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.
"""BUSTER: a BUSiness Transaction Entity Recognition Dataset"""
import os
import datasets
from datasets import load_dataset
_CITATION = """
Accepted at EMNLP 2023 - Industry Track.
TBA
"""
_DESCRIPTION = """
Buster is an Entity Recognition dataset consisting of 3779 manually annotated documents on financial transactions.
Documents were selected using EDGAR (Electronic Data Gathering, Analysis, and Retrieval system) from the
U.S. Securities and Exchange Commission (SEC).
The corpus focuses on the main actors involved in business transactions.
Overall, there are three families of entities: Parties, Advisors and Generic information, for a total of 6 annotated
entity types.
We also released a corpus of 6196 automatically annotated documents.
"""
_HOMEPAGE = "https://expert.ai/buster"
_URL = "BUSTER.zip"
_VERSION = "1.0.0"
logger = datasets.logging.get_logger(__name__)
# --------------------------------------------------------------------------------------------------------
# Tag set
_LABELS = [
"O", # non-entities label
"B-Parties.BUYING_COMPANY",
"I-Parties.BUYING_COMPANY",
"B-Parties.SELLING_COMPANY",
"I-Parties.SELLING_COMPANY",
"B-Parties.ACQUIRED_COMPANY",
"I-Parties.ACQUIRED_COMPANY",
"B-Advisors.LEGAL_CONSULTING_COMPANY",
"I-Advisors.LEGAL_CONSULTING_COMPANY",
"B-Advisors.GENERIC_CONSULTING_COMPANY",
"I-Advisors.GENERIC_CONSULTING_COMPANY",
"B-Generic_Info.ANNUAL_REVENUES",
"I-Generic_Info.ANNUAL_REVENUES"
]
class BusterConfig(datasets.BuilderConfig):
"""BuilderConfig for the BUSTER dataset."""
def __init__(self, **kwargs):
"""BuilderConfig for the BUSTER dataset.
Args:
**kwargs: keyword arguments forwarded to super.
"""
super(BusterConfig, self).__init__(
name=f"BUSTER",
description=_DESCRIPTION,
version=datasets.Version(_VERSION), # hf dataset script version
**kwargs,
)
class Buster(datasets.GeneratorBasedBuilder):
"""The BUSTER dataset."""
BUILDER_CONFIGS = [
BusterConfig()
]
def _info(self):
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=datasets.Features(
{
"document_id": datasets.Value("string"),
"tokens": datasets.Sequence(datasets.Value("string")),
"labels": datasets.Sequence(datasets.features.ClassLabel(names=_LABELS)),
}
),
homepage=_HOMEPAGE,
citation=_CITATION,
)
def _split_generators(self, dl_manager):
data_dir = dl_manager.download_and_extract(_URL)
fold_names = [f"FOLD_{i}" for i in range(1, 6)] + ["SILVER"]
return [
datasets.SplitGenerator(
name=fold_name,
gen_kwargs={"file_path": os.path.join(data_dir, fold_name)},
) for fold_name in fold_names
]
def _generate_examples(self, file_path):
dataset = load_dataset("json", data_files=file_path)
logger.info(f"Generating examples from: {file_path}")
for idx, example in enumerate(dataset["train"]):
# example features: document_id, tokens, labels
yield idx, example