@mailwoman/core 9.0.0 → 9.2.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/README.md +1 -1
- package/api/responses.ts +12 -0
- package/coarse-placer/featurize.ts +0 -2
- package/coarse-placer/tools/build-dataset.ts +2 -2
- package/coarse-placer/tools/build-outlier-exposure.ts +2 -2
- package/coarse-placer/tools/build-outlier-latin.ts +14 -8
- package/coarse-placer/tools/build-outlier-oa.ts +12 -6
- package/coarse-placer/tools/eval-latin-offmap.ts +3 -4
- package/coarse-placer/tools/eval-openset.ts +3 -3
- package/coarse-placer/tools/eval-quant-compare.ts +3 -3
- package/coarse-placer/tools/eval.ts +3 -3
- package/coarse-placer/tools/fnv-hash.ts +1 -6
- package/coarse-placer/tools/index.ts +1 -1
- package/coarse-placer/tools/probe-frontier.ts +3 -4
- package/coarse-placer/tools/quantize.ts +3 -2
- package/coarse-placer/tools/train.ts +2 -2
- package/crypto/node.ts +3 -1
- package/data/internal/dictionaries/languages.csv +184 -184
- package/data/libpostal/README.md +8 -2
- package/db/schema.ts +12 -3
- package/decoder/build-tree.ts +19 -0
- package/decoder/containment.ts +5 -1
- package/decoder/index.ts +1 -0
- package/decoder/parse-diff.ts +347 -0
- package/decoder/proposals-to-tree.ts +1 -1
- package/decoder/serialize-json.ts +51 -7
- package/decoder/serialize-tuples.ts +7 -1
- package/decoder/serialize-xml.ts +1 -1
- package/decoder/tree-shape.ts +144 -0
- package/decoder/types.ts +8 -0
- package/decoder/validate-tree.ts +15 -3
- package/env/index.ts +3 -1
- package/env/paths.ts +21 -33
- package/env/schema.ts +35 -3
- package/fs/utils/formatters.ts +107 -0
- package/fs/utils/index.ts +7 -0
- package/fs/zip.ts +297 -0
- package/layers/manifest.ts +56 -15
- package/layers/schema.ts +54 -2
- package/locale/locale.ts +1 -1
- package/locale/registry.ts +1 -1
- package/objects.ts +20 -8
- package/out/api/responses.d.ts +9 -0
- package/out/api/responses.d.ts.map +1 -1
- package/out/api/responses.js +11 -0
- package/out/api/responses.js.map +1 -1
- package/out/coarse-placer/featurize.d.ts +0 -1
- package/out/coarse-placer/featurize.d.ts.map +1 -1
- package/out/coarse-placer/featurize.js.map +1 -1
- package/out/coarse-placer/tools/build-dataset.js +1 -2
- package/out/coarse-placer/tools/build-dataset.js.map +1 -1
- package/out/coarse-placer/tools/build-outlier-exposure.js +1 -2
- package/out/coarse-placer/tools/build-outlier-exposure.js.map +1 -1
- package/out/coarse-placer/tools/build-outlier-latin.d.ts.map +1 -1
- package/out/coarse-placer/tools/build-outlier-latin.js +12 -8
- package/out/coarse-placer/tools/build-outlier-latin.js.map +1 -1
- package/out/coarse-placer/tools/build-outlier-oa.d.ts.map +1 -1
- package/out/coarse-placer/tools/build-outlier-oa.js +10 -6
- package/out/coarse-placer/tools/build-outlier-oa.js.map +1 -1
- package/out/coarse-placer/tools/eval-latin-offmap.d.ts.map +1 -1
- package/out/coarse-placer/tools/eval-latin-offmap.js +2 -4
- package/out/coarse-placer/tools/eval-latin-offmap.js.map +1 -1
- package/out/coarse-placer/tools/eval-openset.js +2 -3
- package/out/coarse-placer/tools/eval-openset.js.map +1 -1
- package/out/coarse-placer/tools/eval-quant-compare.js +2 -3
- package/out/coarse-placer/tools/eval-quant-compare.js.map +1 -1
- package/out/coarse-placer/tools/eval.js +2 -3
- package/out/coarse-placer/tools/eval.js.map +1 -1
- package/out/coarse-placer/tools/fnv-hash.d.ts +1 -6
- package/out/coarse-placer/tools/fnv-hash.d.ts.map +1 -1
- package/out/coarse-placer/tools/fnv-hash.js +1 -6
- package/out/coarse-placer/tools/fnv-hash.js.map +1 -1
- package/out/coarse-placer/tools/index.d.ts +1 -1
- package/out/coarse-placer/tools/index.js +1 -1
- package/out/coarse-placer/tools/probe-frontier.d.ts.map +1 -1
- package/out/coarse-placer/tools/probe-frontier.js +2 -4
- package/out/coarse-placer/tools/probe-frontier.js.map +1 -1
- package/out/coarse-placer/tools/quantize.d.ts.map +1 -1
- package/out/coarse-placer/tools/quantize.js +2 -2
- package/out/coarse-placer/tools/quantize.js.map +1 -1
- package/out/coarse-placer/tools/train.js +1 -2
- package/out/coarse-placer/tools/train.js.map +1 -1
- package/out/crypto/node.d.ts.map +1 -1
- package/out/crypto/node.js +2 -1
- package/out/crypto/node.js.map +1 -1
- package/out/db/schema.d.ts +12 -3
- package/out/db/schema.d.ts.map +1 -1
- package/out/db/schema.js +6 -0
- package/out/db/schema.js.map +1 -1
- package/out/decoder/build-tree.d.ts.map +1 -1
- package/out/decoder/build-tree.js +17 -0
- package/out/decoder/build-tree.js.map +1 -1
- package/out/decoder/containment.d.ts.map +1 -1
- package/out/decoder/containment.js +5 -1
- package/out/decoder/containment.js.map +1 -1
- package/out/decoder/index.d.ts +1 -0
- package/out/decoder/index.d.ts.map +1 -1
- package/out/decoder/index.js +1 -0
- package/out/decoder/index.js.map +1 -1
- package/out/decoder/parse-diff.d.ts +125 -0
- package/out/decoder/parse-diff.d.ts.map +1 -0
- package/out/decoder/parse-diff.js +219 -0
- package/out/decoder/parse-diff.js.map +1 -0
- package/out/decoder/proposals-to-tree.js.map +1 -1
- package/out/decoder/serialize-json.d.ts +29 -0
- package/out/decoder/serialize-json.d.ts.map +1 -1
- package/out/decoder/serialize-json.js +20 -4
- package/out/decoder/serialize-json.js.map +1 -1
- package/out/decoder/serialize-tuples.d.ts +8 -1
- package/out/decoder/serialize-tuples.d.ts.map +1 -1
- package/out/decoder/serialize-tuples.js +7 -1
- package/out/decoder/serialize-tuples.js.map +1 -1
- package/out/decoder/serialize-xml.js +1 -1
- package/out/decoder/serialize-xml.js.map +1 -1
- package/out/decoder/tree-shape.d.ts +84 -0
- package/out/decoder/tree-shape.d.ts.map +1 -0
- package/out/decoder/tree-shape.js +98 -0
- package/out/decoder/tree-shape.js.map +1 -0
- package/out/decoder/types.d.ts +11 -0
- package/out/decoder/types.d.ts.map +1 -1
- package/out/decoder/validate-tree.d.ts +8 -0
- package/out/decoder/validate-tree.d.ts.map +1 -1
- package/out/decoder/validate-tree.js +4 -3
- package/out/decoder/validate-tree.js.map +1 -1
- package/out/env/index.d.ts +13 -1
- package/out/env/index.d.ts.map +1 -1
- package/out/env/index.js +2 -1
- package/out/env/index.js.map +1 -1
- package/out/env/paths.d.ts +15 -8
- package/out/env/paths.d.ts.map +1 -1
- package/out/env/paths.js +19 -29
- package/out/env/paths.js.map +1 -1
- package/out/env/schema.d.ts +12 -1
- package/out/env/schema.d.ts.map +1 -1
- package/out/env/schema.js +33 -3
- package/out/env/schema.js.map +1 -1
- package/out/fs/utils/formatters.d.ts +57 -0
- package/out/fs/utils/formatters.d.ts.map +1 -0
- package/out/fs/utils/formatters.js +79 -0
- package/out/fs/utils/formatters.js.map +1 -0
- package/out/fs/utils/index.d.ts +7 -0
- package/out/fs/utils/index.d.ts.map +1 -0
- package/out/fs/utils/index.js +7 -0
- package/out/fs/utils/index.js.map +1 -0
- package/out/fs/zip.d.ts +116 -0
- package/out/fs/zip.d.ts.map +1 -0
- package/out/fs/zip.js +216 -0
- package/out/fs/zip.js.map +1 -0
- package/out/layers/manifest.d.ts +32 -7
- package/out/layers/manifest.d.ts.map +1 -1
- package/out/layers/manifest.js +31 -6
- package/out/layers/manifest.js.map +1 -1
- package/out/layers/schema.d.ts +48 -2
- package/out/layers/schema.d.ts.map +1 -1
- package/out/layers/schema.js +32 -0
- package/out/layers/schema.js.map +1 -1
- package/out/locale/locale.d.ts +1 -1
- package/out/locale/locale.d.ts.map +1 -1
- package/out/locale/registry.js +1 -1
- package/out/locale/registry.js.map +1 -1
- package/out/objects.d.ts +12 -6
- package/out/objects.d.ts.map +1 -1
- package/out/objects.js +4 -1
- package/out/objects.js.map +1 -1
- package/out/pipeline/index.d.ts +3 -7
- package/out/pipeline/index.d.ts.map +1 -1
- package/out/pipeline/index.js +2 -4
- package/out/pipeline/index.js.map +1 -1
- package/out/pipeline/runtime-pipeline.d.ts +51 -9
- package/out/pipeline/runtime-pipeline.d.ts.map +1 -1
- package/out/pipeline/runtime-pipeline.js +46 -133
- package/out/pipeline/runtime-pipeline.js.map +1 -1
- package/out/pipeline/span-proposer.js +1 -1
- package/out/pipeline/span-proposer.js.map +1 -1
- package/out/pipeline/types.d.ts +137 -16
- package/out/pipeline/types.d.ts.map +1 -1
- package/out/pipeline/types.js +30 -0
- package/out/pipeline/types.js.map +1 -1
- package/out/policy/defaults.d.ts +1 -1
- package/out/policy/defaults.d.ts.map +1 -1
- package/out/policy/defaults.js +1 -1
- package/out/policy/defaults.js.map +1 -1
- package/out/policy/policy.d.ts +1 -1
- package/out/policy/policy.d.ts.map +1 -1
- package/out/policy/registry.d.ts +1 -1
- package/out/policy/registry.d.ts.map +1 -1
- package/out/resolver/coverage-facts.d.ts +89 -0
- package/out/resolver/coverage-facts.d.ts.map +1 -0
- package/out/resolver/coverage-facts.js +22 -0
- package/out/resolver/coverage-facts.js.map +1 -0
- package/out/resolver/index.d.ts +4 -1
- package/out/resolver/index.d.ts.map +1 -1
- package/out/resolver/index.js +2 -0
- package/out/resolver/index.js.map +1 -1
- package/out/resolver/lookup-types.d.ts +178 -0
- package/out/resolver/lookup-types.d.ts.map +1 -0
- package/out/resolver/lookup-types.js +11 -0
- package/out/resolver/lookup-types.js.map +1 -0
- package/out/resolver/placetype-map.d.ts +71 -0
- package/out/resolver/placetype-map.d.ts.map +1 -0
- package/out/resolver/placetype-map.js +98 -0
- package/out/resolver/placetype-map.js.map +1 -0
- package/out/resolver/postcode-format.d.ts +38 -0
- package/out/resolver/postcode-format.d.ts.map +1 -0
- package/out/resolver/postcode-format.js +83 -0
- package/out/resolver/postcode-format.js.map +1 -0
- package/out/resolver/referential.d.ts +73 -0
- package/out/resolver/referential.d.ts.map +1 -0
- package/out/resolver/referential.js +71 -0
- package/out/resolver/referential.js.map +1 -0
- package/out/resolver/types.d.ts +401 -264
- package/out/resolver/types.d.ts.map +1 -1
- package/out/resolver/types.js +4 -97
- package/out/resolver/types.js.map +1 -1
- package/out/resources/git.d.ts +8 -1
- package/out/resources/git.d.ts.map +1 -1
- package/out/resources/git.js +4 -3
- package/out/resources/git.js.map +1 -1
- package/out/resources/languages/types.gen.d.ts +1 -1
- package/out/resources/languages/types.gen.d.ts.map +1 -1
- package/out/resources/languages/types.gen.js +40 -0
- package/out/resources/languages/types.gen.js.map +1 -1
- package/out/resources/libpostal.d.ts +2 -2
- package/out/resources/libpostal.d.ts.map +1 -1
- package/out/resources/libpostal.js +2 -2
- package/out/resources/libpostal.js.map +1 -1
- package/out/resources/whosonfirst/DataSourceCache.d.ts.map +1 -1
- package/out/resources/whosonfirst/DataSourceCache.js.map +1 -1
- package/out/resources/whosonfirst/PlacetypeDataSource.d.ts +2 -2
- package/out/resources/whosonfirst/PlacetypeDataSource.d.ts.map +1 -1
- package/out/resources/whosonfirst/PlacetypeDataSource.js +28 -3
- package/out/resources/whosonfirst/PlacetypeDataSource.js.map +1 -1
- package/out/resources/whosonfirst/loader.d.ts +2 -2
- package/out/resources/whosonfirst/loader.d.ts.map +1 -1
- package/out/resources/whosonfirst/loader.js.map +1 -1
- package/out/resources/whosonfirst/placetypes/Placetype.d.ts.map +1 -1
- package/out/resources/whosonfirst/placetypes/Placetype.js +1 -1
- package/out/resources/whosonfirst/placetypes/Placetype.js.map +1 -1
- package/out/resources/whosonfirst/placetypes/admin.d.ts +9 -1
- package/out/resources/whosonfirst/placetypes/admin.d.ts.map +1 -1
- package/out/resources/whosonfirst/placetypes/admin.js +1 -1
- package/out/resources/whosonfirst/placetypes/admin.js.map +1 -1
- package/out/resources/whosonfirst/placetypes/definition.d.ts.map +1 -1
- package/out/resources/whosonfirst/placetypes/definition.js +1 -1
- package/out/resources/whosonfirst/placetypes/definition.js.map +1 -1
- package/out/resources/whosonfirst/placetypes/index.d.ts +1 -0
- package/out/resources/whosonfirst/placetypes/index.d.ts.map +1 -1
- package/out/resources/whosonfirst/placetypes/index.js +1 -0
- package/out/resources/whosonfirst/placetypes/index.js.map +1 -1
- package/out/resources/whosonfirst/placetypes/specificity.d.ts +65 -0
- package/out/resources/whosonfirst/placetypes/specificity.d.ts.map +1 -0
- package/out/resources/whosonfirst/placetypes/specificity.js +101 -0
- package/out/resources/whosonfirst/placetypes/specificity.js.map +1 -0
- package/out/resources/whosonfirst/sharded-repo.d.ts +28 -0
- package/out/resources/whosonfirst/sharded-repo.d.ts.map +1 -1
- package/out/resources/whosonfirst/sharded-repo.js +46 -2
- package/out/resources/whosonfirst/sharded-repo.js.map +1 -1
- package/out/scripting/arguments.d.ts +27 -0
- package/out/scripting/arguments.d.ts.map +1 -0
- package/out/scripting/arguments.js +32 -0
- package/out/scripting/arguments.js.map +1 -0
- package/out/scripting/command.d.ts +28 -0
- package/out/scripting/command.d.ts.map +1 -0
- package/out/scripting/command.js +47 -0
- package/out/scripting/command.js.map +1 -0
- package/out/scripting/index.js +3 -3
- package/out/scripting/index.js.map +1 -1
- package/out/scripting/utils/index.d.ts +1 -12
- package/out/scripting/utils/index.d.ts.map +1 -1
- package/out/scripting/utils/index.js +4 -21
- package/out/scripting/utils/index.js.map +1 -1
- package/out/tools/download-libpostal-resources.d.ts.map +1 -1
- package/out/tools/download-libpostal-resources.js +4 -7
- package/out/tools/download-libpostal-resources.js.map +1 -1
- package/out/tools/download-ssl-address.d.ts +3 -3
- package/out/tools/download-ssl-address.d.ts.map +1 -1
- package/out/tools/download-ssl-address.js +26 -13
- package/out/tools/download-ssl-address.js.map +1 -1
- package/out/tools/generate-language-types.d.ts +16 -1
- package/out/tools/generate-language-types.d.ts.map +1 -1
- package/out/tools/generate-language-types.js +38 -5
- package/out/tools/generate-language-types.js.map +1 -1
- package/out/tools/index.d.ts +1 -2
- package/out/tools/index.d.ts.map +1 -1
- package/out/tools/index.js +1 -2
- package/out/tools/index.js.map +1 -1
- package/out/utils/data-root.d.ts +27 -7
- package/out/utils/data-root.d.ts.map +1 -1
- package/out/utils/data-root.js +36 -13
- package/out/utils/data-root.js.map +1 -1
- package/out/utils/hash.d.ts +2 -3
- package/out/utils/hash.d.ts.map +1 -1
- package/out/utils/hash.js +3 -3
- package/out/utils/hash.js.map +1 -1
- package/out/utils/index.d.ts +1 -0
- package/out/utils/index.d.ts.map +1 -1
- package/out/utils/index.js +1 -0
- package/out/utils/index.js.map +1 -1
- package/out/utils/jsonl.js +1 -1
- package/out/utils/jsonl.js.map +1 -1
- package/out/utils/repo.d.ts +8 -0
- package/out/utils/repo.d.ts.map +1 -1
- package/out/utils/repo.js +10 -1
- package/out/utils/repo.js.map +1 -1
- package/out/utils/sealed-db.d.ts +11 -0
- package/out/utils/sealed-db.d.ts.map +1 -1
- package/out/utils/sealed-db.js +28 -1
- package/out/utils/sealed-db.js.map +1 -1
- package/out/utils/sqlite-rows.d.ts +34 -0
- package/out/utils/sqlite-rows.d.ts.map +1 -0
- package/out/utils/sqlite-rows.js +37 -0
- package/out/utils/sqlite-rows.js.map +1 -0
- package/out/utils/stats.d.ts +1 -6
- package/out/utils/stats.d.ts.map +1 -1
- package/out/utils/stats.js +1 -6
- package/out/utils/stats.js.map +1 -1
- package/package.json +488 -8
- package/pipeline/index.ts +14 -15
- package/pipeline/runtime-pipeline.ts +48 -184
- package/pipeline/span-proposer.ts +1 -1
- package/pipeline/types.ts +143 -16
- package/policy/defaults.ts +1 -1
- package/policy/policy.ts +1 -1
- package/policy/registry.ts +1 -1
- package/resolver/coverage-facts.ts +102 -0
- package/resolver/index.ts +18 -0
- package/resolver/lookup-types.ts +174 -0
- package/resolver/placetype-map.ts +122 -0
- package/resolver/postcode-format.ts +89 -0
- package/resolver/referential.ts +84 -0
- package/resolver/types.ts +423 -315
- package/resources/git.ts +18 -4
- package/resources/languages/types.gen.ts +60 -0
- package/resources/libpostal.ts +4 -3
- package/resources/whosonfirst/DataSourceCache.ts +2 -1
- package/resources/whosonfirst/PlacetypeDataSource.ts +36 -11
- package/resources/whosonfirst/loader.ts +3 -2
- package/resources/whosonfirst/placetypes/Placetype.ts +2 -1
- package/resources/whosonfirst/placetypes/admin.ts +11 -2
- package/resources/whosonfirst/placetypes/definition.ts +4 -3
- package/resources/whosonfirst/placetypes/index.ts +1 -0
- package/resources/whosonfirst/placetypes/specificity.ts +114 -0
- package/resources/whosonfirst/sharded-repo.ts +55 -2
- package/scripting/arguments.ts +38 -0
- package/scripting/command.ts +55 -0
- package/scripting/index.ts +3 -3
- package/scripting/utils/index.ts +5 -23
- package/tools/download-libpostal-resources.ts +4 -7
- package/tools/download-ssl-address.ts +28 -12
- package/tools/generate-language-types.ts +39 -5
- package/tools/index.ts +1 -2
- package/utils/data-root.ts +40 -14
- package/utils/hash.ts +5 -4
- package/utils/index.ts +1 -0
- package/utils/jsonl.ts +1 -1
- package/utils/repo.ts +12 -1
- package/utils/sealed-db.ts +30 -1
- package/utils/sqlite-rows.ts +40 -0
- package/utils/stats.ts +1 -6
- package/data/libpostal/dictionaries/all/chains.txt +0 -504
- package/kysley/adapter.ts +0 -29
- package/out/kysley/adapter.d.ts +0 -13
- package/out/kysley/adapter.d.ts.map +0 -1
- package/out/kysley/adapter.js +0 -25
- package/out/kysley/adapter.js.map +0 -1
- package/out/pipeline/reconcile-lookups.d.ts +0 -39
- package/out/pipeline/reconcile-lookups.d.ts.map +0 -1
- package/out/pipeline/reconcile-lookups.js +0 -88
- package/out/pipeline/reconcile-lookups.js.map +0 -1
- package/out/pipeline/reconcile.d.ts +0 -153
- package/out/pipeline/reconcile.d.ts.map +0 -1
- package/out/pipeline/reconcile.js +0 -388
- package/out/pipeline/reconcile.js.map +0 -1
- package/out/pipeline/span-logit-aggregation.d.ts +0 -58
- package/out/pipeline/span-logit-aggregation.d.ts.map +0 -1
- package/out/pipeline/span-logit-aggregation.js +0 -117
- package/out/pipeline/span-logit-aggregation.js.map +0 -1
- package/pipeline/reconcile-lookups.ts +0 -111
- package/pipeline/reconcile.ts +0 -583
- package/pipeline/span-logit-aggregation.ts +0 -156
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @copyright Sister Software
|
|
3
|
-
* @license AGPL-3.0
|
|
4
|
-
* @author Teffen Ellis, et al.
|
|
5
|
-
*
|
|
6
|
-
* Per-span logit aggregation — Option C from the DeepSeek synthesis review.
|
|
7
|
-
*
|
|
8
|
-
* Takes the per-token logits already emitted by the ONNX model (currently discarded after argmax in
|
|
9
|
-
* `classifier.ts`) and aggregates them over phrase-grouper spans to produce per-span top-K tag
|
|
10
|
-
* candidates. These feed directly into `reconcileSpans` as the `classifierTopK` input.
|
|
11
|
-
*
|
|
12
|
-
* Why this instead of a sequence-level beam decoder: the reconciler takes `(span, tag, score)`
|
|
13
|
-
* triples — per-span confidence, not BIO-sequence-level confidence. The phrase grouper has
|
|
14
|
-
* already done boundary discovery. This module answers "given these boundaries, what tags does
|
|
15
|
-
* the classifier think each span is?" — which is the right abstraction for joint decoding.
|
|
16
|
-
*
|
|
17
|
-
* Code path matches the eventual production runtime: when a top-k-trained classifier exists, the TS
|
|
18
|
-
* runtime just swaps "per-token softmax aggregation" for "classifier's native top-k API." Same
|
|
19
|
-
* downstream contract.
|
|
20
|
-
*/
|
|
21
|
-
import type { ClassifierCandidate } from "./reconcile.ts";
|
|
22
|
-
/**
|
|
23
|
-
* A token piece with character-level offsets into the original text.
|
|
24
|
-
*/
|
|
25
|
-
export interface TokenPiece {
|
|
26
|
-
start: number;
|
|
27
|
-
end: number;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* A span proposal from the phrase grouper, in character offsets.
|
|
31
|
-
*/
|
|
32
|
-
export interface SpanBounds {
|
|
33
|
-
start: number;
|
|
34
|
-
end: number;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Given per-token logits and phrase-grouper spans, produce per-span top-K tag candidates.
|
|
38
|
-
*
|
|
39
|
-
* For each span, finds the tokens whose character ranges overlap the span, sums their softmax probabilities per-tag,
|
|
40
|
-
* normalizes, and emits the top K tags with their aggregated scores.
|
|
41
|
-
*
|
|
42
|
-
* BIO prefix stripping: the model emits BIO labels (`B-locality`, `I-locality`, etc.) but the reconciler works with
|
|
43
|
-
* component tags (`locality`). This function strips the `B-`/`I-` prefix and merges probabilities: `score(locality) =
|
|
44
|
-
* sum(score(B-locality) + score(I-locality))` across the span's tokens.
|
|
45
|
-
*
|
|
46
|
-
* @param logits Per-token logits from ONNX inference, shape `[seqLen][numLabels]`.
|
|
47
|
-
* @param pieces Token pieces with character-level offsets (from the tokenizer's `encode`).
|
|
48
|
-
* @param spans Phrase-grouper span proposals in character offsets.
|
|
49
|
-
* @param opts Options bag.
|
|
50
|
-
* @param opts.topK Number of top-scoring tags to return per span (default 3).
|
|
51
|
-
* @param opts.labels The BIO label vocabulary the model emits, e.g. `["O", "B-locality", ...]`.
|
|
52
|
-
*/
|
|
53
|
-
export declare function aggregateSpanLogits(logits: number[][], pieces: readonly TokenPiece[], spans: readonly SpanBounds[], opts: {
|
|
54
|
-
topK?: number;
|
|
55
|
-
labels: readonly string[];
|
|
56
|
-
text?: string;
|
|
57
|
-
}): ClassifierCandidate[];
|
|
58
|
-
//# sourceMappingURL=span-logit-aggregation.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"span-logit-aggregation.d.ts","sourceRoot":"","sources":["../../pipeline/span-logit-aggregation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAGH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;AAEzD;;GAEG;AACH,MAAM,WAAW,UAAU;IAC1B,KAAK,EAAE,MAAM,CAAA;IACb,GAAG,EAAE,MAAM,CAAA;CACX;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IAC1B,KAAK,EAAE,MAAM,CAAA;IACb,GAAG,EAAE,MAAM,CAAA;CACX;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,mBAAmB,CAClC,MAAM,EAAE,MAAM,EAAE,EAAE,EAClB,MAAM,EAAE,SAAS,UAAU,EAAE,EAC7B,KAAK,EAAE,SAAS,UAAU,EAAE,EAC5B,IAAI,EAAE;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,GAC/D,mBAAmB,EAAE,CAgEvB"}
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @copyright Sister Software
|
|
3
|
-
* @license AGPL-3.0
|
|
4
|
-
* @author Teffen Ellis, et al.
|
|
5
|
-
*
|
|
6
|
-
* Per-span logit aggregation — Option C from the DeepSeek synthesis review.
|
|
7
|
-
*
|
|
8
|
-
* Takes the per-token logits already emitted by the ONNX model (currently discarded after argmax in
|
|
9
|
-
* `classifier.ts`) and aggregates them over phrase-grouper spans to produce per-span top-K tag
|
|
10
|
-
* candidates. These feed directly into `reconcileSpans` as the `classifierTopK` input.
|
|
11
|
-
*
|
|
12
|
-
* Why this instead of a sequence-level beam decoder: the reconciler takes `(span, tag, score)`
|
|
13
|
-
* triples — per-span confidence, not BIO-sequence-level confidence. The phrase grouper has
|
|
14
|
-
* already done boundary discovery. This module answers "given these boundaries, what tags does
|
|
15
|
-
* the classifier think each span is?" — which is the right abstraction for joint decoding.
|
|
16
|
-
*
|
|
17
|
-
* Code path matches the eventual production runtime: when a top-k-trained classifier exists, the TS
|
|
18
|
-
* runtime just swaps "per-token softmax aggregation" for "classifier's native top-k API." Same
|
|
19
|
-
* downstream contract.
|
|
20
|
-
*/
|
|
21
|
-
/**
|
|
22
|
-
* Given per-token logits and phrase-grouper spans, produce per-span top-K tag candidates.
|
|
23
|
-
*
|
|
24
|
-
* For each span, finds the tokens whose character ranges overlap the span, sums their softmax probabilities per-tag,
|
|
25
|
-
* normalizes, and emits the top K tags with their aggregated scores.
|
|
26
|
-
*
|
|
27
|
-
* BIO prefix stripping: the model emits BIO labels (`B-locality`, `I-locality`, etc.) but the reconciler works with
|
|
28
|
-
* component tags (`locality`). This function strips the `B-`/`I-` prefix and merges probabilities: `score(locality) =
|
|
29
|
-
* sum(score(B-locality) + score(I-locality))` across the span's tokens.
|
|
30
|
-
*
|
|
31
|
-
* @param logits Per-token logits from ONNX inference, shape `[seqLen][numLabels]`.
|
|
32
|
-
* @param pieces Token pieces with character-level offsets (from the tokenizer's `encode`).
|
|
33
|
-
* @param spans Phrase-grouper span proposals in character offsets.
|
|
34
|
-
* @param opts Options bag.
|
|
35
|
-
* @param opts.topK Number of top-scoring tags to return per span (default 3).
|
|
36
|
-
* @param opts.labels The BIO label vocabulary the model emits, e.g. `["O", "B-locality", ...]`.
|
|
37
|
-
*/
|
|
38
|
-
export function aggregateSpanLogits(logits, pieces, spans, opts) {
|
|
39
|
-
const topK = opts.topK ?? 3;
|
|
40
|
-
const labels = opts.labels;
|
|
41
|
-
const text = opts.text;
|
|
42
|
-
const candidates = [];
|
|
43
|
-
for (const span of spans) {
|
|
44
|
-
// Inherently-numeric components can't live on a span with no digit. An OOD model facing the
|
|
45
|
-
// "<postcode> <City>" order routinely mistags the trailing city as a postcode (Toulouse →
|
|
46
|
-
// postcode:0.77); since postcodes and house numbers contain a digit in every locale we handle,
|
|
47
|
-
// drop those candidates for a digit-less span so the reconciler picks the real component (#425).
|
|
48
|
-
const spanHasNoDigit = text !== undefined && !/\d/.test(text.slice(span.start, span.end));
|
|
49
|
-
// Find tokens overlapping this span (character-level).
|
|
50
|
-
const overlapping = [];
|
|
51
|
-
for (let t = 0; t < pieces.length; t++) {
|
|
52
|
-
const p = pieces[t];
|
|
53
|
-
if (p.end <= span.start)
|
|
54
|
-
continue;
|
|
55
|
-
if (p.start >= span.end)
|
|
56
|
-
break;
|
|
57
|
-
overlapping.push(t);
|
|
58
|
-
}
|
|
59
|
-
if (!overlapping.length)
|
|
60
|
-
continue;
|
|
61
|
-
// Aggregate softmax probabilities per component tag (strip BIO prefix).
|
|
62
|
-
const tagScores = new Map();
|
|
63
|
-
for (const t of overlapping) {
|
|
64
|
-
const probs = softmax(logits[t]);
|
|
65
|
-
for (let l = 0; l < labels.length; l++) {
|
|
66
|
-
const bioLabel = labels[l];
|
|
67
|
-
const tag = stripBIOPrefix(bioLabel);
|
|
68
|
-
if (tag === "O")
|
|
69
|
-
continue;
|
|
70
|
-
if (spanHasNoDigit && (tag === "postcode" || tag === "house_number"))
|
|
71
|
-
continue;
|
|
72
|
-
const prev = tagScores.get(tag) ?? 0;
|
|
73
|
-
tagScores.set(tag, prev + probs[l]);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
// Normalize by number of overlapping tokens so longer spans don't auto-win.
|
|
77
|
-
const norm = overlapping.length;
|
|
78
|
-
const sorted = [...tagScores.entries()]
|
|
79
|
-
.map(([tag, score]) => ({ tag, score: score / norm }))
|
|
80
|
-
// oxlint-disable-next-line unicorn/no-array-sort -- sorts a freshly-built array; toSorted would double-allocate on a hot path
|
|
81
|
-
.sort((a, b) => b.score - a.score)
|
|
82
|
-
.slice(0, topK);
|
|
83
|
-
for (const { tag, score } of sorted) {
|
|
84
|
-
candidates.push({
|
|
85
|
-
span: { start: span.start, end: span.end },
|
|
86
|
-
tag: tag,
|
|
87
|
-
score,
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
return candidates;
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Strip `B-` or `I-` prefix from a BIO label, returning the component tag. `O` returns `"O"`.
|
|
95
|
-
*/
|
|
96
|
-
function stripBIOPrefix(label) {
|
|
97
|
-
if (label === "O")
|
|
98
|
-
return "O";
|
|
99
|
-
const dash = label.indexOf("-");
|
|
100
|
-
if (dash === -1)
|
|
101
|
-
return label;
|
|
102
|
-
return label.slice(dash + 1);
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Numerically stable softmax over a row of logits.
|
|
106
|
-
*/
|
|
107
|
-
function softmax(row) {
|
|
108
|
-
let max = row[0];
|
|
109
|
-
for (let i = 1; i < row.length; i++)
|
|
110
|
-
if (row[i] > max) {
|
|
111
|
-
max = row[i];
|
|
112
|
-
}
|
|
113
|
-
const exps = row.map((v) => Math.exp(v - max));
|
|
114
|
-
const sum = exps.reduce((a, b) => a + b, 0);
|
|
115
|
-
return exps.map((e) => e / sum);
|
|
116
|
-
}
|
|
117
|
-
//# sourceMappingURL=span-logit-aggregation.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"span-logit-aggregation.js","sourceRoot":"","sources":["../../pipeline/span-logit-aggregation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAqBH;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,mBAAmB,CAClC,MAAkB,EAClB,MAA6B,EAC7B,KAA4B,EAC5B,IAAiE;IAEjE,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,IAAI,CAAC,CAAA;IAC3B,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAA;IAC1B,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAA;IAEtB,MAAM,UAAU,GAA0B,EAAE,CAAA;IAE5C,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QAC1B,4FAA4F;QAC5F,0FAA0F;QAC1F,+FAA+F;QAC/F,iGAAiG;QACjG,MAAM,cAAc,GAAG,IAAI,KAAK,SAAS,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAA;QACzF,uDAAuD;QACvD,MAAM,WAAW,GAAa,EAAE,CAAA;QAEhC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACxC,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC,CAAE,CAAA;YAEpB,IAAI,CAAC,CAAC,GAAG,IAAI,IAAI,CAAC,KAAK;gBAAE,SAAQ;YAEjC,IAAI,CAAC,CAAC,KAAK,IAAI,IAAI,CAAC,GAAG;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C,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAA;IAE3C,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,GAAG,CAAC,CAAA;AAChC,CAAC"}
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @copyright Sister Software
|
|
3
|
-
* @license AGPL-3.0
|
|
4
|
-
* @author Teffen Ellis, et al.
|
|
5
|
-
*
|
|
6
|
-
* Pre-fetch adapters that wire a `ResolverBackend` into the reconciler's concordance axes (#478
|
|
7
|
-
* step 2, re-scoped): `reconcileSpans` already implements resolver-candidate and parent-chain
|
|
8
|
-
* scoring but the runtime pipeline never passed the lookups — the axes were dormant, exercised
|
|
9
|
-
* only by Map-backed test fixtures.
|
|
10
|
-
*
|
|
11
|
-
* The reconciler's beam search is SYNCHRONOUS; the backend is async. So this module does one
|
|
12
|
-
* bounded async pre-fetch pass — `findPlace` per (phrase-span × top-k tag) pair, `ancestors` per
|
|
13
|
-
* fetched place — and returns Map-backed lookups with the contract the reconciler expects. Query
|
|
14
|
-
* count is capped (`maxLookups`, default 12) the same way `resolveTree` caps its walk; pairs are
|
|
15
|
-
* visited in classifier-score order so the budget goes to the likeliest spans.
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
import type { ResolvedPlace, ResolverBackend } from "../resolver/types.ts"
|
|
19
|
-
import type { ClassifierCandidate, ParentChainLookup, ResolverCandidatesLookup } from "./reconcile.ts"
|
|
20
|
-
|
|
21
|
-
const RESOLVABLE_TAGS = new Set(["country", "region", "locality", "dependent_locality", "county", "subregion"])
|
|
22
|
-
|
|
23
|
-
export interface ReconcileLookups {
|
|
24
|
-
resolverCandidates: ResolverCandidatesLookup
|
|
25
|
-
parentChain: ParentChainLookup
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Build the reconciler's concordance lookups from one bounded pre-fetch pass over the backend.
|
|
30
|
-
*
|
|
31
|
-
* @param backend The gazetteer backend (Stage 6's `WOFSqlitePlaceLookup.asResolverBackend()` in production; any
|
|
32
|
-
* structural match in tests).
|
|
33
|
-
* @param raw The normalized input text — span bounds index into this.
|
|
34
|
-
* @param classifierTopK The aggregated per-span tag candidates (score-descending preferred; the budget follows this
|
|
35
|
-
* order).
|
|
36
|
-
* @param opts.maxLookups Hard cap on `findPlace` calls (default 12).
|
|
37
|
-
* @param opts.candidatesPerPair Max places retained per (span, tag) pair (default 3).
|
|
38
|
-
*/
|
|
39
|
-
export async function prefetchReconcileLookups(
|
|
40
|
-
backend: ResolverBackend,
|
|
41
|
-
raw: string,
|
|
42
|
-
classifierTopK: ReadonlyArray<ClassifierCandidate>,
|
|
43
|
-
opts?: { maxLookups?: number; candidatesPerPair?: number; defaultCountry?: string }
|
|
44
|
-
): Promise<ReconcileLookups> {
|
|
45
|
-
const maxLookups = opts?.maxLookups ?? 12
|
|
46
|
-
const perPair = opts?.candidatesPerPair ?? 3
|
|
47
|
-
|
|
48
|
-
const candidateTable = new Map<string, ResolvedPlace[]>()
|
|
49
|
-
const chainTable = new Map<number | string, ResolvedPlace[]>()
|
|
50
|
-
const pairKey = (span: { start: number; end: number }, tag: string) => `${span.start}:${span.end}:${tag}`
|
|
51
|
-
|
|
52
|
-
let budget = maxLookups
|
|
53
|
-
|
|
54
|
-
for (const candidate of classifierTopK) {
|
|
55
|
-
if (budget <= 0) break
|
|
56
|
-
|
|
57
|
-
if (!RESOLVABLE_TAGS.has(candidate.tag)) continue
|
|
58
|
-
const key = pairKey(candidate.span, candidate.tag)
|
|
59
|
-
|
|
60
|
-
if (candidateTable.has(key)) continue
|
|
61
|
-
const text = raw.slice(candidate.span.start, candidate.span.end).trim()
|
|
62
|
-
|
|
63
|
-
if (!text) continue
|
|
64
|
-
|
|
65
|
-
budget--
|
|
66
|
-
let places: ResolvedPlace[] = []
|
|
67
|
-
|
|
68
|
-
try {
|
|
69
|
-
places = await backend.findPlace({
|
|
70
|
-
text,
|
|
71
|
-
placetype: candidate.tag,
|
|
72
|
-
...(opts?.defaultCountry ? { country: opts.defaultCountry } : {}),
|
|
73
|
-
limit: perPair,
|
|
74
|
-
})
|
|
75
|
-
} catch {
|
|
76
|
-
// A backend failure degrades to "no concordance evidence for this pair" — the
|
|
77
|
-
// reconciler scores without it, identical to today's behavior.
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
candidateTable.set(key, places.slice(0, perPair))
|
|
81
|
-
|
|
82
|
-
// Ancestors are synchronous + memoized backend-side; chain them now so parentsOf is a
|
|
83
|
-
// pure Map read during the beam search.
|
|
84
|
-
if (backend.ancestors) {
|
|
85
|
-
for (const place of places) {
|
|
86
|
-
if (chainTable.has(place.id)) continue
|
|
87
|
-
const chain = backend.ancestors(place.id) ?? []
|
|
88
|
-
|
|
89
|
-
// The reconciler's concordance check is MEMBERSHIP-ONLY (by id) — Ancestor carries no
|
|
90
|
-
// coordinates, and none are needed; zeroes satisfy the ResolvedPlace shape.
|
|
91
|
-
chainTable.set(
|
|
92
|
-
place.id,
|
|
93
|
-
chain.map((a) => ({ id: a.id, name: a.name, placetype: a.placetype, lat: 0, lon: 0 }) as ResolvedPlace)
|
|
94
|
-
)
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
return {
|
|
100
|
-
resolverCandidates: {
|
|
101
|
-
candidatesFor(span, tag) {
|
|
102
|
-
return candidateTable.get(pairKey(span, tag)) ?? []
|
|
103
|
-
},
|
|
104
|
-
},
|
|
105
|
-
parentChain: {
|
|
106
|
-
parentsOf(place) {
|
|
107
|
-
return chainTable.get(place.id) ?? []
|
|
108
|
-
},
|
|
109
|
-
},
|
|
110
|
-
}
|
|
111
|
-
}
|