Datasets:
umarbutler
commited on
Commit
•
494f500
1
Parent(s):
c84ed9a
Update open_australian_legal_embeddings.py
Browse files
open_australian_legal_embeddings.py
ADDED
@@ -0,0 +1,109 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Copyright 2023 Umar Butler.
|
2 |
+
#
|
3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4 |
+
# you may not use this file except in compliance with the License.
|
5 |
+
# You may obtain a copy of the License at
|
6 |
+
#
|
7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8 |
+
#
|
9 |
+
# Unless required by applicable law or agreed to in writing, software
|
10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12 |
+
# See the License for the specific language governing permissions and
|
13 |
+
# limitations under the License.
|
14 |
+
"""Open Australian Legal Embeddings: the first open-source embeddings of Australian legislative and judicial documents"""
|
15 |
+
|
16 |
+
import datasets
|
17 |
+
for module in ('orjson', 'ujson', 'json'):
|
18 |
+
try:
|
19 |
+
json = __import__(module)
|
20 |
+
|
21 |
+
break
|
22 |
+
except ImportError:
|
23 |
+
pass
|
24 |
+
|
25 |
+
_CITATION = """\
|
26 |
+
@misc{butler-2023-open-australian-legal-embeddings,
|
27 |
+
author = {Butler, Umar},
|
28 |
+
year = {2023},
|
29 |
+
title = {Open Australian Legal Embeddings},
|
30 |
+
publisher = {Hugging Face},
|
31 |
+
version = {1.0.0},
|
32 |
+
url = {https://huggingface.co/datasets/umarbutler/open-australian-legal-embeddings}
|
33 |
+
}
|
34 |
+
"""
|
35 |
+
|
36 |
+
_DESCRIPTION = """\
|
37 |
+
The Open Australian Legal Embeddings are the first open-source embeddings of Australian legislative and judicial documents.
|
38 |
+
|
39 |
+
Trained on the largest open database of Australian law, the [Open Australian Legal Corpus](https://huggingface.co/datasets/umarbutler/open-australian-legal-corpus), the Embeddings consist of roughly 5.2 million 384-dimensional vectors embedded with [`BAAI/bge-small-en-v1.5`](https://huggingface.co/BAAI/bge-small-en-v1.5).
|
40 |
+
|
41 |
+
The Embeddings open the door to a wide range of possibilities in the field of Australian legal AI, including the development of document classifiers, search engines and chatbots.
|
42 |
+
|
43 |
+
To ensure their accessibility to as wide an audience as possible, the Embeddings are distributed under the same licence as the [Open Australian Legal Corpus](https://huggingface.co/datasets/umarbutler/open-australian-legal-corpus/blob/main/LICENCE.md)."""
|
44 |
+
|
45 |
+
_HOMEPAGE = "https://huggingface.co/datasets/umarbutler/open-australian-legal-embeddings"
|
46 |
+
|
47 |
+
_LICENSE = """\
|
48 |
+
The Embeddings are distributed under the same licence as the [Open Australian Legal Corpus](https://huggingface.co/datasets/umarbutler/open-australian-legal-corpus/blob/main/LICENCE.md)."""
|
49 |
+
|
50 |
+
_URLS = {
|
51 |
+
'embeddings' : 'data/embeddings.jsonl',
|
52 |
+
'metadatas' : 'data/metadatas.jsonl',
|
53 |
+
'texts' : 'data/texts.jsonl',
|
54 |
+
}
|
55 |
+
|
56 |
+
class OpenAustralianLegalEmbeddings(datasets.GeneratorBasedBuilder):
|
57 |
+
"""Open Australian Legal Embeddings: the first open-source embeddings of Australian legislative and judicial documents"""
|
58 |
+
|
59 |
+
VERSION = datasets.Version("1.0.0")
|
60 |
+
|
61 |
+
DEFAULT_CONFIG_NAME = "train"
|
62 |
+
|
63 |
+
def _info(self):
|
64 |
+
return datasets.DatasetInfo(
|
65 |
+
description=_DESCRIPTION,
|
66 |
+
features=datasets.Features(
|
67 |
+
{
|
68 |
+
'version_id' : datasets.Value('string'),
|
69 |
+
'type' : datasets.Value('string'),
|
70 |
+
'jurisdiction' : datasets.Value('string'),
|
71 |
+
'source' : datasets.Value('string'),
|
72 |
+
'citation' : datasets.Value('string'),
|
73 |
+
'url' : datasets.Value('string'),
|
74 |
+
'is_last_chunk' : datasets.Value('bool'),
|
75 |
+
'text' : datasets.Value('string'),
|
76 |
+
'embedding' : [datasets.Value('float32')]
|
77 |
+
}
|
78 |
+
),
|
79 |
+
homepage=_HOMEPAGE,
|
80 |
+
license=_LICENSE,
|
81 |
+
citation=_CITATION,
|
82 |
+
)
|
83 |
+
|
84 |
+
def _split_generators(self, dl_manager):
|
85 |
+
downloaded_files = dl_manager.download_and_extract(_URLS)
|
86 |
+
|
87 |
+
return [
|
88 |
+
datasets.SplitGenerator(
|
89 |
+
name=datasets.Split.TRAIN,
|
90 |
+
gen_kwargs={
|
91 |
+
'embeddings_path' : downloaded_files['embeddings'],
|
92 |
+
'metadatas_path' : downloaded_files['metadatas'],
|
93 |
+
'texts_path' : downloaded_files['texts'],
|
94 |
+
}
|
95 |
+
)
|
96 |
+
]
|
97 |
+
|
98 |
+
def _generate_examples(self, embeddings_path, metadatas_path, texts_path):
|
99 |
+
with open(embeddings_path, 'rb') as embeddings_file, \
|
100 |
+
open(metadatas_path, 'rb') as metadatas_file, \
|
101 |
+
open(texts_path, 'rb') as texts_file:
|
102 |
+
i = -1
|
103 |
+
|
104 |
+
for embedding, metadata, text in zip(embeddings_file, metadatas_file, texts_file):
|
105 |
+
i += 1
|
106 |
+
yield i, json.loads(metadata) | {
|
107 |
+
'text' : json.loads(text),
|
108 |
+
'embedding' : json.loads(embedding)
|
109 |
+
}
|