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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# coding=utf-8
|
| 2 |
+
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
|
| 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 |
+
"""The Legal Pile (Preprocessed)"""
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
import datasets
|
| 20 |
+
import json
|
| 21 |
+
|
| 22 |
+
try:
|
| 23 |
+
import lzma as xz
|
| 24 |
+
except ImportError:
|
| 25 |
+
import pylzma as xz
|
| 26 |
+
|
| 27 |
+
logger = datasets.logging.get_logger(__name__)
|
| 28 |
+
|
| 29 |
+
_DESCRIPTION = """The Legal Pile (Preprocessed)"""
|
| 30 |
+
|
| 31 |
+
_HOMEPAGE = "https://iliaschalkidis.github.io/"
|
| 32 |
+
|
| 33 |
+
_VERSION = "1.0.0"
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
class LegalPileConfig(datasets.BuilderConfig):
|
| 37 |
+
"""BuilderConfig for Legal Pile Corpora"""
|
| 38 |
+
def __init__(self, name, n_files, **kwargs):
|
| 39 |
+
super(LegalPileConfig, self).__init__(**kwargs)
|
| 40 |
+
self.name = name
|
| 41 |
+
self.filepath = f'https://huggingface.co/datasets/lexlms/the_legal_pile_preprocessed/' \
|
| 42 |
+
f'resolve/main/{self.name}.jsonl.xz'
|
| 43 |
+
self.n_files = n_files
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
class LegalPile(datasets.GeneratorBasedBuilder):
|
| 47 |
+
"""
|
| 48 |
+
The Legal Pile
|
| 49 |
+
"""
|
| 50 |
+
|
| 51 |
+
VERSION = datasets.Version(_VERSION)
|
| 52 |
+
BUILDER_CONFIG_CLASS = LegalPileConfig
|
| 53 |
+
BUILDER_CONFIGS = [
|
| 54 |
+
LegalPileConfig(
|
| 55 |
+
name=f"eu-legislation",
|
| 56 |
+
n_files=1,
|
| 57 |
+
description="EU Legislation",
|
| 58 |
+
),
|
| 59 |
+
LegalPileConfig(
|
| 60 |
+
name=f"eu-court-cases",
|
| 61 |
+
n_files=1,
|
| 62 |
+
description="EU Court cases",
|
| 63 |
+
),
|
| 64 |
+
LegalPileConfig(
|
| 65 |
+
name=f"ecthr-cases",
|
| 66 |
+
n_files=1,
|
| 67 |
+
description="ECtHR cases",
|
| 68 |
+
),
|
| 69 |
+
LegalPileConfig(
|
| 70 |
+
name=f"uk-legislation",
|
| 71 |
+
n_files=1,
|
| 72 |
+
description="UK Legislation",
|
| 73 |
+
),
|
| 74 |
+
LegalPileConfig(
|
| 75 |
+
name=f"uk-court-cases",
|
| 76 |
+
n_files=1,
|
| 77 |
+
description="UK Court cases",
|
| 78 |
+
),
|
| 79 |
+
LegalPileConfig(
|
| 80 |
+
name=f"indian-court-cases",
|
| 81 |
+
n_files=1,
|
| 82 |
+
description="Indian Court cases",
|
| 83 |
+
),
|
| 84 |
+
LegalPileConfig(
|
| 85 |
+
name=f"canadian-legislation",
|
| 86 |
+
n_files=1,
|
| 87 |
+
description="Canadian Legislation",
|
| 88 |
+
),
|
| 89 |
+
LegalPileConfig(
|
| 90 |
+
name=f"canadian-court-cases",
|
| 91 |
+
n_files=1,
|
| 92 |
+
description="Canadian Legislation",
|
| 93 |
+
),
|
| 94 |
+
LegalPileConfig(
|
| 95 |
+
name=f"us-legislation",
|
| 96 |
+
n_files=1,
|
| 97 |
+
description="US Legislation",
|
| 98 |
+
),
|
| 99 |
+
LegalPileConfig(
|
| 100 |
+
name=f"us-contracts",
|
| 101 |
+
n_files=1,
|
| 102 |
+
description="US Contracts",
|
| 103 |
+
),
|
| 104 |
+
LegalPileConfig(
|
| 105 |
+
name=f"us-court-cases",
|
| 106 |
+
n_files=1,
|
| 107 |
+
description="US Court cases",
|
| 108 |
+
)
|
| 109 |
+
]
|
| 110 |
+
|
| 111 |
+
def _info(self):
|
| 112 |
+
features = datasets.Features(
|
| 113 |
+
{
|
| 114 |
+
"text": datasets.Value("string")
|
| 115 |
+
}
|
| 116 |
+
)
|
| 117 |
+
return datasets.DatasetInfo(
|
| 118 |
+
description=_DESCRIPTION,
|
| 119 |
+
features=features,
|
| 120 |
+
supervised_keys=None,
|
| 121 |
+
homepage=_HOMEPAGE,
|
| 122 |
+
)
|
| 123 |
+
|
| 124 |
+
def _split_generators(self, dl_manager):
|
| 125 |
+
train_data_dir = dl_manager.download([self.config.filepath.replace('.jsonl.xz', f'_train_{idx+1}.jsonl.xz')
|
| 126 |
+
for idx in range(self.config.n_files)])
|
| 127 |
+
# test_data_dir = dl_manager.download([self.config.filepath.replace('.jsonl.xz', 'test.jsonl.xz')])
|
| 128 |
+
|
| 129 |
+
return [
|
| 130 |
+
datasets.SplitGenerator(
|
| 131 |
+
name=datasets.Split.TRAIN,
|
| 132 |
+
gen_kwargs={"filepaths": train_data_dir, "split": 'train'},
|
| 133 |
+
),
|
| 134 |
+
# datasets.SplitGenerator(
|
| 135 |
+
# name=datasets.Split.TEST,
|
| 136 |
+
# gen_kwargs={"filepaths": test_data_dir, "split": 'test'},
|
| 137 |
+
# )
|
| 138 |
+
]
|
| 139 |
+
|
| 140 |
+
def _generate_examples(self, filepaths, split):
|
| 141 |
+
"""
|
| 142 |
+
Reads line by line samples and generates examples.
|
| 143 |
+
:param filepath: Path to jsonl files with line by line examples.
|
| 144 |
+
"""
|
| 145 |
+
id_ = 0
|
| 146 |
+
for filepath in filepaths:
|
| 147 |
+
logger.info("⏳ Generating examples from = %s", filepath)
|
| 148 |
+
with xz.open(open(filepath, "rb"), "rt", encoding='utf-8') as f:
|
| 149 |
+
for row in f:
|
| 150 |
+
try:
|
| 151 |
+
data = json.loads(row)
|
| 152 |
+
yield id_, {
|
| 153 |
+
"text": data["text"]
|
| 154 |
+
}
|
| 155 |
+
id_ += 1
|
| 156 |
+
except:
|
| 157 |
+
continue
|
| 158 |
+
|
us-contracts_train_1.jsonl.xz
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:f6ece6ca34ea8f3bad3382ba646b7df27e5f3bc0f8793c25fdf0bdeeac7f7ce3
|
| 3 |
+
size 762802272
|