Datasets:
Tasks:
Summarization
Modalities:
Text
Formats:
parquet
Languages:
English
Size:
1M - 10M
ArXiv:
Tags:
patent-summarization
License:
Delete loading script
Browse files- big_patent.py +0 -163
big_patent.py
DELETED
|
@@ -1,163 +0,0 @@
|
|
| 1 |
-
# coding=utf-8
|
| 2 |
-
# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
|
| 3 |
-
#
|
| 4 |
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
-
# you may not use this file except in compliance with the License.
|
| 6 |
-
# You may obtain a copy of the License at
|
| 7 |
-
#
|
| 8 |
-
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
-
#
|
| 10 |
-
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
-
# See the License for the specific language governing permissions and
|
| 14 |
-
# limitations under the License.
|
| 15 |
-
|
| 16 |
-
# Lint as: python3
|
| 17 |
-
"""BigPatent Dataset."""
|
| 18 |
-
import gzip
|
| 19 |
-
import json
|
| 20 |
-
import os
|
| 21 |
-
|
| 22 |
-
import datasets
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
_HOMEPAGE = "https://evasharma.github.io/bigpatent/"
|
| 26 |
-
|
| 27 |
-
_CITATION = """
|
| 28 |
-
@misc{sharma2019bigpatent,
|
| 29 |
-
title={BIGPATENT: A Large-Scale Dataset for Abstractive and Coherent Summarization},
|
| 30 |
-
author={Eva Sharma and Chen Li and Lu Wang},
|
| 31 |
-
year={2019},
|
| 32 |
-
eprint={1906.03741},
|
| 33 |
-
archivePrefix={arXiv},
|
| 34 |
-
primaryClass={cs.CL}
|
| 35 |
-
}
|
| 36 |
-
"""
|
| 37 |
-
|
| 38 |
-
_DESCRIPTION = """
|
| 39 |
-
BIGPATENT, consisting of 1.3 million records of U.S. patent documents
|
| 40 |
-
along with human written abstractive summaries.
|
| 41 |
-
Each US patent application is filed under a Cooperative Patent Classification
|
| 42 |
-
(CPC) code. There are nine such classification categories:
|
| 43 |
-
A (Human Necessities), B (Performing Operations; Transporting),
|
| 44 |
-
C (Chemistry; Metallurgy), D (Textiles; Paper), E (Fixed Constructions),
|
| 45 |
-
F (Mechanical Engineering; Lightning; Heating; Weapons; Blasting),
|
| 46 |
-
G (Physics), H (Electricity), and
|
| 47 |
-
Y (General tagging of new or cross-sectional technology)
|
| 48 |
-
There are two features:
|
| 49 |
-
- description: detailed description of patent.
|
| 50 |
-
- abstract: Patent abastract.
|
| 51 |
-
"""
|
| 52 |
-
|
| 53 |
-
_LICENSE = "Creative Commons Attribution 4.0 International"
|
| 54 |
-
|
| 55 |
-
_SPLIT_NAMES = {datasets.Split.TRAIN: "train", datasets.Split.VALIDATION: "val", datasets.Split.TEST: "test"}
|
| 56 |
-
_URL = "data/{version}/{split_name}.zip"
|
| 57 |
-
|
| 58 |
-
_DOCUMENT = "description"
|
| 59 |
-
_SUMMARY = "abstract"
|
| 60 |
-
|
| 61 |
-
_CPC_DESCRIPTION = {
|
| 62 |
-
"a": "Human Necessities",
|
| 63 |
-
"b": "Performing Operations; Transporting",
|
| 64 |
-
"c": "Chemistry; Metallurgy",
|
| 65 |
-
"d": "Textiles; Paper",
|
| 66 |
-
"e": "Fixed Constructions",
|
| 67 |
-
"f": "Mechanical Engineering; Lightning; Heating; Weapons; Blasting",
|
| 68 |
-
"g": "Physics",
|
| 69 |
-
"h": "Electricity",
|
| 70 |
-
"y": "General tagging of new or cross-sectional technology",
|
| 71 |
-
}
|
| 72 |
-
|
| 73 |
-
# Available versions:
|
| 74 |
-
# 1.0.0 lower cased tokenized words.
|
| 75 |
-
# 2.0.0 cased raw strings.
|
| 76 |
-
# 2.1.2 cased raw strings (fixed).
|
| 77 |
-
|
| 78 |
-
_VERSION = "2.1.2"
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
class BigPatentConfig(datasets.BuilderConfig):
|
| 82 |
-
"""BuilderConfig for BigPatent."""
|
| 83 |
-
|
| 84 |
-
def __init__(self, codes="all", version=_VERSION, **kwargs):
|
| 85 |
-
"""BuilderConfig for BigPatent.
|
| 86 |
-
Args:
|
| 87 |
-
codes (str or list, default 'all'): CPC codes. Either 'all' or a combination
|
| 88 |
-
of {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'y'}.
|
| 89 |
-
**kwargs: keyword arguments forwarded to super.
|
| 90 |
-
"""
|
| 91 |
-
if isinstance(codes, str):
|
| 92 |
-
codes = [codes]
|
| 93 |
-
name = "+".join(codes)
|
| 94 |
-
if name == "all":
|
| 95 |
-
codes = list(_CPC_DESCRIPTION)
|
| 96 |
-
if version != _VERSION:
|
| 97 |
-
name = f"{name}-{version}"
|
| 98 |
-
super().__init__(name=name, version=version, **kwargs)
|
| 99 |
-
self.codes = codes
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
class BigPatent(datasets.GeneratorBasedBuilder):
|
| 103 |
-
"""BigPatent datasets."""
|
| 104 |
-
|
| 105 |
-
BUILDER_CONFIG_CLASS = BigPatentConfig
|
| 106 |
-
BUILDER_CONFIGS = [
|
| 107 |
-
BigPatentConfig(
|
| 108 |
-
codes="all",
|
| 109 |
-
description="Patents under all categories.",
|
| 110 |
-
),
|
| 111 |
-
] + [
|
| 112 |
-
BigPatentConfig(
|
| 113 |
-
codes=k,
|
| 114 |
-
description=f"Patents under Cooperative Patent Classification (CPC) {k}: {v}",
|
| 115 |
-
)
|
| 116 |
-
for k, v in sorted(_CPC_DESCRIPTION.items())
|
| 117 |
-
]
|
| 118 |
-
DEFAULT_CONFIG_NAME = "all"
|
| 119 |
-
VERSION = _VERSION
|
| 120 |
-
|
| 121 |
-
def _info(self):
|
| 122 |
-
return datasets.DatasetInfo(
|
| 123 |
-
description=_DESCRIPTION,
|
| 124 |
-
features=datasets.Features({_DOCUMENT: datasets.Value("string"), _SUMMARY: datasets.Value("string")}),
|
| 125 |
-
supervised_keys=(_DOCUMENT, _SUMMARY),
|
| 126 |
-
homepage=_HOMEPAGE,
|
| 127 |
-
license=_LICENSE,
|
| 128 |
-
citation=_CITATION,
|
| 129 |
-
)
|
| 130 |
-
|
| 131 |
-
def _split_generators(self, dl_manager):
|
| 132 |
-
"""Returns SplitGenerators."""
|
| 133 |
-
urls = {
|
| 134 |
-
split: _URL.format(version=self.config.version, split_name=split_name)
|
| 135 |
-
for split, split_name in _SPLIT_NAMES.items()
|
| 136 |
-
}
|
| 137 |
-
dl_paths = dl_manager.download_and_extract(urls)
|
| 138 |
-
paths = {
|
| 139 |
-
split: [
|
| 140 |
-
dl_manager.iter_files(os.path.join(dl_paths[split], split_name, code)) for code in self.config.codes
|
| 141 |
-
]
|
| 142 |
-
for split, split_name in _SPLIT_NAMES.items()
|
| 143 |
-
}
|
| 144 |
-
return [
|
| 145 |
-
datasets.SplitGenerator(
|
| 146 |
-
name=split,
|
| 147 |
-
gen_kwargs={"paths": paths[split]},
|
| 148 |
-
)
|
| 149 |
-
for split in _SPLIT_NAMES
|
| 150 |
-
]
|
| 151 |
-
|
| 152 |
-
def _generate_examples(self, paths=None):
|
| 153 |
-
"""Yields examples."""
|
| 154 |
-
for paths_per_code in paths:
|
| 155 |
-
for path in paths_per_code:
|
| 156 |
-
with open(path, "rb") as fin:
|
| 157 |
-
fin = gzip.GzipFile(fileobj=fin)
|
| 158 |
-
for row in fin:
|
| 159 |
-
json_obj = json.loads(row)
|
| 160 |
-
yield json_obj["publication_number"], {
|
| 161 |
-
_DOCUMENT: json_obj[_DOCUMENT],
|
| 162 |
-
_SUMMARY: json_obj[_SUMMARY],
|
| 163 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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