Rob Kopel commited on
Commit
4c1155b
1 Parent(s): 574738a

added dataset loader

Browse files
open_australian_legal_embeddings_openai.py ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2024 Rob Kopel.
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
+ """An extension of Umar Butler's open-australian-legal-corpus dataset to include 1024 long embeddings from OpenAI's text-embedding-3-large model"""
15
+
16
+ import json
17
+ import datasets
18
+
19
+
20
+ _CITATION = """\
21
+ @misc{open-australian-legal-embeddings-openai,
22
+ title = {Open Australian Legal Embeddings OpenAI},
23
+ author={Rob Kopel},
24
+ year={2024},
25
+ version={1.0}
26
+ url={https://huggingface.co/datasets/R0bk/open-australian-legal-embeddings-openai}
27
+ }
28
+ """
29
+
30
+ _DESCRIPTION = """\
31
+ An extension of Umar Butler's open-australian-legal-corpus dataset to include 1024 long embeddings from OpenAI's text-embedding-3-large model.
32
+ If you wish to explore or deploy in your environment it can be used with open-australian-legal-explorer on github.
33
+ """
34
+
35
+ _HOMEPAGE = "https://huggingface.co/datasets/R0bk/open-australian-legal-embeddings-openai"
36
+
37
+ _LICENSE = """
38
+ Please see the open-australian-legal-corpus licence [Open Australian Legal Corpus](https://huggingface.co/datasets/umarbutler/open-australian-legal-corpus/blob/main/LICENCE.md).
39
+ """
40
+
41
+ _URLS = {
42
+ 'metadatas' : 'data/metadatas.jsonl',
43
+ 'texts' : 'data/texts.jsonl',
44
+ 'embeddings' : 'data/embeddings.jsonl',
45
+ }
46
+
47
+ class OpenAustralianLegalEmbeddingsOpenai(datasets.GeneratorBasedBuilder):
48
+ """An extension of Umar Butler's open-australian-legal-corpus dataset to include 1024 long embeddings from OpenAI's text-embedding-3-large model"""
49
+
50
+ VERSION = datasets.Version("1.0.0")
51
+
52
+ DEFAULT_CONFIG_NAME = "train"
53
+
54
+ def _info(self):
55
+ return datasets.DatasetInfo(
56
+ description=_DESCRIPTION,
57
+ features=datasets.Features(
58
+ {
59
+ 'version_id' : datasets.Value('string'),
60
+ 'type' : datasets.Value('string'),
61
+ 'jurisdiction' : datasets.Value('string'),
62
+ 'source' : datasets.Value('string'),
63
+ 'citation' : datasets.Value('string'),
64
+ 'url' : datasets.Value('string'),
65
+ 'is_last_chunk' : datasets.Value('bool'),
66
+ 'chunk_index' : datasets.Value('int'),
67
+ 'text' : datasets.Value('string'),
68
+ 'embedding' : [datasets.Value('float32')]
69
+ }
70
+ ),
71
+ homepage=_HOMEPAGE,
72
+ license=_LICENSE,
73
+ citation=_CITATION,
74
+ )
75
+
76
+ def _split_generators(self, dl_manager):
77
+ dl_files = dl_manager.download_and_extract(_URLS)
78
+ return [
79
+ datasets.SplitGenerator(
80
+ name=datasets.Split.TRAIN,
81
+ gen_kwargs={
82
+ 'metadatas_path' : dl_files['metadatas'],
83
+ 'texts_path' : dl_files['texts'],
84
+ 'embeddings_path' : dl_files['embeddings'],
85
+ }
86
+ )
87
+ ]
88
+
89
+ def _generate_examples(self, embed_path, metas_path, texts_path):
90
+ with open(embed_path, 'r') as embeds, \
91
+ open(metas_path, 'r') as metas, \
92
+ open(texts_path, 'r') as texts:
93
+
94
+ for key, (embed, meta, text) in enumerate(zip(embeds, metas, texts)):
95
+ yield key, {
96
+ **json.loads(meta),
97
+ 'text': json.loads(text),
98
+ 'embedding': json.loads(embed)
99
+ }