umarbutler commited on
Commit
9e8d83b
1 Parent(s): 494f500

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +147 -1
README.md CHANGED
@@ -1,5 +1,151 @@
1
  ---
 
 
2
  license: other
3
  license_name: open-australian-legal-corpus
4
- license_link: LICENSE
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ language:
3
+ - en
4
  license: other
5
  license_name: open-australian-legal-corpus
6
+ license_link: https://huggingface.co/datasets/umarbutler/open-australian-legal-corpus/blob/main/LICENCE.md
7
+ tags:
8
+ - law
9
+ - legal
10
+ - australia
11
+ - embeddings
12
+ annotations_creators:
13
+ - no-annotation
14
+ language_creators:
15
+ - found
16
+ language_details: en-AU, en-GB
17
+ pretty_name: Open Australian Legal Embeddings
18
+ size_categories:
19
+ - 1M<n<10M
20
+ source_datasets:
21
+ - Federal Register of Legislation
22
+ - Federal Court of Australia
23
+ - High Court of Australia
24
+ - NSW Caselaw
25
+ - NSW Legislation
26
+ - Queensland Legislation
27
+ - Western Australian Legislation
28
+ - South Australian Legislation
29
+ - Tasmanian Legislation
30
+ task_categories:
31
+ - text-retrieval
32
+ task_ids:
33
+ - document-retrieval
34
+ viewer: true
35
+ dataset_info:
36
+ features:
37
+ - name: version_id
38
+ dtype: string
39
+ - name: type
40
+ dtype: string
41
+ - name: jurisdiction
42
+ dtype: string
43
+ - name: source
44
+ dtype: string
45
+ - name: citation
46
+ dtype: string
47
+ - name: url
48
+ dtype: string
49
+ - name: is_last_chunk
50
+ dtype: bool
51
+ - name: text
52
+ dtype: string
53
+ - name: embedding
54
+ list: float32
55
+ config_name: train
56
+ splits:
57
+ - name: train
58
+ num_bytes: 28500857221
59
+ num_examples: 5208238
60
+ download_size: 45586801753
61
+ dataset_size: 28500857221
62
  ---
