Datasets:
Document embed + reduce stages in dataset card
Browse files
README.md
CHANGED
|
@@ -364,6 +364,91 @@ for sec in structure.get("sections", []):
|
|
| 364 |
print(sec["kind"], sec["label"])
|
| 365 |
```
|
| 366 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 367 |
## Trực quan hoá embedding · Embedding visualization
|
| 368 |
|
| 369 |
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. The published reducer parquet still carries `tsne_x` / `tsne_y` columns next to `umap_*` for consumers who want to render t-SNE themselves.
|
|
|
|
| 364 |
print(sec["kind"], sec["label"])
|
| 365 |
```
|
| 366 |
|
| 367 |
+
## Companion stages · `embed` + `reduce`
|
| 368 |
+
|
| 369 |
+
Alongside the default `documents-*.parquet` shards (one row per
|
| 370 |
+
document, with text + structure), the repo also carries the
|
| 371 |
+
**embed** and **reduce** pipeline outputs as separate parquet
|
| 372 |
+
bundles. Both join back to the `documents` table on the
|
| 373 |
+
`doc_name` primary key.
|
| 374 |
+
|
| 375 |
+
### `embed-*.parquet` — 2048-D dense vectors
|
| 376 |
+
|
| 377 |
+
15 shards (~93 MB each, ~1.33 GB total, 10 000 rows per shard,
|
| 378 |
+
deterministic `doc_name` ordering). One row per embeddable
|
| 379 |
+
document (**147,317** rows after dropping the 11 505 NULL-markdown
|
| 380 |
+
rows for which there is no body to embed). Schema mirrors the
|
| 381 |
+
`anle.toaan.gov.vn` corpus's embed stage exactly so cross-corpus
|
| 382 |
+
joins are straightforward:
|
| 383 |
+
|
| 384 |
+
| Field | Type | Description |
|
| 385 |
+
|---|---|---|
|
| 386 |
+
| `doc_name` | string | Join key back to `documents-*.parquet`. |
|
| 387 |
+
| `text_hash` | string | SHA-256 of the post-normalisation `markdown` (stable across re-runs). |
|
| 388 |
+
| `embedding` | list<float64> | **2 048-D** dense vector from `nvidia/llama-nemotron-embed-1b-v2` (default; other models give other dims). |
|
| 389 |
+
| `embedding_dim` | int64 | Length of `embedding` (denormalised for fast filtering, always `2048` in this release). |
|
| 390 |
+
| `embedding_model_id` | string | Model slug as the embedder backend reports it. |
|
| 391 |
+
| `embedding_text_hash` | string | SHA-256 of the exact text fed to the embedder (differs from `text_hash` when sliding-window chunking applies). |
|
| 392 |
+
| `embedding_chunks_used` | int64 | Number of windows mean-pooled into the final vector (1 when the doc fits in one window). |
|
| 393 |
+
| `embedding_chunking` | string | Chunking strategy: `off` / `sliding` / `sentence`. |
|
| 394 |
+
|
| 395 |
+
### `reduce-*.parquet` — 2-D projections + cluster ids
|
| 396 |
+
|
| 397 |
+
15 shards (~0.5 MB each, ~7 MB total, 10 000 rows per shard).
|
| 398 |
+
One row per embeddable document (**147,317** rows). PCA + t-SNE +
|
| 399 |
+
UMAP run with `cfg.reducer.n_components=2` so the `*_z` columns
|
| 400 |
+
that existed in the on-disk per-doc shards are dropped here.
|
| 401 |
+
HDBSCAN cluster ids land in `[-1, 289]` on this corpus (`-1` is
|
| 402 |
+
the noise bucket).
|
| 403 |
+
|
| 404 |
+
| Field | Type | Description |
|
| 405 |
+
|---|---|---|
|
| 406 |
+
| `doc_name` / `text_hash` | string | Join keys back to `documents-*.parquet` and `embed-*.parquet`. |
|
| 407 |
+
| `pca_x` / `pca_y` | float64 | 2-D PCA projection of the 2048-D embedding. |
|
| 408 |
+
| `tsne_x` / `tsne_y` | float64 | 2-D t-SNE projection. |
|
| 409 |
+
| `umap_x` / `umap_y` | float64 | 2-D UMAP projection (the one used in the scatter PNGs above). |
|
| 410 |
+
| `cluster_id` | int64 | HDBSCAN cluster label; `-1` is the noise / unclustered bucket. |
|
| 411 |
+
|
| 412 |
+
Quick load (each stage is a `data_files` glob; the default
|
| 413 |
+
`load_dataset("tmquan/vbpl-vn")` still resolves to the
|
| 414 |
+
`documents` config):
|
| 415 |
+
|
| 416 |
+
```python
|
| 417 |
+
from datasets import load_dataset
|
| 418 |
+
|
| 419 |
+
embed = load_dataset(
|
| 420 |
+
"tmquan/vbpl-vn",
|
| 421 |
+
data_files="embed-*.parquet",
|
| 422 |
+
split="train",
|
| 423 |
+
)
|
| 424 |
+
print(embed[0]["doc_name"], len(embed[0]["embedding"]))
|
| 425 |
+
# e.g. "100000 2048"
|
| 426 |
+
|
| 427 |
+
reduce = load_dataset(
|
| 428 |
+
"tmquan/vbpl-vn",
|
| 429 |
+
data_files="reduce-*.parquet",
|
| 430 |
+
split="train",
|
| 431 |
+
)
|
| 432 |
+
print(reduce[0]["doc_name"], reduce[0]["umap_x"], reduce[0]["cluster_id"])
|
| 433 |
+
# e.g. "100000 1.7142 -1"
|
| 434 |
+
```
|
| 435 |
+
|
| 436 |
+
To join embed-stage vectors back to the document metadata, do
|
| 437 |
+
the join client-side on `doc_name`:
|
| 438 |
+
|
| 439 |
+
```python
|
| 440 |
+
import pandas as pd
|
| 441 |
+
|
| 442 |
+
docs = load_dataset("tmquan/vbpl-vn", split="train").to_pandas()
|
| 443 |
+
embed = load_dataset("tmquan/vbpl-vn",
|
| 444 |
+
data_files="embed-*.parquet",
|
| 445 |
+
split="train").to_pandas()
|
| 446 |
+
joined = docs.merge(embed, on="doc_name", how="inner")
|
| 447 |
+
# joined now has the title / so_hieu / markdown / ... columns
|
| 448 |
+
# next to the 2048-d embedding vector for the 147 317 embeddable
|
| 449 |
+
# documents.
|
| 450 |
+
```
|
| 451 |
+
|
| 452 |
## Trực quan hoá embedding · Embedding visualization
|
| 453 |
|
| 454 |
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. The published reducer parquet still carries `tsne_x` / `tsne_y` columns next to `umap_*` for consumers who want to render t-SNE themselves.
|