tmquan commited on
Commit
8b69bc7
·
verified ·
1 Parent(s): f3143c0

Vietnamese National Legal Database (vbpl.vn) corpus with structure + embedding layers

Browse files
Files changed (3) hide show
  1. README.md +35 -92
  2. embedding-legal-type-umap.png +2 -2
  3. manifest.json +1 -1
README.md CHANGED
@@ -29,14 +29,6 @@ configs:
29
  data_files:
30
  - split: train
31
  path: documents-*.parquet
32
- - config_name: embed
33
- data_files:
34
- - split: train
35
- path: embed-*.parquet
36
- - config_name: reduce
37
- data_files:
38
- - split: train
39
- path: reduce-*.parquet
40
  ---
41
 
42
  # Vietnamese National Legal Database — `vbpl.vn`
@@ -371,91 +363,34 @@ for sec in structure.get("sections", []):
371
  print(sec["kind"], sec["label"])
372
  ```
373
 
374
- ## Companion stages · `embed` + `reduce`
375
-
376
- Alongside the default `documents-*.parquet` shards (one row per
377
- document, with text + structure), the repo also carries the
378
- **embed** and **reduce** pipeline outputs as separate parquet
379
- bundles. Both join back to the `documents` table on the
380
- `doc_name` primary key. Only the **embeddable** rows
381
- (147,317 after dropping NULL-markdown
382
- docs) appear in these stages.
383
-
384
- ### `embed-*.parquet` dense vectors
385
-
386
- 15 shards (~93 MB each, ~1.33 GB total, 10 000 rows per shard,
387
- deterministic `doc_name` ordering). Schema mirrors the
388
- `anle.toaan.gov.vn` corpus's embed stage exactly so
389
- cross-corpus joins are straightforward:
390
-
391
- | Field | Type | Description |
392
- |---|---|---|
393
- | `doc_name` | string | Join key back to `documents-*.parquet`. |
394
- | `text_hash` | string | SHA-256 of the post-normalisation `markdown` (stable across re-runs). |
395
- | `embedding` | list<float64> | **2048-D** dense vector from `nvidia/llama-nemotron-embed-1b-v2` (default; other models give other dims). |
396
- | `embedding_dim` | int64 | Length of `embedding` (denormalised for fast filtering, always `2048` in this release). |
397
- | `embedding_model_id` | string | Model slug as the embedder backend reports it. |
398
- | `embedding_text_hash` | string | SHA-256 of the exact text fed to the embedder (differs from `text_hash` when sliding-window chunking applies). |
399
- | `embedding_chunks_used` | int64 | Number of windows mean-pooled into the final vector (1 when the doc fits in one window). |
400
- | `embedding_chunking` | string | Chunking strategy: `off` / `sliding` / `sentence`. |
401
-
402
- ### `reduce-*.parquet` — 2-D projections + cluster ids
403
-
404
- 15 shards (~0.5 MB each, ~7 MB total). PCA + t-SNE + UMAP run
405
- with `cfg.reducer.n_components=2` so the `*_z` columns that
406
- existed in the on-disk per-doc shards are dropped here.
407
- HDBSCAN cluster ids land in `[-1, N]` (`-1` is the noise
408
- bucket).
409
-
410
- | Field | Type | Description |
411
- |---|---|---|
412
- | `doc_name` / `text_hash` | string | Join keys back to `documents-*.parquet` and `embed-*.parquet`. |
413
- | `pca_x` / `pca_y` | float64 | 2-D PCA projection of the 2048-D embedding. |
414
- | `umap_x` / `umap_y` | float64 | 2-D UMAP projection (the one used in the scatter PNGs above). Fit globally across all rows for cross-doc comparability. |
415
- | `cluster_id` | int64 | HDBSCAN cluster label; `-1` is the noise / unclustered bucket. |
416
-
417
- Quick load (each stage is a `data_files` glob; the default
418
- `load_dataset("tmquan/vbpl-vn")` still resolves to the
419
- `documents` config):
420
-
421
- ```python
422
- from datasets import load_dataset
423
-
424
- embed = load_dataset(
425
- "tmquan/vbpl-vn",
426
- data_files="embed-*.parquet",
427
- split="train",
428
- )
429
- print(embed[0]["doc_name"], len(embed[0]["embedding"]))
430
- # e.g. "100000 2048"
431
-
432
- reduce = load_dataset(
433
- "tmquan/vbpl-vn",
434
- data_files="reduce-*.parquet",
435
- split="train",
436
- )
437
- print(reduce[0]["doc_name"], reduce[0]["umap_x"], reduce[0]["cluster_id"])
438
- # e.g. "100000 1.7142 -1"
439
  ```
440
 
441
- To join embed-stage vectors back to the document metadata, do
442
- the join client-side on `doc_name`:
443
-
444
- ```python
445
- import pandas as pd
446
-
447
- docs = load_dataset("tmquan/vbpl-vn", split="train").to_pandas()
448
- embed = load_dataset("tmquan/vbpl-vn",
449
- data_files="embed-*.parquet",
450
- split="train").to_pandas()
451
- joined = docs.merge(embed, on="doc_name", how="inner")
452
- # joined now has the title / so_hieu / markdown / ... columns
453
- # next to the 2048-D embedding vector for every embeddable doc.
454
- ```
455
 
456
  ## Trực quan hoá embedding · Embedding visualization
457
 
458
- Mỗi điểm là một văn bản pháp luật; toạ độ là vector embedding 2048-D từ `nvidia/llama-nemotron-embed-1b-v2` chiếu xuống 2D bằng UMAP, cụm bằng HDBSCAN. Sáu mặt phân hoạch: `scope`, `doc_type` (mã ngắn), `legal_type` (tên đầy đủ), `legal_area` (lĩnh vực pháp luật), `year`, `cluster_id`. Các nhãn tail-end (sau top-18) được dồn vào nhóm *Khác / Other* màu xám để chú giải đọc được. — Each dot is one legal document; coordinates are the 2D UMAP projection of a 2048-D embedding from `nvidia/llama-nemotron-embed-1b-v2`, with HDBSCAN cluster ids. Six facets: `scope`, `doc_type` (canonical short code), `legal_type` (canonical full name), `legal_area` (subject domain), `year`, `cluster_id`. Tail-end labels beyond the top 18 are collapsed into a grey *Khác / Other* bucket to keep the legend legible.
459
 
460
  ### UMAP colored by `scope`
461
 
@@ -503,9 +438,17 @@ intercepts the resulting authenticated XHRs, downloads any
503
  4. **Embed** -- `nvidia/llama-nemotron-embed-1b-v2` (2048-D) over the
504
  normalised markdown; sliding-window mean pool when a doc exceeds
505
  the model's native context window.
506
- 5. **Reduce** -- PCA + t-SNE + UMAP on the embedding matrix +
507
- HDBSCAN cluster ids. cuML on a GPU worker; sklearn / umap-learn
508
- / hdbscan otherwise.
 
 
 
 
 
 
 
 
509
 
510
  All five layers are deterministic and re-runnable; re-running any
511
  stage with the same `--limit` is a no-op (each stage skips
@@ -529,7 +472,7 @@ embedding parquets for the NULL-markdown rows are dropped from
529
  the embedding corpus entirely so the reducer fits on the
530
  embeddable rows only (147,317-row corpus).
531
 
532
- Captured: `2026-05-23T14:10:30.764933+00:00`.
533
 
534
  ## Nguồn · Source
535
 
 
29
  data_files:
30
  - split: train
31
  path: documents-*.parquet
 
 
 
 
 
 
 
 
32
  ---
33
 
34
  # Vietnamese National Legal Database — `vbpl.vn`
 
363
  print(sec["kind"], sec["label"])
364
  ```