63
+ <!-- To update the above `dataset_info` section, please run the following command: `datasets-cli test open_australian_legal_embeddings.py --save_info --all_configs`. -->
64
+
65
+ # **Open Australian Legal Embeddings ‍⚖️**
66
+ <a href="https://huggingface.co/datasets/umarbutler/open-australian-legal-embeddings" alt="Release"><img src="https://img.shields.io/badge/release-v1.0.0-green"></a>
67
+
68
+ The Open Australian Legal Embeddings are the first open-source embeddings of Australian legislative and judicial documents.
69
+
70
+ 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).
71
+
72
+ 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.
73
+
74
+ 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).
75
+
76
+ ## Usage 👩‍💻
77
+ The below code snippet illustrates how the Embeddings may be loaded and queried via the [Hugging Face Datasets](https://huggingface.co/docs/datasets/index) Python library:
78
+ ```python
79
+ import itertools
80
+ import sklearn.metrics.pairwise
81
+
82
+ from datasets import load_dataset
83
+ from sentence_transformers import SentenceTransformer
84
+
85
+ model = SentenceTransformer('BAAI/bge-small-en-v1.5')
86
+ instruction = 'Represent this sentence for searching relevant passages: '
87
+
88
+ oale = load_dataset('umarbutler/open_australian_legal_embeddings', split='train', streaming=True) # Set `streaming` to `False` if you wish to load the entire dataset into memory (unadvised unless you have at least 64 GB of RAM).
89
+
90
+ # Sample the first 100,000 embeddings.
91
+ sample = list(itertools.islice(oale, 100000))
92
+
93
+ # Embed a query.
94
+ query = model.encode(instruction + 'Who is the Governor-General of Australia?', normalize_embeddings=True)
95
+
96
+ # Identify the most similar embedding to the query.
97
+ similarities = sklearn.metrics.pairwise.cosine_similarity([query], [embedding['embedding'] for embedding in sample])
98
+ most_similar_index = similarities.argmax()
99
+ most_similar = sample[most_similar_index]
100
+
101
+ # Print the most similar text.
102
+ print(most_similar['text'])
103
+ ```
104
+
105
+ To speed up the loading of the Embeddings, you may wish to install [`orjson`](https://github.com/ijl/orjson).
106
+
107
+ ## Structure 🗂️
108
+ The Embeddings are stored in [`data/embeddings.jsonl`](https://huggingface.co/datasets/umarbutler/open-australian-legal-embeddings/blob/main/data/embeddings.jsonl), a json lines file where each line is a list of 384 32-bit floating point numbers. Associated metadata is stored in [`data/metadatas.jsonl`](https://huggingface.co/datasets/umarbutler/open-australian-legal-embeddings/blob/main/data/metadatas.jsonl) and the corresponding texts are located in [`data/texts.jsonl`](https://huggingface.co/datasets/umarbutler/open-australian-legal-embeddings/blob/main/data/texts.jsonl).
109
+
110
+ The metadata fields are the same as those used for the [Open Australian Legal Corpus](https://huggingface.co/datasets/umarbutler/open-australian-legal-corpus#structure-%F0%9F%97%82%EF%B8%8F), barring the `text` field, which was removed, and with the addition of the `is_last_chunk` key, which is a boolean flag for whether a text is the last chunk of a document (used to detect and remove corrupted documents when creating and updating the Embeddings).
111
+
112
+ ## Creation 🧪
113
+ All documents in the [Open Australian Legal Corpus](https://huggingface.co/datasets/umarbutler/open-australian-legal-corpus#statistics-%F0%9F%93%8A) were split into semantically meaningful chunks up to 512-tokens-long (as determined by [`bge-small-en-v1.5`](https://huggingface.co/BAAI/bge-small-en-v1.5)'s tokeniser) with the [`semchunk`](https://github.com/umarbutler/semchunk) Python library. These chunks included a header embedding documents' titles, jurisdictions and types in the following format:
114
+ ```perl
115
+ Title: {title}
116
+ Jurisdiction: {jurisdiction}
117
+ Type: {type}
118
+ {text}
119
+ ```
120
+
121
+ The chunks were then vectorised by [`bge-small-en-v1.5`](https://huggingface.co/BAAI/bge-small-en-v1.5) on a single GeForce RTX 2080 Ti with a batch size of 32 via the [`SentenceTransformers`](https://www.sbert.net/) library.
122
+
123
+ The resulting embeddings were serialised as json-encoded lists of floats by [`orjson`](https://github.com/ijl/orjson) and stored in [`data/embeddings.jsonl`](https://huggingface.co/datasets/umarbutler/open-australian-legal-embeddings/blob/main/data/embeddings.jsonl). The corresponding metadata and texts (with their headers removed) were saved to [`data/metadatas.jsonl`](https://huggingface.co/datasets/umarbutler/open-australian-legal-embeddings/blob/main/data/metadatas.jsonl) and [`data/texts.jsonl`](https://huggingface.co/datasets/umarbutler/open-australian-legal-embeddings/blob/main/data/texts.jsonl), respectively.
124
+
125
+ ## Changelog 🔄
126
+ All notable changes to the Embeddings are documented in its [Changelog 🔄](https://huggingface.co/datasets/umarbutler/open-australian-legal-embeddings/blob/main/CHANGELOG.md).
127
+
128
+ This project adheres to [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
129
+
130
+ ## Licence 📜
131
+ 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).
132
+
133
+ ## Citation 🔖
134
+ If you've relied on the Embeddings for your work, please cite:
135
+ ```latex
136
+ @misc{butler-2023-open-australian-legal-embeddings,
137
+ author = {Butler, Umar},
138
+ year = {2023},
139
+ title = {Open Australian Legal Embeddings},
140
+ publisher = {Hugging Face},
141
+ version = {1.0.0},
142
+ url = {https://huggingface.co/datasets/umarbutler/open-australian-legal-embeddings}
143
+ }
144
+ ```
145
+
146
+ ## Acknowledgements 🙏
147
+ In the spirit of reconciliation, the author acknowledges the Traditional Custodians of Country throughout Australia and their connections to land, sea and community. He pays his respect to their Elders past and present and extends that respect to all Aboriginal and Torres Strait Islander peoples today.
148
+
149
+ The author thanks the creators of the many Python libraries relied upon in the creation of the Embeddings.
150
+
151
+ Finally, the author is eternally grateful for the endless support of his wife and her willingness to put up with many a late night spent writing code and quashing bugs.