File size: 9,823 Bytes
0f518ee
ceb2f41
 
 
 
 
 
 
 
0f518ee
ceb2f41
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0f518ee
ceb2f41
 
 
 
d5f41af
 
 
 
 
bb606b7
 
 
27682d9
 
 
 
 
 
 
 
bb606b7
27682d9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bb606b7
 
1b30c5c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21c086d
 
 
bb606b7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2a9a623
21c086d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bb606b7
21c086d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bb606b7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27682d9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bb606b7
27682d9
 
 
 
 
 
 
 
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
---
language:
- fr
license: cc-by-4.0
task_categories:
- question-answering
- text-generation
- table-question-answering
pretty_name: The Laws, centralizing legal texts for better use
dataset_info:
- config_name: fr
  features:
  - name: jurisdiction
    dtype: string
  - name: language
    dtype: string
  - name: text
    dtype: string
  - name: html
    dtype: string
  - name: title_main
    dtype: string
  - name: title_alternative
    dtype: string
  - name: id_sub
    dtype: string
  - name: id_main
    dtype: string
  - name: url_sourcepage
    dtype: string
  - name: url_sourcefile
    dtype: 'null'
  - name: date_publication
    dtype: string
  - name: date_signature
    dtype: 'null'
  - name: uuid
    dtype: string
  - name: text_hash
    dtype: string
  splits:
  - name: train
    num_bytes: 531412652
    num_examples: 162702
  download_size: 212898761
  dataset_size: 531412652
configs:
- config_name: fr
  data_files:
  - split: train
    path: fr/train-*
tags:
- legal
- droit
- fiscalité
- taxation
- δεξιά
- recht
- derecho
---
## Dataset Description
- **Repository:** https://huggingface.co/datasets/HFforLegal/laws
- **Leaderboard:** N/A
- **Point of Contact:** [Louis Brulé Naudet](mailto:louisbrulenaudet@icloud.com)

<img src="assets/thumbnail.png">
  
# The Laws, centralizing legal texts for better use, a community Dataset.

The Laws Dataset is a comprehensive collection of legal texts from various countries, centralized in a common format. This dataset aims to improve the development of legal AI models by providing a standardized, easily accessible corpus of global legal documents.

<div class="not-prose bg-gradient-to-r from-gray-50-to-white text-gray-900 border" style="border-radius: 8px; padding: 0.5rem 1rem;">
    <p>Join us in our mission to make AI more accessible and understandable for the legal world, ensuring that the power of language models can be harnessed effectively and ethically in the pursuit of justice.</p>
</div>

## Objective

The primary objective of this dataset is to centralize laws from around the world in a common format, thereby facilitating:

1. Comparative legal studies
2. Development of multilingual legal AI models
3. Cross-jurisdictional legal research
4. Improvement of legal technology tools

By providing a standardized dataset of global legal texts, we aim to accelerate the development of AI models in the legal domain, enabling more accurate and comprehensive legal analysis across different jurisdictions.

## Dataset Structure

The dataset contains the following columns:

1. **jurisdiction**: Capitalized ISO 3166-1 alpha-2 code representing the country or jurisdiction. This column is useful when stacking data from different jurisdictions.
2. **language**: Non-capitalized ISO 639-1 code representing the language of the document. This is particularly useful for multilingual jurisdictions.
3. **text**: The main textual content of the document.
4. **html**: An HTML-structured version of the text. This may include additional structure such as XML (Akoma Ntoso).
5. **title_main**: The primary title of the document. This replaces the 'book' column, as many modern laws are not structured or referred to as 'books'.
6. **title_alternative**: A list of official and non-official (nickname) titles for the document.
7. **id_sub**: Identifier for lower granularity items within the document, such as specific article numbers. This replaces the 'id' column.
8. **id_main**: Document identifier for the main document, such as the European Legislation Identifier (ELI).
9. **url_sourcepage**: The source URL of the web page where the document is published.
10. **url_sourcefile**: The source URL of the document file (e.g., PDF file).
11. **date_publication**: The date when the document was published.
12. **date_signature**: The date when the document was signed.
13. **uuid**: A universally unique identifier for each row in the dataset.
14. **text_hash**: A SHA-256 hash of the 'text' column, useful for verifying data integrity.
15. **formatted_date**: The publication date formatted as 'YYYY-MM-DD HH:MM:SS', derived from the 'date_publication' column.

This structure ensures comprehensive metadata for each legal document, facilitating easier data management, cross-referencing, and analysis across different jurisdictions and languages.
Easy-to-use script for hashing the `text`:

Datasets version:

```python
import hashlib
import datasets

def hash(
  text: str
) -> str:
    """
    Create or update the hash of the document content.

    This function takes a text input, converts it to a string, encodes it in UTF-8, 
    and then generates a SHA-256 hash of the encoded text.

    Parameters
    ----------
    text : str
        The text content to be hashed.

    Returns
    -------
    str
        The SHA-256 hash of the input text, represented as a hexadecimal string.
    """
    return hashlib.sha256(str(text).encode()).hexdigest()

dataset = dataset.map(lambda x: {"hash": hash(x["document"])})
```

Polars version:

```python
import polars as pl
import hashlib

def add_text_hash_column(
    df: pl.DataFrame,
    text_column: str = "text",
    hash_column: str = "text_hash"
) -> pl.DataFrame:
    """
    Add a column with SHA-256 hash values of a specified text column to a Polars DataFrame.

    This function computes the SHA-256 hash of the values in the specified text column
    and adds it as a new column to the DataFrame.

    Parameters
    ----------
    df : pl.DataFrame
        The input Polars DataFrame.
    text_column : str, optional
        The name of the column containing the text to be hashed (default is "text").
    hash_column : str, optional
        The name of the new column to be added with hash values (default is "text_hash").

    Returns
    -------
    pl.DataFrame
        A new DataFrame with the hash column added.

    Examples
    --------
    >>> import polars as pl
    >>> df = pl.DataFrame({"text": ["Hello", "World", "OpenAI"]})
    >>> df_with_hash = add_text_hash_column(df)
    >>> print(df_with_hash)
    shape: (3, 2)
    ┌────────┬──────────────────────────────────────────────────────────────────┐
    │ text   ┆ text_hash                                                        │
    │ ---    ┆ ---                                                              │
    │ str    ┆ str                                                              │
    ╞════════╪══════════════════════════════════════════════════════════════════╡
    │ Hello  ┆ 185f8db32271fe25f561a6fc938b2e264306ec304eda518007d1764826381969 │
    │ World  ┆ 78ae647dc5544d227130a0682a51e30bc7777fbb6d8a8f17007463a3ecd1d524 │
    │ OpenAI ┆ 0c3f4a61f7e5d29abc29d63f1a0cad36c49ffd5b5c0b5b38ce0c7aa0bdc94696 │
    └────────┴──────────────────────────────────────────────────────────────────┘

    Raises
    ------
    ValueError
        If the specified text_column is not found in the DataFrame.
    """
    if text_column not in df.columns:
        raise ValueError(f"Column '{text_column}' not found in the DataFrame.")

    return df.with_columns(
        pl.col(text_column)
        .map_elements(lambda x: hashlib.sha256(str(x).encode()).hexdigest())
        .alias(hash_column)
    )

dataframe = add_text_hash_column(dataframe)
```

## Upload to the Hub

Here is a code snippet to push dedicated config (in this example for France) to the HF hub:

```python
hf_dataset.push_to_hub(
    repo_id="HFforLegal/laws-new",
    config_name="fr",
    split="train",
)
```

## Country-based Configs

The dataset uses country-based configs to organize legal documents from different jurisdictions. Each config is identified by the ISO 3166-1 alpha-2 code of the corresponding country.

### ISO 3166-1 alpha-2 Codes

ISO 3166-1 alpha-2 codes are two-letter country codes defined in ISO 3166-1, part of the ISO 3166 standard published by the International Organization for Standardization (ISO).

Some examples of ISO 3166-1 alpha-2 codes:
- France: fr
- United States: us
- United Kingdom: gb
- Germany: de
- Japan: jp
- Brazil: br
- Australia: au

Before submitting a new split, please make sure the proposed split fits within the ISO code for the related country. 

## Ethical Considerations

While this dataset provides a valuable resource for legal AI development, users should be aware of the following ethical considerations:

- Privacy: Ensure that all personal information has been properly anonymized.
- Bias: Be aware of potential biases in the source material and in the selection of included laws.
- Currency: Laws change over time. Always verify that you're working with the most up-to-date version of a law for any real-world application.
- Jurisdiction: Legal interpretations can vary by jurisdiction. AI models trained on this data should not be used as a substitute for professional legal advice.

## Citing & Authors

If you use this dataset in your research, please use the following BibTeX entry.

```BibTeX
@misc{HFforLegal2024,
  author =       {Louis Brulé Naudet},
  title =        {The Laws, centralizing legal texts for better use},
  year =         {2024}
  howpublished = {\url{https://huggingface.co/datasets/HFforLegal/laws}},
}
```

## Feedback

If you have any feedback, please reach out at [louisbrulenaudet@icloud.com](mailto:louisbrulenaudet@icloud.com).