365
 
366
+ ## Embedding + reduction artefacts
367
+
368
+ The Hub ships the **`documents` config only**
369
+ (`documents-*.parquet`, one row per document, with text +
370
+ structure). The 2048-D
371
+ `nvidia/llama-nemotron-embed-1b-v2` embeddings, the global UMAP / PCA
372
+ coordinates, and the HDBSCAN cluster ids are computed during the
373
+ build (over 147,317 embeddable rows,
374
+ i.e. all documents with non-null `markdown`) and used to render
375
+ the scatter PNGs below, but they are **not bundled as separate
376
+ parquet configs on the Hub** -- 1.3 GB of dense vectors per
377
+ re-build is too costly to ship for a corpus this size when the
378
+ embeddings are deterministic from `markdown` + a model id.
379
+ Re-derive the same matrices locally via:
380
+
381
+ ```bash
382
+ git clone https://github.com/<owner>/ViLA # the build repo
383
+ python -m packages.datasites.vbpl --pipeline embed
384
+ python -m packages.datasites.vbpl.\_reduce\_inproc # global UMAP
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
385
  ```
386
 
387
+ which yields `parquet/embeddings/<doc_name>.parquet` and
388
+ `parquet/reduced/<doc_name>.parquet` per-doc shards keyed back to
389
+ `documents.doc_name`.
 
 
 
 
 
 
 
 
 
 
 
