legi / README.md
FaheemBEG's picture
Update README.md
56f8c81 verified
|
Raw History Blame Contribute Delete
11.8 kB
---
language:
- fr
tags:
- france
- legislation
- law
- loi
- codes
- embeddings
- open-data
- government
- legifrance
pretty_name: French Consolidated Legislation Dataset (LEGI)
size_categories:
- 1M<n<10M
license: etalab-2.0
configs:
- config_name: latest
data_files: "data/legi-latest/*/*.parquet"
default: true
---
---------------------------------------------------------------------------------------------------
### 📢 Sondage 2026 : Utilisation des datasets publiques de MediaTech
Vous utilisez ce dataset ou d’autres datasets de notre collection [MediaTech](https://huggingface.co/collections/AgentPublic/mediatech) ? Votre avis compte !
Aidez-nous à améliorer nos datasets publiques en répondant à ce sondage rapide (5 min) : 👉 https://grist.numerique.gouv.fr/o/albert/forms/gF4hLaq9VvUog6c5aVDuMw/11
Merci pour votre contribution ! 🙌
---------------------------------------------------------------------------------------------------
# 🇫🇷 French Consolidated Legislation Dataset (LEGI)
This dataset contains a **semantic-ready and embedded version** of the French **full consolidated text of national legislation and regulations** as published in the official **LEGI** database by Légifrance.
The original data is downloaded from [the dedicated **DILA** open data repository](https://echanges.dila.gouv.fr/OPENDATA/LEGI) and is also published on [data.gouv.fr](https://www.data.gouv.fr/datasets/legi-codes-lois-et-reglements-consolides/).
The original and full **LEGI** dataset includes:
- All **laws, codes, decrees, circulars, deliberations, decree-laws, ordinances etc...** since 1945.
- A selection of consolidated **ministerial orders (arrêtés)**.
- All **official codes in force**, and **repealed codes**.
- And more ...
In this version, **all** status are included :
- **In force** (`VIGUEUR`) : article that applies on the current date.
- **Modified** (`MODIFIE`) : content that has been modified, so not in force anymore
- **Abrogated deferred** (`ABROGE_DIFF`) : content still valid until the end date indicated.
- **Abrogated** (`ABROGE`) : article that is no longer in force as a result of explicit repeal by a text published in the Official Journal.
- **Canceled** (`ANNULE`) : article of the code cancelled by decision of the Council of State following an appeal.
- **Disjointed** (`DISJOINT`) : ‘separate’ article of the code; its provisions are no longer applied. This separation may not be permanent; its provisions may be reinstated by a new text. This legal status is specific to tax legislation.
- **Modified stillborn** (`MODIFIE_MORT_NE`) : article amended or repealed before the date set for its entry into force shall be deemed never to have had legal existence.
- **Outdated** (`PERIME`) : article subject to implicit repeal; this is the case, for example, with Article 39 octies of the General Tax Code.
- **Transfered** (`TRANSFERE`) : article whose provisions are reproduced under another article number. Example: Article L. 821-5-2 of the code de commerce has become Article L. 821-5-3 of the same code.
- **In force deferred** (`VIGUEUR_DIFF`) : article that comes into force at a later date. When this date is known, this deferred effective status is indicated.
To keep only certain statuses, you can check out the dedicated [tutorial section below](#2-how-to-load-mediatechs-datasets-from-hugging-face-and-use-them-in-a-rag-pipeline)
Each article is chunked and vectorized using the [`BAAI/bge-m3`](https://huggingface.co/BAAI/bge-m3) embedding model, enabling use in **semantic search**, **retrieval-augmented generation (RAG)**, and **legal research** systems for example.
The dataset is splitted in subfolders by 'category' and 'code', so that the dataset is more usable for specifics use cases.
---
## 🗂️ Dataset Contents
The dataset is provided in **Parquet format** and includes the following columns:
| Column Name | Type | Description |
|---------------------|----------|-----------------------------------------------------------------------------|
| `chunk_id` | `str` | Unique chunk identifier. |
| `doc_id` | `str` | LEGI article source identifier. |
| `chunk_index` | `int` | Index of the chunk within its original document. Starting from 1. |
| `chunk_xxh64` | `str` | XXH64 hash of the `chunk_text` value. |
| `nature` | `str` | Nature of the text (e.g., `Article`). |
| `category` | `str` | Type of legislative document (e.g., `LOI`, `DECRET`, `ARRETE`, etc.). |
| `ministry` | `str` | Ministry responsible for the publication, if applicable. |
| `status` | `str` | Status of the article: `VIGUEUR` (in force), `MODIFIE` (modified) etc ... |
| `title` | `str` | Short title of the legislative document. |
| `full_title` | `str` | Full formal title of the text. |
| `subtitles` | `str` | Subtitle(s) indicating article grouping or section. |
| `number` | `str` | Article or section number. |
| `start_date` | `str` | Date the article entered into force (format: YYYY-MM-DD). |
| `end_date` | `str` | End of validity date (or `2999-01-01` if still in force). |
| `nota` | `str` | Additional notes, if present. |
| `links` | `list[dict]` | List of legal links associated with the text with metadata. |
| `text` | `str` | Textual content chunk of the article (or subsection). |
| `chunk_text` | `str` | Formatted full chunk including `full_title`, `number`, formatted `subtitles` and `text`.|
| `embeddings_bge-m3` | `str` | Embedding vector of `chunk_text` using `BAAI/bge-m3`, stored as JSON array string. |
---
## 🛠️ Data Processing Methodology
### 📥 1. Field Extraction
The following fields were extracted and/or transformed from the original source:
- **Basic fields**:
- `doc_id`, `nature`, `category`, ,`ministry`,`status`, `title`, `full_title`, `subtitles`, `number`, and `start_date`, `end_date` are extracted directly from the metadata of each article.
- **Generated fields**:
- `chunk_id`: a generated unique identifier of the chunk, combining the `doc_id` and `chunk_index`.
- `chunk_index`: is the index of the chunk of a same article. Each article has an unique `doc_id`.
- `chunk_xxh64`: is the xxh64 hash of the `chunk_text` value. It is useful to determine if the `chunk_text` value has changed from a version to another.
- **Textual fields**:
- `nota`: additional notes, also directly extracted from metadatas.
- `text`: chunk of the main text content.
- `chunk_text`: generated by concatenating `full_title`, article `number`, formatted `subtitles` and `text`.
- **List-based fields**:
- `links`: list of legal relationships associated with the article, extracted from the LEGI metadata.
Each element is a JSON object describing a link to another legal document (source or target), with fields such as:
- `title`: official title of the related document.
- `doc_id` / `text_doc_id`: LEGI or JORF identifier of the related document.
- `number` / `text_number`: article or act number when applicable.
- `category`: type of the related document (e.g. `LOI`, `DECRET`, etc.).
- `link_type`: nature of the relationship (e.g. `TXT_SOURCE`, `CITATION`).
- `link_direction`: direction of the relation, indicates whether the element carrying the link corresponds to the source or target of the link.
(e.g. `source` when the current article cites another text, `cible` when it is cited by another text).
- `nor`: NOR identifier of the related act, when available.
- `text_signature_date`: signature date of the related text (YYYY-MM-DD), when available.
### ✂️ 2. Generation of 'chunk_text'
Each article is naturally isolated and has its own `cid` value. But in case the article is too long, we have to split it in several chunks.
The Langchain's `RecursiveCharacterTextSplitter` function was used to make these chunks, which correspond to the `text` value. The parameters used are :
- `chunk_size` = 1024
- `chunk_overlap` = 0
- `length_function` = bge_m3_tokenizer
For each chunk (`text`), a `chunk_text` is constructed as follows:
``` text
"{full_title} - Article {number}
{formatted subtitles}
{text}"
```
### 🧠 3. Embeddings Generation
Each `chunk_text` was embedded using the [**`BAAI/bge-m3`**](https://huggingface.co/BAAI/bge-m3) model.
The resulting embedding vector is stored in the `embeddings_bge-m3` column as a **string**, but can easily be parsed back into a `list[float]` or NumPy array.
## 🎓 Tutorials
### 🔄 1. The chunking doesn't fit your use case?
If you need to reconstitute the original, un-chunked dataset, you can follow [this tutorial notebook available on our GitHub repository](https://github.com/etalab-ia/mediatech/blob/main/docs/reconstruct_vector_database.ipynb).
⚠️ The tutorial is only relevant for datasets that were chunked **without overlap**.
### 🤖 2. How to load MediaTech's datasets from Hugging Face and use them in a RAG pipeline ?
To learn how to load MediaTech's datasets from Hugging Face and integrate them into a Retrieval-Augmented Generation (RAG) pipeline, check out our [step-by-step RAG tutorial available on our GitHub repository !](https://github.com/etalab-ia/mediatech/blob/main/docs/hugging_face_rag_tutorial.ipynb)
### 📌 3. Embedding Use Notice
⚠️ The `embeddings_bge-m3` column is stored as a **stringified list** of floats (e.g., `"[-0.03062629,-0.017049594,...]"`).
To use it as a vector, you need to parse it into a list of floats or NumPy array.
#### Using the `datasets` library:
```python
import pandas as pd
import json
from datasets import load_dataset
# The Pyarrow library must be installed in your Python environment for this example. By doing => pip install pyarrow
dataset = load_dataset("AgentPublic/legi")
df = pd.DataFrame(dataset['train'])
df["embeddings_bge-m3"] = df["embeddings_bge-m3"].apply(json.loads)
```
#### Using downloaded local Parquet files:
```python
import pandas as pd
import json
# The Pyarrow library must be installed in your Python environment for this example. By doing => pip install pyarrow
df = pd.read_parquet(path="legi-latest/") # Assuming that all parquet files are located into this folder
df["embeddings_bge-m3"] = df["embeddings_bge-m3"].apply(json.loads)
```
You can then use the dataframe as you wish, such as by inserting the data from the dataframe into the vector database of your choice.
## 🐱 GitHub repository :
The project MediaTech is open source ! You are free to contribute or see the complete code used to build the dataset by checking the [GitHub repository](https://github.com/etalab-ia/mediatech)
## 📚 Source & License
### 🔗 Source :
- [**DILA** open data repository](https://echanges.dila.gouv.fr/OPENDATA/LEGI)
- [Data.gouv.fr : LEGI: Codes, lois et règlements consolidés ](https://www.data.gouv.fr/datasets/legi-codes-lois-et-reglements-consolides/)
### 📄 Licence :
**Open License (Etalab)** — This dataset is publicly available and can be reused under the conditions of the Etalab open license.