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