390
 
391
  ## Trực quan hoá embedding · Embedding visualization
392
 
393
+ Mỗi điểm là một văn bản pháp luật; toạ độ là vector embedding 2048-D từ `nvidia/llama-nemotron-embed-1b-v2` chiếu xuống 2D bằng **UMAP fit globally** trên toàn bộ kho văn bản (không chia batch) để toạ độ so sánh được giữa các tài liệu. Năm mặt phân hoạch: `scope`, `doc_type` (mã ngắn), `legal_type` (tên đầy đủ), `legal_area` (lĩnh vực pháp luật), `year`. Các nhãn tail-end (sau top-18) được dồn vào nhóm *Khác / Other* màu xám để chú giải đọc được. — Each dot is one legal document; coordinates are the 2D UMAP projection of a 2048-D embedding from `nvidia/llama-nemotron-embed-1b-v2`, **fit globally across the whole corpus** so positions are directly comparable across documents. Five facets: `scope`, `doc_type` (canonical short code), `legal_type` (canonical full name), `legal_area` (subject domain), `year`. Tail-end labels beyond the top 18 are collapsed into a grey *Khác / Other* bucket to keep the legend legible.
394
 
395
  ### UMAP colored by `scope`
396
 
 
438
  4. **Embed** -- `nvidia/llama-nemotron-embed-1b-v2` (2048-D) over the
439
  normalised markdown; sliding-window mean pool when a doc exceeds
440
  the model's native context window.
441
+ 5. **Reduce** -- PCA + UMAP on the embedding matrix + HDBSCAN
442
+ cluster ids. The May-2026 rerun switched from per-batch
443
+ reduction (each Curator `DocumentBatch` independently) to a
444
+ **global in-process fit** over the full 147,317
445
+ × 2048-D matrix so the projection is comparable
446
+ across documents (`packages/datasites/vbpl/_reduce_inproc.py`).
447
+ t-SNE was dropped from the rerun because a single global fit
448
+ under `random_state=0` (single-threaded by construction) took
449
+ prohibitively long on this corpus; PCA + UMAP cover the same
450
+ visual story without it. cuML on a GPU worker; sklearn /
451
+ umap-learn / hdbscan otherwise.
452
 
453
  All five layers are deterministic and re-runnable; re-running any
454
  stage with the same `--limit` is a no-op (each stage skips
 
472
  the embedding corpus entirely so the reducer fits on the
473
  embeddable rows only (147,317-row corpus).
474
 
475
+ Captured: `2026-05-23T14:29:39.492383+00:00`.
476
 
477
  ## Nguồn · Source
478
 
embedding-legal-type-umap.png CHANGED

Git LFS Details

  • SHA256: 4aedac0773aedda56fab06301b4ed7671c6c79cdb6478e930383a6c9783d6fc9
  • Pointer size: 131 Bytes
  • Size of remote file: 431 kB

Git LFS Details

  • SHA256: 5a835d0609029a4b079df1b26dd9eb1443bd76c697ead3f7daaac42c50fd0814
  • Pointer size: 132 Bytes
  • Size of remote file: 1.98 MB
manifest.json CHANGED
@@ -536,5 +536,5 @@
536
  "share": 0.07243958645527698
537
  }
538
  },
539
- "completed_at": "2026-05-23T14:10:30.764933+00:00"
540
  }
 
536
  "share": 0.07243958645527698
537
  }
538
  },
539
+ "completed_at": "2026-05-23T14:29:39.492383+00:00"
540
  }