@mailwoman/core 8.1.0 → 8.3.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/api/APIClient.ts +3 -4
- package/api/responses.ts +6 -3
- package/coarse-placer/coarse-placer.ts +26 -11
- package/coarse-placer/featurize.ts +25 -16
- package/coarse-placer/tools/build-dataset.ts +42 -18
- package/coarse-placer/tools/build-outlier-exposure.ts +51 -18
- package/coarse-placer/tools/build-outlier-latin.ts +48 -22
- package/coarse-placer/tools/build-outlier-oa.ts +52 -20
- package/coarse-placer/tools/eval-latin-offmap.ts +37 -12
- package/coarse-placer/tools/eval-openset.ts +104 -37
- package/coarse-placer/tools/eval-quant-compare.ts +41 -11
- package/coarse-placer/tools/eval.ts +51 -13
- package/coarse-placer/tools/fnv-hash.ts +5 -3
- package/coarse-placer/tools/probe-frontier.ts +63 -32
- package/coarse-placer/tools/quantize.ts +30 -8
- package/coarse-placer/tools/train.ts +63 -17
- package/collections.ts +2 -2
- package/decoder/build-tree.ts +16 -3
- package/decoder/calibration.ts +23 -7
- package/decoder/containment.ts +3 -1
- package/decoder/proposals-to-tree.ts +2 -0
- package/decoder/resolve-proposal-overlaps.ts +5 -1
- package/decoder/serialize-json.ts +8 -2
- package/decoder/serialize-tuples.ts +7 -2
- package/decoder/serialize-xml.ts +29 -11
- package/decoder/types.ts +34 -12
- package/decoder/unknown-spans.ts +14 -5
- package/decoder/validate-tree.ts +6 -1
- package/env/index.ts +1 -1
- package/env/load.ts +1 -1
- package/env/paths.ts +1 -1
- package/env/schema.ts +12 -4
- package/errors/schema.ts +1 -1
- package/fs/node.ts +9 -10
- package/identifiers.ts +3 -3
- package/kysley/adapter.ts +1 -1
- package/layers/manifest.ts +22 -8
- package/layers/schema.ts +59 -19
- package/locale/locale.ts +6 -2
- package/locale/profiles/en-us.ts +3 -0
- package/locale/profiles/fr-fr.ts +3 -0
- package/locale/profiles/ja-jp.ts +6 -0
- package/locale/registry.ts +3 -1
- package/logging/shared.ts +1 -0
- package/logging/utils.ts +1 -1
- package/objects.ts +7 -2
- package/out/api/APIClient.d.ts +1 -1
- package/out/api/APIClient.d.ts.map +1 -1
- package/out/api/APIClient.js +3 -2
- package/out/api/APIClient.js.map +1 -1
- package/out/api/responses.d.ts.map +1 -1
- package/out/api/responses.js +3 -3
- package/out/api/responses.js.map +1 -1
- package/out/coarse-placer/coarse-placer.d.ts +19 -9
- package/out/coarse-placer/coarse-placer.d.ts.map +1 -1
- package/out/coarse-placer/coarse-placer.js +6 -4
- package/out/coarse-placer/coarse-placer.js.map +1 -1
- package/out/coarse-placer/featurize.d.ts.map +1 -1
- package/out/coarse-placer/featurize.js +20 -16
- package/out/coarse-placer/featurize.js.map +1 -1
- package/out/coarse-placer/tools/build-dataset.d.ts +15 -5
- package/out/coarse-placer/tools/build-dataset.d.ts.map +1 -1
- package/out/coarse-placer/tools/build-dataset.js +19 -14
- package/out/coarse-placer/tools/build-dataset.js.map +1 -1
- package/out/coarse-placer/tools/build-outlier-exposure.d.ts +21 -7
- package/out/coarse-placer/tools/build-outlier-exposure.d.ts.map +1 -1
- package/out/coarse-placer/tools/build-outlier-exposure.js +24 -12
- package/out/coarse-placer/tools/build-outlier-exposure.js.map +1 -1
- package/out/coarse-placer/tools/build-outlier-latin.d.ts +18 -6
- package/out/coarse-placer/tools/build-outlier-latin.d.ts.map +1 -1
- package/out/coarse-placer/tools/build-outlier-latin.js +27 -17
- package/out/coarse-placer/tools/build-outlier-latin.js.map +1 -1
- package/out/coarse-placer/tools/build-outlier-oa.d.ts +18 -6
- package/out/coarse-placer/tools/build-outlier-oa.d.ts.map +1 -1
- package/out/coarse-placer/tools/build-outlier-oa.js +29 -15
- package/out/coarse-placer/tools/build-outlier-oa.js.map +1 -1
- package/out/coarse-placer/tools/eval-latin-offmap.d.ts +18 -6
- package/out/coarse-placer/tools/eval-latin-offmap.d.ts.map +1 -1
- package/out/coarse-placer/tools/eval-latin-offmap.js +13 -7
- package/out/coarse-placer/tools/eval-latin-offmap.js.map +1 -1
- package/out/coarse-placer/tools/eval-openset.d.ts +24 -8
- package/out/coarse-placer/tools/eval-openset.d.ts.map +1 -1
- package/out/coarse-placer/tools/eval-openset.js +52 -31
- package/out/coarse-placer/tools/eval-openset.js.map +1 -1
- package/out/coarse-placer/tools/eval-quant-compare.d.ts +30 -10
- package/out/coarse-placer/tools/eval-quant-compare.d.ts.map +1 -1
- package/out/coarse-placer/tools/eval-quant-compare.js +4 -2
- package/out/coarse-placer/tools/eval-quant-compare.js.map +1 -1
- package/out/coarse-placer/tools/eval.d.ts +24 -8
- package/out/coarse-placer/tools/eval.d.ts.map +1 -1
- package/out/coarse-placer/tools/eval.js +16 -6
- package/out/coarse-placer/tools/eval.js.map +1 -1
- package/out/coarse-placer/tools/fnv-hash.d.ts +3 -1
- package/out/coarse-placer/tools/fnv-hash.d.ts.map +1 -1
- package/out/coarse-placer/tools/fnv-hash.js +5 -3
- package/out/coarse-placer/tools/fnv-hash.js.map +1 -1
- package/out/coarse-placer/tools/probe-frontier.d.ts +18 -6
- package/out/coarse-placer/tools/probe-frontier.d.ts.map +1 -1
- package/out/coarse-placer/tools/probe-frontier.js +39 -23
- package/out/coarse-placer/tools/probe-frontier.js.map +1 -1
- package/out/coarse-placer/tools/quantize.d.ts +15 -5
- package/out/coarse-placer/tools/quantize.d.ts.map +1 -1
- package/out/coarse-placer/tools/quantize.js +11 -4
- package/out/coarse-placer/tools/quantize.js.map +1 -1
- package/out/coarse-placer/tools/train.d.ts +24 -8
- package/out/coarse-placer/tools/train.d.ts.map +1 -1
- package/out/coarse-placer/tools/train.js +24 -10
- package/out/coarse-placer/tools/train.js.map +1 -1
- package/out/collections.js +2 -2
- package/out/collections.js.map +1 -1
- package/out/decoder/build-tree.d.ts.map +1 -1
- package/out/decoder/build-tree.js +9 -3
- package/out/decoder/build-tree.js.map +1 -1
- package/out/decoder/calibration.d.ts +17 -3
- package/out/decoder/calibration.d.ts.map +1 -1
- package/out/decoder/calibration.js +12 -4
- package/out/decoder/calibration.js.map +1 -1
- package/out/decoder/containment.d.ts +3 -1
- package/out/decoder/containment.d.ts.map +1 -1
- package/out/decoder/containment.js +3 -1
- package/out/decoder/containment.js.map +1 -1
- package/out/decoder/proposals-to-tree.d.ts.map +1 -1
- package/out/decoder/proposals-to-tree.js.map +1 -1
- package/out/decoder/resolve-proposal-overlaps.d.ts.map +1 -1
- package/out/decoder/resolve-proposal-overlaps.js +5 -1
- package/out/decoder/resolve-proposal-overlaps.js.map +1 -1
- package/out/decoder/serialize-json.d.ts +6 -2
- package/out/decoder/serialize-json.d.ts.map +1 -1
- package/out/decoder/serialize-json.js.map +1 -1
- package/out/decoder/serialize-tuples.d.ts +6 -2
- package/out/decoder/serialize-tuples.d.ts.map +1 -1
- package/out/decoder/serialize-tuples.js.map +1 -1
- package/out/decoder/serialize-xml.d.ts +21 -7
- package/out/decoder/serialize-xml.d.ts.map +1 -1
- package/out/decoder/serialize-xml.js +7 -5
- package/out/decoder/serialize-xml.js.map +1 -1
- package/out/decoder/types.d.ts +34 -12
- package/out/decoder/types.d.ts.map +1 -1
- package/out/decoder/types.js +1 -1
- package/out/decoder/types.js.map +1 -1
- package/out/decoder/unknown-spans.d.ts +9 -3
- package/out/decoder/unknown-spans.d.ts.map +1 -1
- package/out/decoder/unknown-spans.js +4 -2
- package/out/decoder/unknown-spans.js.map +1 -1
- package/out/decoder/validate-tree.d.ts +3 -1
- package/out/decoder/validate-tree.d.ts.map +1 -1
- package/out/decoder/validate-tree.js +3 -1
- package/out/decoder/validate-tree.js.map +1 -1
- package/out/env/index.js +0 -1
- package/out/env/index.js.map +1 -1
- package/out/env/load.js +1 -1
- package/out/env/load.js.map +1 -1
- package/out/env/paths.js +1 -1
- package/out/env/paths.js.map +1 -1
- package/out/env/schema.d.ts.map +1 -1
- package/out/env/schema.js +12 -4
- package/out/env/schema.js.map +1 -1
- package/out/errors/schema.js +1 -1
- package/out/errors/schema.js.map +1 -1
- package/out/fs/node.d.ts +1 -2
- package/out/fs/node.d.ts.map +1 -1
- package/out/fs/node.js +7 -8
- package/out/fs/node.js.map +1 -1
- package/out/identifiers.js +3 -3
- package/out/identifiers.js.map +1 -1
- package/out/kysley/adapter.d.ts +1 -1
- package/out/kysley/adapter.d.ts.map +1 -1
- package/out/kysley/adapter.js +1 -1
- package/out/kysley/adapter.js.map +1 -1
- package/out/layers/manifest.d.ts +18 -6
- package/out/layers/manifest.d.ts.map +1 -1
- package/out/layers/manifest.js +8 -4
- package/out/layers/manifest.js.map +1 -1
- package/out/layers/schema.d.ts +57 -19
- package/out/layers/schema.d.ts.map +1 -1
- package/out/layers/schema.js +24 -8
- package/out/layers/schema.js.map +1 -1
- package/out/locale/locale.d.ts +6 -2
- package/out/locale/locale.d.ts.map +1 -1
- package/out/locale/profiles/en-us.d.ts +3 -0
- package/out/locale/profiles/en-us.d.ts.map +1 -1
- package/out/locale/profiles/en-us.js +3 -0
- package/out/locale/profiles/en-us.js.map +1 -1
- package/out/locale/profiles/fr-fr.d.ts +3 -0
- package/out/locale/profiles/fr-fr.d.ts.map +1 -1
- package/out/locale/profiles/fr-fr.js +3 -0
- package/out/locale/profiles/fr-fr.js.map +1 -1
- package/out/locale/profiles/ja-jp.d.ts +3 -0
- package/out/locale/profiles/ja-jp.d.ts.map +1 -1
- package/out/locale/profiles/ja-jp.js +6 -0
- package/out/locale/profiles/ja-jp.js.map +1 -1
- package/out/locale/registry.d.ts +3 -1
- package/out/locale/registry.d.ts.map +1 -1
- package/out/locale/registry.js +3 -1
- package/out/locale/registry.js.map +1 -1
- package/out/logging/shared.d.ts.map +1 -1
- package/out/logging/shared.js +1 -0
- package/out/logging/shared.js.map +1 -1
- package/out/logging/utils.js +1 -1
- package/out/logging/utils.js.map +1 -1
- package/out/objects.d.ts.map +1 -1
- package/out/objects.js +2 -2
- package/out/objects.js.map +1 -1
- package/out/pipeline/index.d.ts +2 -2
- package/out/pipeline/index.d.ts.map +1 -1
- package/out/pipeline/index.js +1 -1
- package/out/pipeline/index.js.map +1 -1
- package/out/pipeline/reconcile-lookups.d.ts.map +1 -1
- package/out/pipeline/reconcile-lookups.js.map +1 -1
- package/out/pipeline/reconcile.d.ts +30 -10
- package/out/pipeline/reconcile.d.ts.map +1 -1
- package/out/pipeline/reconcile.js +12 -9
- package/out/pipeline/reconcile.js.map +1 -1
- package/out/pipeline/runtime-pipeline.d.ts +18 -0
- package/out/pipeline/runtime-pipeline.d.ts.map +1 -1
- package/out/pipeline/runtime-pipeline.js +73 -46
- package/out/pipeline/runtime-pipeline.js.map +1 -1
- package/out/pipeline/span-logit-aggregation.d.ts.map +1 -1
- package/out/pipeline/span-logit-aggregation.js +5 -2
- package/out/pipeline/span-logit-aggregation.js.map +1 -1
- package/out/pipeline/span-proposer.d.ts +19 -9
- package/out/pipeline/span-proposer.d.ts.map +1 -1
- package/out/pipeline/span-proposer.js +42 -22
- package/out/pipeline/span-proposer.js.map +1 -1
- package/out/pipeline/types.d.ts +77 -19
- package/out/pipeline/types.d.ts.map +1 -1
- package/out/pipeline/types.js +16 -0
- package/out/pipeline/types.js.map +1 -1
- package/out/policy/proposal-collection.d.ts +1 -1
- package/out/policy/proposal-collection.d.ts.map +1 -1
- package/out/policy/proposal-collection.js +2 -3
- package/out/policy/proposal-collection.js.map +1 -1
- package/out/policy/registry.d.ts +9 -3
- package/out/policy/registry.d.ts.map +1 -1
- package/out/policy/registry.js +9 -3
- package/out/policy/registry.js.map +1 -1
- package/out/resolver/index.d.ts.map +1 -1
- package/out/resolver/types.d.ts +94 -30
- package/out/resolver/types.d.ts.map +1 -1
- package/out/resolver/types.js +7 -1
- package/out/resolver/types.js.map +1 -1
- package/out/resources/LocaleIndex.d.ts +1 -1
- package/out/resources/LocaleIndex.d.ts.map +1 -1
- package/out/resources/LocaleIndex.js +1 -2
- package/out/resources/LocaleIndex.js.map +1 -1
- package/out/resources/ResourceMapCache.d.ts.map +1 -1
- package/out/resources/ResourceMapCache.js +1 -1
- package/out/resources/ResourceMapCache.js.map +1 -1
- package/out/resources/collections.d.ts.map +1 -1
- package/out/resources/collections.js +3 -1
- package/out/resources/collections.js.map +1 -1
- package/out/resources/languages/index.d.ts +1 -1
- package/out/resources/languages/index.d.ts.map +1 -1
- package/out/resources/languages/index.js +1 -1
- package/out/resources/languages/index.js.map +1 -1
- package/out/resources/libpostal.d.ts +1 -1
- package/out/resources/libpostal.d.ts.map +1 -1
- package/out/resources/libpostal.js +7 -5
- package/out/resources/libpostal.js.map +1 -1
- package/out/resources/set.js +6 -6
- package/out/resources/set.js.map +1 -1
- package/out/resources/whosonfirst/DataSourceCache.d.ts +1 -4
- package/out/resources/whosonfirst/DataSourceCache.d.ts.map +1 -1
- package/out/resources/whosonfirst/DataSourceCache.js +1 -20
- package/out/resources/whosonfirst/DataSourceCache.js.map +1 -1
- package/out/resources/whosonfirst/PlacetypeDataSource.d.ts +1 -1
- package/out/resources/whosonfirst/PlacetypeDataSource.d.ts.map +1 -1
- package/out/resources/whosonfirst/PlacetypeDataSource.js +2 -2
- package/out/resources/whosonfirst/PlacetypeDataSource.js.map +1 -1
- package/out/resources/whosonfirst/backoff.d.ts +19 -0
- package/out/resources/whosonfirst/backoff.d.ts.map +1 -0
- package/out/resources/whosonfirst/backoff.js +35 -0
- package/out/resources/whosonfirst/backoff.js.map +1 -0
- package/out/resources/whosonfirst/loader.d.ts +1 -1
- package/out/resources/whosonfirst/loader.d.ts.map +1 -1
- package/out/resources/whosonfirst/loader.js +0 -1
- package/out/resources/whosonfirst/loader.js.map +1 -1
- package/out/resources/whosonfirst/placetypes/Placetype.d.ts +4 -1
- package/out/resources/whosonfirst/placetypes/Placetype.d.ts.map +1 -1
- package/out/resources/whosonfirst/placetypes/Placetype.js +8 -6
- package/out/resources/whosonfirst/placetypes/Placetype.js.map +1 -1
- package/out/resources/whosonfirst/placetypes/admin.d.ts +6 -4
- package/out/resources/whosonfirst/placetypes/admin.d.ts.map +1 -1
- package/out/resources/whosonfirst/placetypes/admin.js +8 -4
- package/out/resources/whosonfirst/placetypes/admin.js.map +1 -1
- package/out/resources/whosonfirst/placetypes/definition.d.ts +5 -6
- package/out/resources/whosonfirst/placetypes/definition.d.ts.map +1 -1
- package/out/resources/whosonfirst/placetypes/definition.js +3 -0
- package/out/resources/whosonfirst/placetypes/definition.js.map +1 -1
- package/out/resources/whosonfirst/placetypes/graph.d.ts +4 -2
- package/out/resources/whosonfirst/placetypes/graph.d.ts.map +1 -1
- package/out/resources/whosonfirst/placetypes/graph.js +0 -0
- package/out/resources/whosonfirst/placetypes/graph.js.map +1 -1
- package/out/resources/whosonfirst/placetypes/mermaid.d.ts +4 -2
- package/out/resources/whosonfirst/placetypes/mermaid.d.ts.map +1 -1
- package/out/resources/whosonfirst/placetypes/mermaid.js +0 -1
- package/out/resources/whosonfirst/placetypes/mermaid.js.map +1 -1
- package/out/resources/whosonfirst/placetypes/tree.d.ts +1 -1
- package/out/resources/whosonfirst/placetypes/tree.d.ts.map +1 -1
- package/out/resources/whosonfirst/placetypes/tree.js +0 -1
- package/out/resources/whosonfirst/placetypes/tree.js.map +1 -1
- package/out/routing/index.d.ts.map +1 -1
- package/out/routing/index.js +1 -1
- package/out/routing/index.js.map +1 -1
- package/out/scripting/utils/index.d.ts +3 -1
- package/out/scripting/utils/index.d.ts.map +1 -1
- package/out/scripting/utils/index.js +3 -1
- package/out/scripting/utils/index.js.map +1 -1
- package/out/tokenization/Span.js.map +1 -1
- package/out/tokenization/normalizer.js +11 -11
- package/out/tokenization/normalizer.js.map +1 -1
- package/out/tools/download-libpostal-resources.d.ts.map +1 -1
- package/out/tools/download-libpostal-resources.js.map +1 -1
- package/out/tools/download-ssl-address.d.ts +9 -3
- package/out/tools/download-ssl-address.d.ts.map +1 -1
- package/out/tools/download-ssl-address.js +8 -4
- package/out/tools/download-ssl-address.js.map +1 -1
- package/out/tools/generate-language-types.d.ts +12 -4
- package/out/tools/generate-language-types.d.ts.map +1 -1
- package/out/tools/generate-language-types.js +3 -1
- package/out/tools/generate-language-types.js.map +1 -1
- package/out/types/Classification.d.ts.map +1 -1
- package/out/types/Classification.js.map +1 -1
- package/out/types/classifier.d.ts +27 -9
- package/out/types/classifier.d.ts.map +1 -1
- package/out/types/component.d.ts +8 -4
- package/out/types/component.d.ts.map +1 -1
- package/out/types/component.js +3 -3
- package/out/types/component.js.map +1 -1
- package/out/utils/data-root.d.ts +3 -1
- package/out/utils/data-root.d.ts.map +1 -1
- package/out/utils/data-root.js +3 -1
- package/out/utils/data-root.js.map +1 -1
- package/out/utils/hash.d.ts +6 -2
- package/out/utils/hash.d.ts.map +1 -1
- package/out/utils/hash.js +6 -2
- package/out/utils/hash.js.map +1 -1
- package/out/utils/jsonl.d.ts +9 -3
- package/out/utils/jsonl.d.ts.map +1 -1
- package/out/utils/jsonl.js +9 -3
- package/out/utils/jsonl.js.map +1 -1
- package/out/utils/python-json.d.ts +6 -2
- package/out/utils/python-json.d.ts.map +1 -1
- package/out/utils/python-json.js +9 -3
- package/out/utils/python-json.js.map +1 -1
- package/out/utils/python-random.d.ts +15 -5
- package/out/utils/python-random.d.ts.map +1 -1
- package/out/utils/python-random.js +17 -7
- package/out/utils/python-random.js.map +1 -1
- package/out/utils/repo.d.ts +4 -0
- package/out/utils/repo.d.ts.map +1 -1
- package/out/utils/repo.js +4 -0
- package/out/utils/repo.js.map +1 -1
- package/out/utils/sealed-db.d.ts +6 -2
- package/out/utils/sealed-db.d.ts.map +1 -1
- package/out/utils/sealed-db.js +6 -2
- package/out/utils/sealed-db.js.map +1 -1
- package/out/utils/stats.d.ts +9 -3
- package/out/utils/stats.d.ts.map +1 -1
- package/out/utils/stats.js +11 -5
- package/out/utils/stats.js.map +1 -1
- package/package.json +2 -2
- package/pipeline/index.ts +5 -1
- package/pipeline/reconcile-lookups.ts +3 -0
- package/pipeline/reconcile.ts +65 -24
- package/pipeline/runtime-pipeline.ts +95 -46
- package/pipeline/span-logit-aggregation.ts +7 -2
- package/pipeline/span-proposer.ts +95 -34
- package/pipeline/types.ts +88 -19
- package/policy/proposal-collection.ts +4 -3
- package/policy/registry.ts +13 -3
- package/resolver/index.ts +1 -0
- package/resolver/types.ts +95 -30
- package/resources/LocaleIndex.ts +2 -2
- package/resources/ResourceMapCache.ts +3 -2
- package/resources/collections.ts +4 -1
- package/resources/languages/index.ts +2 -1
- package/resources/libpostal.ts +6 -3
- package/resources/set.ts +6 -6
- package/resources/whosonfirst/DataSourceCache.ts +2 -24
- package/resources/whosonfirst/PlacetypeDataSource.ts +2 -2
- package/resources/whosonfirst/backoff.ts +39 -0
- package/resources/whosonfirst/loader.ts +2 -1
- package/resources/whosonfirst/placetypes/Placetype.ts +9 -6
- package/resources/whosonfirst/placetypes/admin.ts +12 -7
- package/resources/whosonfirst/placetypes/definition.ts +6 -6
- package/resources/whosonfirst/placetypes/graph.ts +0 -0
- package/resources/whosonfirst/placetypes/mermaid.ts +5 -2
- package/resources/whosonfirst/placetypes/tree.ts +1 -1
- package/routing/index.ts +5 -1
- package/scripting/utils/index.ts +3 -1
- package/tokenization/Span.ts +1 -1
- package/tokenization/normalizer.ts +11 -11
- package/tools/download-libpostal-resources.ts +1 -0
- package/tools/download-ssl-address.ts +19 -7
- package/tools/generate-language-types.ts +12 -4
- package/types/Classification.ts +5 -0
- package/types/classifier.ts +27 -9
- package/types/component.ts +9 -5
- package/utils/data-root.ts +3 -1
- package/utils/hash.ts +6 -2
- package/utils/jsonl.ts +11 -3
- package/utils/python-json.ts +13 -4
- package/utils/python-random.ts +17 -7
- package/utils/repo.ts +8 -0
- package/utils/sealed-db.ts +10 -2
- package/utils/stats.ts +11 -5
|
@@ -30,6 +30,9 @@
|
|
|
30
30
|
* Run: `mailwoman placer eval openset [--model <dir>] [--out-md <path>]`
|
|
31
31
|
*/
|
|
32
32
|
|
|
33
|
+
/* oxlint-disable sister-software/prefer-region-over-marks -- these markers label steps inside one
|
|
34
|
+
procedure, not sections of declarations. A region there folds nothing a reader wants folded. */
|
|
35
|
+
|
|
33
36
|
import { readFileSync, writeFileSync } from "node:fs"
|
|
34
37
|
import * as path from "node:path"
|
|
35
38
|
|
|
@@ -38,6 +41,16 @@ import { repoRootPath } from "../../utils/repo.ts"
|
|
|
38
41
|
import type { CoarsePlacerMeta } from "../coarse-placer.ts"
|
|
39
42
|
import { COARSE_CLASSES, featurize } from "../featurize.ts"
|
|
40
43
|
|
|
44
|
+
/**
|
|
45
|
+
* Steps in the threshold sweep; finer than the reporting precision so the knee is not missed.
|
|
46
|
+
*/
|
|
47
|
+
const QUANTILE_SWEEP_STEPS = 200
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Percentage both held-out catch and in-map accuracy must clear for an operating point to qualify.
|
|
51
|
+
*/
|
|
52
|
+
const TARGET_PERCENT = 90
|
|
53
|
+
|
|
41
54
|
type ScoreKey = "maxprob" | "p_inmap" | "energy" | "maxlogit" | "maha"
|
|
42
55
|
|
|
43
56
|
interface DataRow {
|
|
@@ -59,21 +72,35 @@ interface ParetoPoint {
|
|
|
59
72
|
heldCaught: number
|
|
60
73
|
}
|
|
61
74
|
|
|
62
|
-
/**
|
|
75
|
+
/**
|
|
76
|
+
* Options for {@linkcode evalOpenSet}.
|
|
77
|
+
*/
|
|
63
78
|
export interface EvalOpenSetOptions {
|
|
64
|
-
/**
|
|
79
|
+
/**
|
|
80
|
+
* Model artifact dir. Default `$MAILWOMAN_DATA_ROOT/coarse-placer/model`.
|
|
81
|
+
*/
|
|
65
82
|
model?: string
|
|
66
|
-
/**
|
|
83
|
+
/**
|
|
84
|
+
* Dataset dir. Default `<repo>/data/coarse-placer`.
|
|
85
|
+
*/
|
|
67
86
|
data?: string
|
|
68
|
-
/**
|
|
87
|
+
/**
|
|
88
|
+
* Mahalanobis fit rows per class. Default 2000.
|
|
89
|
+
*/
|
|
69
90
|
fitPerClass?: number
|
|
70
|
-
/**
|
|
91
|
+
/**
|
|
92
|
+
* Also write the markdown report here.
|
|
93
|
+
*/
|
|
71
94
|
outMd?: string
|
|
72
95
|
}
|
|
73
96
|
|
|
74
|
-
/**
|
|
97
|
+
/**
|
|
98
|
+
* Result of {@linkcode evalOpenSet}.
|
|
99
|
+
*/
|
|
75
100
|
export interface EvalOpenSetResult {
|
|
76
|
-
/**
|
|
101
|
+
/**
|
|
102
|
+
* Best score by the honest dev→test balanced min.
|
|
103
|
+
*/
|
|
77
104
|
winner: ScoreKey
|
|
78
105
|
honestMin: number
|
|
79
106
|
clears90: boolean
|
|
@@ -87,6 +114,7 @@ function logsumexp(xs: number[]): number {
|
|
|
87
114
|
if (x > m) {
|
|
88
115
|
m = x
|
|
89
116
|
}
|
|
117
|
+
|
|
90
118
|
let s = 0
|
|
91
119
|
|
|
92
120
|
for (const x of xs) {
|
|
@@ -96,7 +124,9 @@ function logsumexp(xs: number[]): number {
|
|
|
96
124
|
return m + Math.log(s)
|
|
97
125
|
}
|
|
98
126
|
|
|
99
|
-
/**
|
|
127
|
+
/**
|
|
128
|
+
* Per-class softmax prob over ALL 12 classes.
|
|
129
|
+
*/
|
|
100
130
|
function softmax(z: Float64Array): Float64Array {
|
|
101
131
|
const m = Math.max(...z)
|
|
102
132
|
const e = z.map((x) => Math.exp(x - m))
|
|
@@ -105,15 +135,19 @@ function softmax(z: Float64Array): Float64Array {
|
|
|
105
135
|
return e.map((x) => x / s)
|
|
106
136
|
}
|
|
107
137
|
|
|
108
|
-
/**
|
|
138
|
+
/**
|
|
139
|
+
* Invert a symmetric positive-definite matrix via Gauss-Jordan.
|
|
140
|
+
*/
|
|
109
141
|
function inverse(M: Float64Array[]): number[][] {
|
|
110
142
|
const n = M.length
|
|
143
|
+
|
|
111
144
|
const A = M.map((row, i) => {
|
|
112
145
|
const r = new Float64Array(2 * n)
|
|
113
146
|
|
|
114
147
|
for (let j = 0; j < n; j++) {
|
|
115
148
|
r[j] = row[j]!
|
|
116
149
|
}
|
|
150
|
+
|
|
117
151
|
r[n + i] = 1
|
|
118
152
|
|
|
119
153
|
return r
|
|
@@ -126,6 +160,7 @@ function inverse(M: Float64Array[]): number[][] {
|
|
|
126
160
|
if (Math.abs(A[r]![col]!) > Math.abs(A[piv]![col]!)) {
|
|
127
161
|
piv = r
|
|
128
162
|
}
|
|
163
|
+
|
|
129
164
|
;[A[col], A[piv]] = [A[piv]!, A[col]!]
|
|
130
165
|
const d = A[col]![col]!
|
|
131
166
|
|
|
@@ -146,7 +181,9 @@ function inverse(M: Float64Array[]): number[][] {
|
|
|
146
181
|
return A.map((r) => Array.from(r.slice(n)))
|
|
147
182
|
}
|
|
148
183
|
|
|
149
|
-
/**
|
|
184
|
+
/**
|
|
185
|
+
* Coarse-placer post-hoc open-set score comparison — see the module doc. Emits the markdown report to stdout.
|
|
186
|
+
*/
|
|
150
187
|
export async function evalOpenSet(
|
|
151
188
|
options: EvalOpenSetOptions = {},
|
|
152
189
|
report?: (line: string) => void
|
|
@@ -166,7 +203,9 @@ export async function evalOpenSet(
|
|
|
166
203
|
|
|
167
204
|
if (W.length !== C * D) throw new Error(`weights ${W.length} ≠ ${C}×${D}`)
|
|
168
205
|
|
|
169
|
-
/**
|
|
206
|
+
/**
|
|
207
|
+
* Raw logits (PRE-temperature) for the 12 classes. OOD scores use the geometry, not calibration.
|
|
208
|
+
*/
|
|
170
209
|
function logits(raw: string): Float64Array {
|
|
171
210
|
const feats = featurize(raw)
|
|
172
211
|
const z = new Float64Array(C)
|
|
@@ -178,13 +217,16 @@ export async function evalOpenSet(
|
|
|
178
217
|
for (const i of feats) {
|
|
179
218
|
s += W[base + i]!
|
|
180
219
|
}
|
|
220
|
+
|
|
181
221
|
z[c] = s
|
|
182
222
|
}
|
|
183
223
|
|
|
184
224
|
return z
|
|
185
225
|
}
|
|
186
226
|
|
|
187
|
-
/**
|
|
227
|
+
/**
|
|
228
|
+
* In-map logit sub-vector (length nIn), in IN order.
|
|
229
|
+
*/
|
|
188
230
|
const inVec = (z: Float64Array): number[] => IN.map((c) => z[c]!)
|
|
189
231
|
|
|
190
232
|
function load(file: string): DataRow[] {
|
|
@@ -194,10 +236,8 @@ export async function evalOpenSet(
|
|
|
194
236
|
.map((l) => JSON.parse(l) as DataRow)
|
|
195
237
|
}
|
|
196
238
|
|
|
197
|
-
// ---------------------------------------------------------------------------
|
|
198
239
|
// Fit the Mahalanobis params on IN-MAP TRAIN logits (no test leak): per-class
|
|
199
240
|
// mean in the nIn-dim in-map-logit space + a tied (shared) covariance.
|
|
200
|
-
// ---------------------------------------------------------------------------
|
|
201
241
|
report?.("fitting Mahalanobis on in-map train logits…")
|
|
202
242
|
const trainRows = load("train.jsonl")
|
|
203
243
|
const byClass = new Map<string, string[]>(COARSE_CLASSES.map((c): [string, string[]] => [c, []]))
|
|
@@ -210,12 +250,13 @@ export async function evalOpenSet(
|
|
|
210
250
|
arr.push(r.raw)
|
|
211
251
|
}
|
|
212
252
|
}
|
|
253
|
+
|
|
213
254
|
const means = new Map<string, Float64Array>() // country -> Float64Array(nIn)
|
|
214
255
|
const counts = new Map<string, number>()
|
|
215
256
|
|
|
216
257
|
// Accumulate per-class means.
|
|
217
258
|
for (const [country, raws] of byClass) {
|
|
218
|
-
if (raws.length
|
|
259
|
+
if (!raws.length) continue
|
|
219
260
|
const mu = new Float64Array(nIn)
|
|
220
261
|
|
|
221
262
|
for (const raw of raws) {
|
|
@@ -229,9 +270,11 @@ export async function evalOpenSet(
|
|
|
229
270
|
for (let k = 0; k < nIn; k++) {
|
|
230
271
|
mu[k] = mu[k]! / raws.length
|
|
231
272
|
}
|
|
273
|
+
|
|
232
274
|
means.set(country, mu)
|
|
233
275
|
counts.set(country, raws.length)
|
|
234
276
|
}
|
|
277
|
+
|
|
235
278
|
// Tied covariance over centered in-map train logits.
|
|
236
279
|
const Sigma = Array.from({ length: nIn }, () => new Float64Array(nIn))
|
|
237
280
|
let nTot = 0
|
|
@@ -254,6 +297,7 @@ export async function evalOpenSet(
|
|
|
254
297
|
Sigma[a]![b] = Sigma[a]![b]! + d[a]! * d[b]!
|
|
255
298
|
}
|
|
256
299
|
}
|
|
300
|
+
|
|
257
301
|
nTot++
|
|
258
302
|
}
|
|
259
303
|
}
|
|
@@ -271,7 +315,9 @@ export async function evalOpenSet(
|
|
|
271
315
|
|
|
272
316
|
const SigmaInv = inverse(Sigma)
|
|
273
317
|
|
|
274
|
-
/**
|
|
318
|
+
/**
|
|
319
|
+
* -min_c Mahalanobis² to any in-map class mean (higher = closer to the in-map manifold).
|
|
320
|
+
*/
|
|
275
321
|
function mahaScore(z: Float64Array): number {
|
|
276
322
|
const v = inVec(z)
|
|
277
323
|
let best = Infinity
|
|
@@ -282,6 +328,7 @@ export async function evalOpenSet(
|
|
|
282
328
|
for (let k = 0; k < nIn; k++) {
|
|
283
329
|
d[k] = v[k]! - mu[k]!
|
|
284
330
|
}
|
|
331
|
+
|
|
285
332
|
let q = 0
|
|
286
333
|
|
|
287
334
|
for (let a = 0; a < nIn; a++) {
|
|
@@ -290,6 +337,7 @@ export async function evalOpenSet(
|
|
|
290
337
|
for (let b = 0; b < nIn; b++) {
|
|
291
338
|
row += SigmaInv[a]![b]! * d[b]!
|
|
292
339
|
}
|
|
340
|
+
|
|
293
341
|
q += d[a]! * row
|
|
294
342
|
}
|
|
295
343
|
|
|
@@ -301,17 +349,19 @@ export async function evalOpenSet(
|
|
|
301
349
|
return -best
|
|
302
350
|
}
|
|
303
351
|
|
|
304
|
-
//
|
|
305
|
-
|
|
306
|
-
// ---------------------------------------------------------------------------
|
|
352
|
+
// MARK: Score both splits
|
|
353
|
+
|
|
307
354
|
report?.("scoring in-map test + off-map heldout…")
|
|
308
355
|
const SCORES: ScoreKey[] = ["maxprob", "p_inmap", "energy", "maxlogit", "maha"]
|
|
309
356
|
|
|
310
|
-
/**
|
|
357
|
+
/**
|
|
358
|
+
* All open-set scores for one raw string + whether argmax-in-map routes to `trueCountry`.
|
|
359
|
+
*/
|
|
311
360
|
function scoreRow(raw: string, trueCountry: string | undefined): ScoredRow {
|
|
312
361
|
const z = logits(raw)
|
|
313
362
|
const probs = softmax(z)
|
|
314
363
|
const zin = inVec(z)
|
|
364
|
+
|
|
315
365
|
// argmax over in-map classes (the FIXED routing).
|
|
316
366
|
let amIdx = 0,
|
|
317
367
|
am = -Infinity
|
|
@@ -321,6 +371,7 @@ export async function evalOpenSet(
|
|
|
321
371
|
am = zin[k]!
|
|
322
372
|
amIdx = k
|
|
323
373
|
}
|
|
374
|
+
|
|
324
375
|
const routedCountry = COARSE_CLASSES[IN[amIdx]!]!
|
|
325
376
|
const inmapProbMax = Math.max(...IN.map((c) => probs[c]!))
|
|
326
377
|
|
|
@@ -350,7 +401,9 @@ export async function evalOpenSet(
|
|
|
350
401
|
const heldDev = heldoutScored.filter((_, i) => i % 2 === 0)
|
|
351
402
|
const heldTest = heldoutScored.filter((_, i) => i % 2 === 1)
|
|
352
403
|
|
|
353
|
-
/**
|
|
404
|
+
/**
|
|
405
|
+
* (inMapAcc, heldCaught) at threshold t over a given in-map/heldout split.
|
|
406
|
+
*/
|
|
354
407
|
function pointAt(scoreKey: ScoreKey, t: number, inSplit: ScoredRow[], heldSplit: ScoredRow[]): ParetoPoint {
|
|
355
408
|
let keepCorrect = 0
|
|
356
409
|
|
|
@@ -358,6 +411,7 @@ export async function evalOpenSet(
|
|
|
358
411
|
if (o.s[scoreKey] >= t && o.correctRoute) {
|
|
359
412
|
keepCorrect++
|
|
360
413
|
}
|
|
414
|
+
|
|
361
415
|
let caught = 0
|
|
362
416
|
|
|
363
417
|
for (const o of heldSplit)
|
|
@@ -374,15 +428,17 @@ export async function evalOpenSet(
|
|
|
374
428
|
const inVals = inmapScored.map((o) => ({ v: o.s[scoreKey], ok: o.correctRoute }))
|
|
375
429
|
const heldVals = heldoutScored.map((o) => o.s[scoreKey])
|
|
376
430
|
// Candidate thresholds: quantiles of the union of scores.
|
|
377
|
-
const all = [...inVals.map((x) => x.v), ...heldVals].
|
|
431
|
+
const all = [...inVals.map((x) => x.v), ...heldVals].toSorted((a, b) => a - b)
|
|
378
432
|
const ts: number[] = []
|
|
379
433
|
|
|
380
|
-
for (let q = 0; q <=
|
|
434
|
+
for (let q = 0; q <= QUANTILE_SWEEP_STEPS; q++) {
|
|
381
435
|
ts.push(all[Math.min(all.length - 1, Math.floor((q / 200) * (all.length - 1)))]!)
|
|
382
436
|
}
|
|
437
|
+
|
|
383
438
|
const uniq = [...new Set(ts)]
|
|
384
439
|
const nInVals = inVals.length
|
|
385
440
|
const nHeld = heldVals.length
|
|
441
|
+
|
|
386
442
|
const pts: ParetoPoint[] = uniq.map((t) => {
|
|
387
443
|
let keepCorrect = 0
|
|
388
444
|
|
|
@@ -390,6 +446,7 @@ export async function evalOpenSet(
|
|
|
390
446
|
if (x.v >= t && x.ok) {
|
|
391
447
|
keepCorrect++
|
|
392
448
|
}
|
|
449
|
+
|
|
393
450
|
let caught = 0
|
|
394
451
|
|
|
395
452
|
for (const v of heldVals)
|
|
@@ -399,6 +456,7 @@ export async function evalOpenSet(
|
|
|
399
456
|
|
|
400
457
|
return { t, inMapAcc: (100 * keepCorrect) / nInVals, heldCaught: (100 * caught) / nHeld }
|
|
401
458
|
})
|
|
459
|
+
|
|
402
460
|
// Summaries.
|
|
403
461
|
let balanced: { val: number; pt: ParetoPoint | null } = { val: -1, pt: null } // max of min(inMapAcc, heldCaught) on the FULL probe
|
|
404
462
|
let atHeld90: ParetoPoint | null = null // highest inMapAcc with heldCaught >= 90
|
|
@@ -412,11 +470,11 @@ export async function evalOpenSet(
|
|
|
412
470
|
balanced = { val: m, pt: p }
|
|
413
471
|
}
|
|
414
472
|
|
|
415
|
-
if (p.heldCaught >=
|
|
473
|
+
if (p.heldCaught >= TARGET_PERCENT && (!atHeld90 || p.inMapAcc > atHeld90.inMapAcc)) {
|
|
416
474
|
atHeld90 = p
|
|
417
475
|
}
|
|
418
476
|
|
|
419
|
-
if (p.inMapAcc >=
|
|
477
|
+
if (p.inMapAcc >= TARGET_PERCENT && (!atIn90 || p.heldCaught > atIn90.heldCaught)) {
|
|
420
478
|
atIn90 = p
|
|
421
479
|
}
|
|
422
480
|
}
|
|
@@ -432,6 +490,7 @@ export async function evalOpenSet(
|
|
|
432
490
|
devBest = { val: m, t: p.t }
|
|
433
491
|
}
|
|
434
492
|
}
|
|
493
|
+
|
|
435
494
|
const heldoutTestPt = pointAt(scoreKey, devBest.t!, inTest, heldTest)
|
|
436
495
|
|
|
437
496
|
return { balanced, atHeld90, atIn90, devThreshold: devBest.t, honest: heldoutTestPt, pts }
|
|
@@ -440,20 +499,20 @@ export async function evalOpenSet(
|
|
|
440
499
|
type Pareto = ReturnType<typeof paretoFor>
|
|
441
500
|
const results = Object.fromEntries(SCORES.map((k) => [k, paretoFor(k)])) as Record<ScoreKey, Pareto>
|
|
442
501
|
|
|
443
|
-
//
|
|
444
|
-
|
|
445
|
-
// ---------------------------------------------------------------------------
|
|
502
|
+
// MARK: Report.
|
|
503
|
+
|
|
446
504
|
const f = (x: number | null | undefined): string => (x == null ? "—" : x.toFixed(1))
|
|
447
|
-
|
|
448
|
-
lines
|
|
449
|
-
|
|
450
|
-
|
|
505
|
+
|
|
506
|
+
const lines: string[] = [
|
|
507
|
+
`# Coarse-placer M2 Phase 1 — post-hoc open-set score comparison (#244)`,
|
|
508
|
+
"",
|
|
451
509
|
`_Frozen shipped model (\`${path.basename(modelDir)}\`), NO retrain. In-map test ${inmapTest.length} rows ` +
|
|
452
510
|
`(11 countries); off-map HELDOUT ${heldout.length} rows (never-trained families: baltic/oceania/middle-east). ` +
|
|
453
511
|
`Mahalanobis fit on ≤${fitPerClass}/class in-map train logits. The 11-way routing is fixed; each score only ` +
|
|
454
|
-
`changes the reject decision._
|
|
455
|
-
|
|
456
|
-
|
|
512
|
+
`changes the reject decision._`,
|
|
513
|
+
"",
|
|
514
|
+
]
|
|
515
|
+
|
|
457
516
|
function atStr(p: ParetoPoint | null): string {
|
|
458
517
|
if (!p) return "— (unreachable)"
|
|
459
518
|
|
|
@@ -468,10 +527,12 @@ export async function evalOpenSet(
|
|
|
468
527
|
for (const k of SCORES) {
|
|
469
528
|
const r = results[k]
|
|
470
529
|
const h = r.honest
|
|
530
|
+
|
|
471
531
|
lines.push(
|
|
472
532
|
`| \`${k}\` | ${f(h.inMapAcc)} | ${f(h.heldCaught)} | **${f(Math.min(h.inMapAcc, h.heldCaught))}** | ${f(r.balanced.val)} |`
|
|
473
533
|
)
|
|
474
534
|
}
|
|
535
|
+
|
|
475
536
|
lines.push("")
|
|
476
537
|
lines.push(`## Full-probe corners (the achievable Pareto), per score`)
|
|
477
538
|
lines.push("")
|
|
@@ -481,33 +542,39 @@ export async function evalOpenSet(
|
|
|
481
542
|
for (const k of SCORES) {
|
|
482
543
|
const r = results[k]
|
|
483
544
|
const bal = r.balanced.pt
|
|
545
|
+
|
|
484
546
|
lines.push(
|
|
485
547
|
`| \`${k}\` | **${f(r.balanced.val)}** (in ${f(bal?.inMapAcc)}, held ${f(bal?.heldCaught)}) | ` +
|
|
486
548
|
`${atStr(r.atHeld90)} | ${atStr(r.atIn90)} |`
|
|
487
549
|
)
|
|
488
550
|
}
|
|
551
|
+
|
|
489
552
|
lines.push("")
|
|
490
553
|
|
|
491
554
|
// Winner by the HONEST dev→test balanced min (not the full-probe number).
|
|
492
555
|
const ranked = SCORES.map((k) => ({
|
|
493
556
|
k,
|
|
494
557
|
honestMin: Math.min(results[k].honest.inMapAcc, results[k].honest.heldCaught),
|
|
495
|
-
})).
|
|
558
|
+
})).toSorted((a, b) => b.honestMin - a.honestMin)
|
|
559
|
+
|
|
496
560
|
const winner = ranked[0]!
|
|
497
|
-
const clears90 = winner.honestMin >=
|
|
561
|
+
const clears90 = winner.honestMin >= TARGET_PERCENT
|
|
498
562
|
lines.push(`## Verdict`)
|
|
499
563
|
lines.push("")
|
|
564
|
+
|
|
500
565
|
lines.push(
|
|
501
566
|
`Best score (honest dev→test): **\`${winner.k}\`** at min(in-map, heldout) = **${f(winner.honestMin)}** on the frozen test half. ` +
|
|
502
567
|
(clears90
|
|
503
568
|
? `**Clears 90/90 post-hoc** — wire it into CoarsePlacer as the open-set reject rule; no retrain needed (Phase 2 reject-head unnecessary).`
|
|
504
569
|
: `Below the 90/90 bar — the best post-hoc score reaches ${f(winner.honestMin)}. Escalate to Phase 2 (explicit binary reject head).`)
|
|
505
570
|
)
|
|
571
|
+
|
|
506
572
|
lines.push("")
|
|
507
573
|
lines.push(`Ranking (honest dev→test min): ${ranked.map((r) => `\`${r.k}\` ${f(r.honestMin)}`).join(" · ")}`)
|
|
508
574
|
lines.push("")
|
|
509
575
|
|
|
510
576
|
const md = lines.join("\n")
|
|
577
|
+
|
|
511
578
|
console.log(md)
|
|
512
579
|
|
|
513
580
|
if (options.outMd) {
|
|
@@ -23,30 +23,50 @@ interface TestRow {
|
|
|
23
23
|
country: string
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
/**
|
|
26
|
+
/**
|
|
27
|
+
* Options for {@linkcode evalQuantCompare}.
|
|
28
|
+
*/
|
|
27
29
|
export interface EvalQuantCompareOptions {
|
|
28
|
-
/**
|
|
30
|
+
/**
|
|
31
|
+
* Fp32 artifact dir. Default `$MAILWOMAN_DATA_ROOT/coarse-placer/model`.
|
|
32
|
+
*/
|
|
29
33
|
fp32?: string
|
|
30
|
-
/**
|
|
34
|
+
/**
|
|
35
|
+
* Int8 artifact dir. Default `$MAILWOMAN_DATA_ROOT/coarse-placer/model-int8`.
|
|
36
|
+
*/
|
|
31
37
|
int8?: string
|
|
32
|
-
/**
|
|
38
|
+
/**
|
|
39
|
+
* Abstention threshold. Default 0.5.
|
|
40
|
+
*/
|
|
33
41
|
abstain?: number
|
|
34
|
-
/**
|
|
42
|
+
/**
|
|
43
|
+
* Dataset dir (`test.jsonl`). Default `<repo>/data/coarse-placer`.
|
|
44
|
+
*/
|
|
35
45
|
data?: string
|
|
36
46
|
}
|
|
37
47
|
|
|
38
|
-
/**
|
|
48
|
+
/**
|
|
49
|
+
* Result of {@linkcode evalQuantCompare}.
|
|
50
|
+
*/
|
|
39
51
|
export interface EvalQuantCompareResult {
|
|
40
52
|
n: number
|
|
41
|
-
/**
|
|
53
|
+
/**
|
|
54
|
+
* Fp32 overall accuracy in percent.
|
|
55
|
+
*/
|
|
42
56
|
accFp32: number
|
|
43
|
-
/**
|
|
57
|
+
/**
|
|
58
|
+
* Int8 overall accuracy in percent.
|
|
59
|
+
*/
|
|
44
60
|
accInt8: number
|
|
45
|
-
/**
|
|
61
|
+
/**
|
|
62
|
+
* Whether int8 is within 1pp of fp32 (the gate).
|
|
63
|
+
*/
|
|
46
64
|
pass: boolean
|
|
47
65
|
}
|
|
48
66
|
|
|
49
|
-
/**
|
|
67
|
+
/**
|
|
68
|
+
* Coarse-placer int8-vs-fp32 comparison — see the module doc. Emits the report to stdout.
|
|
69
|
+
*/
|
|
50
70
|
export async function evalQuantCompare(options: EvalQuantCompareOptions = {}): Promise<EvalQuantCompareResult> {
|
|
51
71
|
const fp32Dir = options.fp32 || dataRootPath("coarse-placer", "model")
|
|
52
72
|
const int8Dir = options.int8 || dataRootPath("coarse-placer", "model-int8")
|
|
@@ -61,6 +81,7 @@ export async function evalQuantCompare(options: EvalQuantCompareOptions = {}): P
|
|
|
61
81
|
|
|
62
82
|
return new CoarsePlacer({ ...meta, weights }, { abstainBelow })
|
|
63
83
|
}
|
|
84
|
+
|
|
64
85
|
function loadInt8(dir: string): CoarsePlacer {
|
|
65
86
|
const meta = JSON.parse(readFileSync(path.join(dir, "meta.json"), "utf8")) as CoarsePlacerMeta
|
|
66
87
|
const buf = readFileSync(path.join(dir, "weights.bin"))
|
|
@@ -103,28 +124,34 @@ export async function evalQuantCompare(options: EvalQuantCompareOptions = {}): P
|
|
|
103
124
|
const pf = fp32.predict(r.raw)
|
|
104
125
|
const pi = int8.predict(r.raw)
|
|
105
126
|
const cf = pf.country ?? "(abstain)"
|
|
127
|
+
|
|
106
128
|
const ci = pi.country ?? "(abstain)"
|
|
107
129
|
;(perF[r.country] ??= { n: 0, ok: 0 }).n++
|
|
108
130
|
;(perI[r.country] ??= { n: 0, ok: 0 }).n++
|
|
109
131
|
|
|
110
132
|
if (cf === r.country) {
|
|
111
133
|
okF++
|
|
134
|
+
|
|
112
135
|
perF[r.country]!.ok++
|
|
113
136
|
}
|
|
114
137
|
|
|
115
138
|
if (ci === r.country) {
|
|
116
139
|
okI++
|
|
140
|
+
|
|
117
141
|
perI[r.country]!.ok++
|
|
118
142
|
}
|
|
119
143
|
|
|
120
144
|
if (cf === ci) {
|
|
121
145
|
agree++
|
|
122
146
|
}
|
|
147
|
+
|
|
123
148
|
confMae += Math.abs(pf.confidence - pi.confidence)
|
|
124
149
|
}
|
|
150
|
+
|
|
125
151
|
const N = test.length
|
|
126
152
|
const accF = (100 * okF) / N
|
|
127
153
|
const accI = (100 * okI) / N
|
|
154
|
+
|
|
128
155
|
console.log(`coarse-placer int8 vs fp32 — test n=${N} (abstain ${abstainBelow})`)
|
|
129
156
|
console.log(
|
|
130
157
|
` overall accuracy: fp32 ${accF.toFixed(2)}% int8 ${accI.toFixed(2)}% Δ ${(accI - accF >= 0 ? "+" : "") + (accI - accF).toFixed(2)}pp`
|
|
@@ -140,11 +167,14 @@ export async function evalQuantCompare(options: EvalQuantCompareOptions = {}): P
|
|
|
140
167
|
if (!f) continue
|
|
141
168
|
const rf = (100 * f.ok) / f.n
|
|
142
169
|
const ri = (100 * i.ok) / i.n
|
|
170
|
+
|
|
143
171
|
console.log(
|
|
144
172
|
` ${c.padEnd(6)} ${rf.toFixed(1)}% → ${ri.toFixed(1)}% (Δ ${(ri - rf >= 0 ? "+" : "") + (ri - rf).toFixed(1)}pp, n=${f.n})`
|
|
145
173
|
)
|
|
146
174
|
}
|
|
147
|
-
|
|
175
|
+
|
|
176
|
+
const pass = Math.abs(accI - accF) <= 1
|
|
177
|
+
|
|
148
178
|
console.log(` gate: ${pass ? "PASS (within 1pp)" : "FAIL (>1pp drop)"}`)
|
|
149
179
|
|
|
150
180
|
return { n: N, accFp32: accF, accInt8: accI, pass }
|