File size: 4,734 Bytes
494f500
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8c55779
494f500
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# Copyright 2023 Umar Butler.
#
# 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.
"""Open Australian Legal Embeddings: the first open-source embeddings of Australian legislative and judicial documents"""

import datasets
for module in ('orjson', 'ujson', 'json'):
    try:
        json = __import__(module)
        
        break
    except ImportError:
        pass

_CITATION = """\
@misc{butler-2023-open-australian-legal-embeddings,
    author = {Butler, Umar},
    year = {2023},
    title = {Open Australian Legal Embeddings},
    publisher = {Hugging Face},
    version = {1.0.0},
    doi = {10.57967/hf/1347},
    url = {https://huggingface.co./datasets/umarbutler/open-australian-legal-embeddings}
}
"""

_DESCRIPTION = """\
The Open Australian Legal Embeddings are the first open-source embeddings of Australian legislative and judicial documents.

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).

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.

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)."""

_HOMEPAGE = "https://huggingface.co./datasets/umarbutler/open-australian-legal-embeddings"

_LICENSE = """\
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)."""

_URLS = {
    'embeddings' : 'data/embeddings.jsonl',
    'metadatas' : 'data/metadatas.jsonl',
    'texts' : 'data/texts.jsonl',
}

class OpenAustralianLegalEmbeddings(datasets.GeneratorBasedBuilder):
    """Open Australian Legal Embeddings: the first open-source embeddings of Australian legislative and judicial documents"""

    VERSION = datasets.Version("1.0.0")

    DEFAULT_CONFIG_NAME = "train"

    def _info(self):
        return datasets.DatasetInfo(
            description=_DESCRIPTION,
            features=datasets.Features(
                {
                    'version_id' : datasets.Value('string'),
                    'type' : datasets.Value('string'),
                    'jurisdiction' : datasets.Value('string'),
                    'source' : datasets.Value('string'),
                    'citation' : datasets.Value('string'),
                    'url' : datasets.Value('string'),
                    'is_last_chunk' : datasets.Value('bool'),
                    'text' : datasets.Value('string'),
                    'embedding' : [datasets.Value('float32')]
                }
            ),
            homepage=_HOMEPAGE,
            license=_LICENSE,
            citation=_CITATION,
        )

    def _split_generators(self, dl_manager):
        downloaded_files = dl_manager.download_and_extract(_URLS)
        
        return [
            datasets.SplitGenerator(
                name=datasets.Split.TRAIN,
                gen_kwargs={
                    'embeddings_path' : downloaded_files['embeddings'],
                    'metadatas_path' : downloaded_files['metadatas'],
                    'texts_path' : downloaded_files['texts'],
                }
            )
        ]

    def _generate_examples(self, embeddings_path, metadatas_path, texts_path):
        with open(embeddings_path, 'rb') as embeddings_file, \
            open(metadatas_path, 'rb') as metadatas_file, \
            open(texts_path, 'rb') as texts_file:
                i = -1
                
                for embedding, metadata, text in zip(embeddings_file, metadatas_file, texts_file):
                    i += 1
                    yield i, json.loads(metadata) | {
                        'text' : json.loads(text),
                        'embedding' : json.loads(embedding)
                    }