@mailwoman/corpus 11.4.0 → 12.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/data/address-source-register.json +9 -1
- package/data/builds/v0.8.22-nz-overlay/OVERLAY_PLAN.json +19 -0
- package/data/builds/v0.8.22-wofrank-overlay/OVERLAY_PLAN.json +51 -0
- package/data/builds/v0.8.24-everyplace/inputs.json +35 -0
- package/data/license-decisions.json +9 -1
- package/data/training-configs/v8.14.0-base-c6-wofreps-cursor-v0822-s42.yaml +926 -0
- package/data/training-configs/v8.15.0-base-c6-wofreps-cursor-emit-v0822-s42.yaml +973 -0
- package/data/training-configs/v8.16.0-base-c6-wofreps-positions-v0822-s42.yaml +988 -0
- package/data/training-configs/v8.17.0-stage1-gazetteer-v0822-s42.yaml +557 -0
- package/data/training-configs/v8.17.0-stage2-corpus-v0822-s42.yaml +1008 -0
- package/data/training-configs/v8.18.0-gazetteer-then-mixture-v0822-s42.yaml +1225 -0
- package/data/training-configs/v8.19.0-nz-v0822-s42.yaml +870 -0
- package/data/training-configs/v8.20.0-wofrank-v0822-s42.yaml +863 -0
- package/data/training-configs/v8.21.0-outcomes-v0822-s42.yaml +873 -0
- package/data/training-configs/v8.22.0-stage1-everyplace-v0824-s42.yaml +374 -0
- package/data/training-configs/v8.22.0-stage2-corpus-v0824-s42.yaml +808 -0
- package/data/training-configs/v8.22.1-stage1-everyplace-v0824-s42.yaml +376 -0
- package/data/training-configs/v8.22.1-stage2-corpus-v0824-s42.yaml +793 -0
- package/data/training-configs/v9.0.0-bytestem-v090-s42.yaml +665 -0
- package/data/training-manifests/v0.8.22-nz-overlay.effective.json +2556 -0
- package/data/training-manifests/v0.8.22-nz-overlay.json +9000 -0
- package/data/training-manifests/v0.8.22-wofrank-overlay.json +9000 -0
- package/data/training-manifests/v0.8.24-everyplace-overlay.json +9000 -0
- package/data/training-manifests/v0.9.0-compact.effective.json +2556 -0
- package/data/training-manifests/v0.9.0-compact.json +9000 -0
- package/lib/adapters/wof/admin/json/adapter.ts +38 -3
- package/lib/adapters/wof/json-rows.ts +84 -5
- package/lib/adapters/wof/sample.ts +42 -6
- package/lib/build/code-hash.ts +1 -1
- package/lib/cjk/foreign-places.ts +1 -1
- package/lib/kr/adapters/localdata/permit-rows.ts +1 -1
- package/lib/parquet/schema.ts +7 -0
- package/lib/tools/anthropic/batches.ts +221 -0
- package/lib/tools/anthropic/labeling.ts +263 -0
- package/lib/tools/compact-v9.ts +872 -0
- package/lib/tools/fetch/wikidata/vital-places/entities.ts +20 -2
- package/lib/tools/fetch/wikidata/vital-places/qrank.ts +5 -4
- package/lib/tools/fragment-assay.run.ts +2 -1
- package/lib/tools/name-roles/name-roles.run.ts +296 -0
- package/lib/tools/name-roles/prompt.ts +253 -0
- package/lib/tools/overlay/deletions.ts +1 -1
- package/lib/tools/overlay/draw-weight.ts +275 -0
- package/lib/tools/overlay/manifest.ts +36 -5
- package/lib/tools/place-twins/place-twins.run.ts +528 -0
- package/lib/tools/place-twins/prompt.ts +276 -0
- package/lib/tools/prominent-shapes/prominent-shapes.run.ts +420 -0
- package/lib/tools/prominent-shapes/prompt.ts +189 -0
- package/lib/tools/prominent-shapes/read-seeds.ts +286 -0
- package/lib/tools/prominent-shapes/seeds.ts +281 -0
- package/lib/tools/prominent-shapes/validate.ts +563 -0
- package/lib/training/config/admission.ts +9 -2
- package/lib/training/config/schema.ts +84 -0
- package/lib/types.ts +23 -0
- package/lib/us/adapters/usgov/nad/adapter.ts +8 -3
- package/lib/utils/split.ts +1 -1
- package/out/adapters/wof/admin/json/adapter.d.ts +7 -0
- package/out/adapters/wof/admin/json/adapter.d.ts.map +1 -1
- package/out/adapters/wof/admin/json/adapter.js +28 -3
- package/out/adapters/wof/admin/json/adapter.js.map +1 -1
- package/out/adapters/wof/json-rows.d.ts +8 -0
- package/out/adapters/wof/json-rows.d.ts.map +1 -1
- package/out/adapters/wof/json-rows.js +56 -4
- package/out/adapters/wof/json-rows.js.map +1 -1
- package/out/adapters/wof/sample.d.ts +12 -0
- package/out/adapters/wof/sample.d.ts.map +1 -1
- package/out/adapters/wof/sample.js +37 -6
- package/out/adapters/wof/sample.js.map +1 -1
- package/out/build/code-hash.js +1 -1
- package/out/build/code-hash.js.map +1 -1
- package/out/cjk/foreign-places.js +1 -1
- package/out/cjk/foreign-places.js.map +1 -1
- package/out/kr/adapters/localdata/permit-rows.js +1 -1
- package/out/kr/adapters/localdata/permit-rows.js.map +1 -1
- package/out/parquet/schema.d.ts +6 -0
- package/out/parquet/schema.d.ts.map +1 -1
- package/out/parquet/schema.js +6 -0
- package/out/parquet/schema.js.map +1 -1
- package/out/tools/anthropic/batches.d.ts +117 -0
- package/out/tools/anthropic/batches.d.ts.map +1 -0
- package/out/tools/anthropic/batches.js +141 -0
- package/out/tools/anthropic/batches.js.map +1 -0
- package/out/tools/anthropic/labeling.d.ts +97 -0
- package/out/tools/anthropic/labeling.d.ts.map +1 -0
- package/out/tools/anthropic/labeling.js +146 -0
- package/out/tools/anthropic/labeling.js.map +1 -0
- package/out/tools/compact-v9.d.ts +117 -0
- package/out/tools/compact-v9.d.ts.map +1 -0
- package/out/tools/compact-v9.js +494 -0
- package/out/tools/compact-v9.js.map +1 -0
- package/out/tools/fetch/wikidata/vital-places/entities.d.ts +3 -0
- package/out/tools/fetch/wikidata/vital-places/entities.d.ts.map +1 -1
- package/out/tools/fetch/wikidata/vital-places/entities.js +19 -1
- package/out/tools/fetch/wikidata/vital-places/entities.js.map +1 -1
- package/out/tools/fetch/wikidata/vital-places/qrank.d.ts.map +1 -1
- package/out/tools/fetch/wikidata/vital-places/qrank.js +4 -4
- package/out/tools/fetch/wikidata/vital-places/qrank.js.map +1 -1
- package/out/tools/fragment-assay.run.js +1 -1
- package/out/tools/fragment-assay.run.js.map +1 -1
- package/out/tools/name-roles/name-roles.run.d.ts +2 -0
- package/out/tools/name-roles/name-roles.run.d.ts.map +1 -0
- package/out/tools/name-roles/name-roles.run.js +230 -0
- package/out/tools/name-roles/name-roles.run.js.map +1 -0
- package/out/tools/name-roles/prompt.d.ts +166 -0
- package/out/tools/name-roles/prompt.d.ts.map +1 -0
- package/out/tools/name-roles/prompt.js +176 -0
- package/out/tools/name-roles/prompt.js.map +1 -0
- package/out/tools/overlay/deletions.js +1 -1
- package/out/tools/overlay/deletions.js.map +1 -1
- package/out/tools/overlay/draw-weight.d.ts +86 -0
- package/out/tools/overlay/draw-weight.d.ts.map +1 -0
- package/out/tools/overlay/draw-weight.js +131 -0
- package/out/tools/overlay/draw-weight.js.map +1 -0
- package/out/tools/overlay/manifest.d.ts.map +1 -1
- package/out/tools/overlay/manifest.js +29 -5
- package/out/tools/overlay/manifest.js.map +1 -1
- package/out/tools/place-twins/place-twins.run.d.ts +2 -0
- package/out/tools/place-twins/place-twins.run.d.ts.map +1 -0
- package/out/tools/place-twins/place-twins.run.js +385 -0
- package/out/tools/place-twins/place-twins.run.js.map +1 -0
- package/out/tools/place-twins/prompt.d.ts +169 -0
- package/out/tools/place-twins/prompt.d.ts.map +1 -0
- package/out/tools/place-twins/prompt.js +183 -0
- package/out/tools/place-twins/prompt.js.map +1 -0
- package/out/tools/prominent-shapes/prominent-shapes.run.d.ts +2 -0
- package/out/tools/prominent-shapes/prominent-shapes.run.d.ts.map +1 -0
- package/out/tools/prominent-shapes/prominent-shapes.run.js +302 -0
- package/out/tools/prominent-shapes/prominent-shapes.run.js.map +1 -0
- package/out/tools/prominent-shapes/prompt.d.ts +74 -0
- package/out/tools/prominent-shapes/prompt.d.ts.map +1 -0
- package/out/tools/prominent-shapes/prompt.js +156 -0
- package/out/tools/prominent-shapes/prompt.js.map +1 -0
- package/out/tools/prominent-shapes/read-seeds.d.ts +23 -0
- package/out/tools/prominent-shapes/read-seeds.d.ts.map +1 -0
- package/out/tools/prominent-shapes/read-seeds.js +219 -0
- package/out/tools/prominent-shapes/read-seeds.js.map +1 -0
- package/out/tools/prominent-shapes/seeds.d.ts +132 -0
- package/out/tools/prominent-shapes/seeds.d.ts.map +1 -0
- package/out/tools/prominent-shapes/seeds.js +178 -0
- package/out/tools/prominent-shapes/seeds.js.map +1 -0
- package/out/tools/prominent-shapes/validate.d.ts +152 -0
- package/out/tools/prominent-shapes/validate.d.ts.map +1 -0
- package/out/tools/prominent-shapes/validate.js +389 -0
- package/out/tools/prominent-shapes/validate.js.map +1 -0
- package/out/training/config/admission.d.ts +2 -1
- package/out/training/config/admission.d.ts.map +1 -1
- package/out/training/config/admission.js +9 -2
- package/out/training/config/admission.js.map +1 -1
- package/out/training/config/schema.d.ts +321 -0
- package/out/training/config/schema.d.ts.map +1 -1
- package/out/training/config/schema.js +76 -0
- package/out/training/config/schema.js.map +1 -1
- package/out/types.d.ts +21 -0
- package/out/types.d.ts.map +1 -1
- package/out/types.js +13 -0
- package/out/types.js.map +1 -1
- package/out/us/adapters/usgov/nad/adapter.d.ts +4 -0
- package/out/us/adapters/usgov/nad/adapter.d.ts.map +1 -1
- package/out/us/adapters/usgov/nad/adapter.js +8 -3
- package/out/us/adapters/usgov/nad/adapter.js.map +1 -1
- package/out/utils/split.js +1 -1
- package/out/utils/split.js.map +1 -1
- package/package.json +24 -24
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
|
|
3
|
+
/**
|
|
4
|
+
* @file The submit, status and collect steps every batch labeling tool shares.
|
|
5
|
+
*
|
|
6
|
+
* A labeling tool splits its items into chunks, one request each, and the model returns one label per item.
|
|
7
|
+
* `submitLabelingBatch` writes `chunks.jsonl` and `batch.json` to the tool's output directory,
|
|
8
|
+
* and `collectLabelingBatch` joins the finished batch back to those chunks by `custom_id`.
|
|
9
|
+
* A request that failed, stopped at `max_tokens`, or returned labels the tool's parser refuses is listed as failed
|
|
10
|
+
* with its reason, and its items receive no label.
|
|
11
|
+
*/
|
|
12
|
+
import { readLocalJSONFile } from "@mailwoman/core/fs/readers";
|
|
13
|
+
import { writeLocalJSONFile, writeLocalJSONLFile } from "@mailwoman/core/fs/writers";
|
|
14
|
+
import { JSONSpliterator } from "spliterator";
|
|
15
|
+
import { batchCostUSD, createAnthropicClient, createMessage, createMessageBatch, readMessageBatch, readMessageBatchResults, resultText, } from "#tools/anthropic/batches";
|
|
16
|
+
/**
|
|
17
|
+
* Dollars per million tokens on the batch endpoint, at half the standard price.
|
|
18
|
+
*/
|
|
19
|
+
const BATCH_PRICES = {
|
|
20
|
+
"claude-opus-5-5": { input: 2, output: 10 },
|
|
21
|
+
"claude-sonnet-5-5": { input: 1, output: 5 },
|
|
22
|
+
"claude-haiku-5-5": { input: 0.05, output: 0.25 },
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Returns the batch price of `model`.
|
|
26
|
+
*
|
|
27
|
+
* @throws When no price is recorded for it, so a cost is never reported from a guessed rate.
|
|
28
|
+
*/
|
|
29
|
+
export function batchPrice(model) {
|
|
30
|
+
const price = BATCH_PRICES[model];
|
|
31
|
+
if (!price)
|
|
32
|
+
throw new Error(`No batch price is recorded for ${model}; add it to BATCH_PRICES`);
|
|
33
|
+
return price;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Splits `items` into requests of `size`, with ids `<prefix>-<n>`.
|
|
37
|
+
*/
|
|
38
|
+
export function toLabelingChunks(items, size, prefix) {
|
|
39
|
+
if (!Number.isInteger(size) || size < 1)
|
|
40
|
+
throw new Error(`A chunk holds a whole number of items, and --chunk was ${size}`);
|
|
41
|
+
const chunks = [];
|
|
42
|
+
for (let start = 0; start < items.length; start += size) {
|
|
43
|
+
chunks.push({ custom_id: `${prefix}-${chunks.length}`, items: items.slice(start, start + size) });
|
|
44
|
+
}
|
|
45
|
+
return chunks;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Sends `count` evenly spaced chunks one at a time at the standard price.
|
|
49
|
+
*
|
|
50
|
+
* @returns Each chunk with its labels and token use, and the batch cost per request those requests imply.
|
|
51
|
+
* @throws When a response stops at `max_tokens` or the parser refuses it,
|
|
52
|
+
* since a batch of the same requests would fail the same way.
|
|
53
|
+
*/
|
|
54
|
+
export async function pilotLabelingRequests(chunks, count, settings, toParams, parse) {
|
|
55
|
+
const client = createAnthropicClient();
|
|
56
|
+
const stride = Math.max(1, Math.floor(chunks.length / count));
|
|
57
|
+
const requests = [];
|
|
58
|
+
const results = [];
|
|
59
|
+
for (let n = 0; n < count && n * stride < chunks.length; n++) {
|
|
60
|
+
const chunk = chunks[n * stride];
|
|
61
|
+
const result = await createMessage(client, { custom_id: chunk.custom_id, params: toParams(chunk.items, settings) });
|
|
62
|
+
const text = resultText(result);
|
|
63
|
+
if (text == null)
|
|
64
|
+
throw new Error(`${chunk.custom_id} stopped at ${result.result.message?.stop_reason ?? "no message"}`);
|
|
65
|
+
requests.push({ chunk, labels: parse(text, chunk.items), usage: result.result.message.usage });
|
|
66
|
+
results.push(result);
|
|
67
|
+
}
|
|
68
|
+
return { requests, batchCostPerRequestUSD: batchCostUSD(results, batchPrice(settings.model)) / results.length };
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Writes `chunks.jsonl`, creates one batch of the chunks, and records it in `batch.json`.
|
|
72
|
+
*/
|
|
73
|
+
export async function submitLabelingBatch(out, chunks, settings, toParams) {
|
|
74
|
+
batchPrice(settings.model);
|
|
75
|
+
await writeLocalJSONLFile(chunks, out("chunks.jsonl"));
|
|
76
|
+
const batch = await createMessageBatch(createAnthropicClient(), chunks.map((chunk) => ({ custom_id: chunk.custom_id, params: toParams(chunk.items, settings) })));
|
|
77
|
+
const record = {
|
|
78
|
+
id: batch.id,
|
|
79
|
+
...settings,
|
|
80
|
+
requests: chunks.length,
|
|
81
|
+
items: chunks.reduce((sum, chunk) => sum + chunk.items.length, 0),
|
|
82
|
+
};
|
|
83
|
+
await writeLocalJSONFile(record, out("batch.json"));
|
|
84
|
+
return record;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Reads the state of the batch `batch.json` records.
|
|
88
|
+
*/
|
|
89
|
+
export async function readLabelingBatch(out) {
|
|
90
|
+
const { id } = await readLocalJSONFile(out("batch.json"));
|
|
91
|
+
return readMessageBatch(createAnthropicClient(), id);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Joins the finished batch to its chunks and writes `failed-chunks.jsonl`.
|
|
95
|
+
*
|
|
96
|
+
* @returns Every labeled item beside its label, the failed requests, the result
|
|
97
|
+
* count per outcome type, and the dollars the batch cost.
|
|
98
|
+
* @throws When the batch is still in progress.
|
|
99
|
+
*/
|
|
100
|
+
export async function collectLabelingBatch(out, parse) {
|
|
101
|
+
const record = await readLocalJSONFile(out("batch.json"));
|
|
102
|
+
const chunks = await JSONSpliterator.fromAsync(out("chunks.jsonl")).toArray();
|
|
103
|
+
const results = await readMessageBatchResults(createAnthropicClient(), record.id);
|
|
104
|
+
const byCustomID = new Map(results.map((result) => [result.custom_id, result]));
|
|
105
|
+
const labeled = [];
|
|
106
|
+
const failed = [];
|
|
107
|
+
for (const chunk of chunks) {
|
|
108
|
+
const result = byCustomID.get(chunk.custom_id);
|
|
109
|
+
const text = result ? resultText(result) : null;
|
|
110
|
+
if (!result || text == null) {
|
|
111
|
+
const reason = result
|
|
112
|
+
? `${result.result.type}:${result.result.message?.stop_reason ?? "no message"}`
|
|
113
|
+
: "no result line";
|
|
114
|
+
failed.push({ custom_id: chunk.custom_id, reason, items: chunk.items.length });
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
try {
|
|
118
|
+
const labels = parse(text, chunk.items);
|
|
119
|
+
for (const [i, item] of chunk.items.entries()) {
|
|
120
|
+
labeled.push({ item, label: labels[i] });
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
failed.push({ custom_id: chunk.custom_id, reason: error.message, items: chunk.items.length });
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
await writeLocalJSONLFile(failed, out("failed-chunks.jsonl"));
|
|
128
|
+
return {
|
|
129
|
+
record,
|
|
130
|
+
labeled,
|
|
131
|
+
failed,
|
|
132
|
+
resultsByType: countEach(results.map((result) => result.result.type)),
|
|
133
|
+
costUSD: Number(batchCostUSD(results, batchPrice(record.model)).toFixed(2)),
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Counts each distinct value.
|
|
138
|
+
*/
|
|
139
|
+
export function countEach(values) {
|
|
140
|
+
const counts = {};
|
|
141
|
+
for (const value of values) {
|
|
142
|
+
counts[value] = (counts[value] ?? 0) + 1;
|
|
143
|
+
}
|
|
144
|
+
return counts;
|
|
145
|
+
}
|
|
146
|
+
//# sourceMappingURL=labeling.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"labeling.js","sourceRoot":"","sources":["../../../lib/tools/anthropic/labeling.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAClE,kEAAkE;AAElE;;;;;;;;GAQG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAA;AAC9D,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAA;AAEpF,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAE7C,OAAO,EACN,YAAY,EACZ,qBAAqB,EACrB,aAAa,EACb,kBAAkB,EAClB,gBAAgB,EAChB,uBAAuB,EACvB,UAAU,GAMV,MAAM,0BAA0B,CAAA;AAEjC;;GAEG;AACH,MAAM,YAAY,GAA+B;IAChD,iBAAiB,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE;IAC3C,mBAAmB,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE;IAC5C,kBAAkB,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE;CACjD,CAAA;AAED;;;;GAIG;AACH,MAAM,UAAU,UAA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,EAAE,SAAS,EAAE,KAAK,CAAC,SAAS,EAAE,MAAM,EAAG,KAAe,CAAC,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,CAAA;QACzG,CAAC;IACF,CAAC;IAED,MAAM,mBAAmB,CAAC,MAAM,EAAE,GAAG,CAAC,qBAAqB,CAAC,CAAC,CAAA;IAE7D,OAAO;QACN,MAAM;QACN,OAAO;QACP,MAAM;QACN,aAAa,EAAE,SAAS,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACrE,OAAO,EAAE,MAAM,CAAC,YAAY,CAAC,OAAO,EAAE,UAAU,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;KAC3E,CAAA;AACF,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,SAAS,CAAC,MAAwB;IACjD,MAAM,MAAM,GAA2B,EAAE,CAAA;IAEzC,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC5B,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAA;IACzC,CAAC;IAED,OAAO,MAAM,CAAA;AACd,CAAC"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { type PathBuilderLike } from "path-ts";
|
|
2
|
+
import { type DuckDBLimits } from "#parquet/duckdb";
|
|
3
|
+
/**
|
|
4
|
+
* Default maximum number of Tier-2 train rows kept per digit-masked skeleton bucket.
|
|
5
|
+
*/
|
|
6
|
+
export declare const DEFAULT_SKELETON_CAP = 6;
|
|
7
|
+
/**
|
|
8
|
+
* Default Tier-2 dense register sources subject to cross-source deduplication and skeleton capping.
|
|
9
|
+
*/
|
|
10
|
+
export declare const DEFAULT_TIER2_SOURCES: readonly ["usgov-nad", "ban", "ban-gp", "ban-gf", "ban-mq", "ban-re", "ban-yt", "ban-bl", "ban-mf", "ban-pm", "ban-wf", "ban-pf", "usgov-nppes", "tiger", "usgov-usgs-structures", "state-ia-contractors", "state-ny-notaries", "state-tx-notaries", "overture", "overture-latam", "gleif-lei"];
|
|
11
|
+
/**
|
|
12
|
+
* Options for {@linkcode compactCorpusV9}.
|
|
13
|
+
*/
|
|
14
|
+
export interface CompactCorpusV9Options {
|
|
15
|
+
/**
|
|
16
|
+
* Input corpus directory holding `MANIFEST.json`, or direct path to `MANIFEST.json`.
|
|
17
|
+
*/
|
|
18
|
+
inPath: PathBuilderLike;
|
|
19
|
+
/**
|
|
20
|
+
* Output directory for compacted Parquet files, `MANIFEST.json`, and `COMPACTION_REPORT.json`.
|
|
21
|
+
*/
|
|
22
|
+
outDir: PathBuilderLike;
|
|
23
|
+
/**
|
|
24
|
+
* Output `corpus_version` recorded in `MANIFEST.json`.
|
|
25
|
+
*
|
|
26
|
+
* Defaults to `<input version>-v9-compact`.
|
|
27
|
+
*/
|
|
28
|
+
version?: string;
|
|
29
|
+
/**
|
|
30
|
+
* Maximum Tier-2 train rows kept per `(country, labels, digit-masked raw)` skeleton bucket.
|
|
31
|
+
*
|
|
32
|
+
* @default 6
|
|
33
|
+
*/
|
|
34
|
+
skeletonCap?: number;
|
|
35
|
+
/**
|
|
36
|
+
* Optional cap for rare Tier-2 pattern rows (`unit`, `po_box`, `cedex`,
|
|
37
|
+
* `intersection_a`, `venue`, `building_name`, `building_number`).
|
|
38
|
+
*
|
|
39
|
+
* A `null` value keeps rare patterns uncapped.
|
|
40
|
+
*
|
|
41
|
+
* @default null
|
|
42
|
+
*/
|
|
43
|
+
rareSkeletonCap?: number | null;
|
|
44
|
+
/**
|
|
45
|
+
* Sources treated as Tier-2 dense registers.
|
|
46
|
+
*
|
|
47
|
+
* Every other source is treated as Tier 1.
|
|
48
|
+
*
|
|
49
|
+
* @default {@linkcode DEFAULT_TIER2_SOURCES}
|
|
50
|
+
*/
|
|
51
|
+
tier2Sources?: readonly string[];
|
|
52
|
+
/**
|
|
53
|
+
* Optional path prefix written into `MANIFEST.json` entries.
|
|
54
|
+
*
|
|
55
|
+
* Defaults to the local `outDir` path.
|
|
56
|
+
*/
|
|
57
|
+
modalRoot?: string;
|
|
58
|
+
/**
|
|
59
|
+
* Optional DuckDB memory/thread/spill settings.
|
|
60
|
+
*/
|
|
61
|
+
limits?: DuckDBLimits;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Per-source row counts across compaction stages.
|
|
65
|
+
*/
|
|
66
|
+
export interface CompactSourceStats {
|
|
67
|
+
source: string;
|
|
68
|
+
tier: 1 | 2;
|
|
69
|
+
inputTrainRows: number;
|
|
70
|
+
inputValRows: number;
|
|
71
|
+
inputTestRows: number;
|
|
72
|
+
keptTrainRows: number;
|
|
73
|
+
keptValRows: number;
|
|
74
|
+
keptTestRows: number;
|
|
75
|
+
droppedAugmentationRows: number;
|
|
76
|
+
droppedDedupRows: number;
|
|
77
|
+
droppedSkeletonCapRows: number;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Summary report written to `COMPACTION_REPORT.json` beside the compacted `MANIFEST.json`.
|
|
81
|
+
*/
|
|
82
|
+
export interface CompactionReport {
|
|
83
|
+
compacted_at: string;
|
|
84
|
+
input_manifest: string;
|
|
85
|
+
corpus_version: string;
|
|
86
|
+
skeleton_cap: number;
|
|
87
|
+
rare_skeleton_cap: number | null;
|
|
88
|
+
tier2_sources: string[];
|
|
89
|
+
totals: {
|
|
90
|
+
input_rows: number;
|
|
91
|
+
kept_rows: number;
|
|
92
|
+
input_train_rows: number;
|
|
93
|
+
kept_train_rows: number;
|
|
94
|
+
input_val_rows: number;
|
|
95
|
+
kept_val_rows: number;
|
|
96
|
+
input_test_rows: number;
|
|
97
|
+
kept_test_rows: number;
|
|
98
|
+
dropped_augmentation_rows: number;
|
|
99
|
+
dropped_dedup_rows: number;
|
|
100
|
+
dropped_skeleton_cap_rows: number;
|
|
101
|
+
};
|
|
102
|
+
sources: CompactSourceStats[];
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Result of {@linkcode compactCorpusV9}.
|
|
106
|
+
*/
|
|
107
|
+
export interface CompactCorpusV9Result {
|
|
108
|
+
manifestPath: string;
|
|
109
|
+
reportPath: string;
|
|
110
|
+
report: CompactionReport;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Compacts a corpus manifest into a two-tier base-row v9 corpus while preserving all `val`
|
|
114
|
+
* and `test` rows and split-attribute holdout boundaries untouched.
|
|
115
|
+
*/
|
|
116
|
+
export declare function compactCorpusV9(options: CompactCorpusV9Options): Promise<CompactCorpusV9Result>;
|
|
117
|
+
//# sourceMappingURL=compact-v9.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compact-v9.d.ts","sourceRoot":"","sources":["../../lib/tools/compact-v9.ts"],"names":[],"mappings":"AAwBA,OAAO,EAA4B,KAAK,eAAe,EAAE,MAAM,SAAS,CAAA;AAExE,OAAO,EAAsD,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAMvG;;GAEG;AACH,eAAO,MAAM,oBAAoB,IAAI,CAAA;AAErC;;GAEG;AACH,eAAO,MAAM,qBAAqB,YACjC,WAAW,EACX,KAAK,EACL,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,aAAa,EACb,OAAO,EACP,uBAAuB,EACvB,sBAAsB,EACtB,mBAAmB,EACnB,mBAAmB,EACnB,UAAU,EACV,gBAAgB,EAChB,WAAW,CACF,CAAA;AAeV;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACtC;;OAEG;IACH,MAAM,EAAE,eAAe,CAAA;IACvB;;OAEG;IACH,MAAM,EAAE,eAAe,CAAA;IACvB;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAA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