@atlaskit/editor-plugin-autocomplete 9.0.0 → 9.1.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/CHANGELOG.md +28 -0
- package/dist/cjs/pm-plugins/autocomplete-plugin.js +82 -31
- package/dist/cjs/pm-plugins/debug-mode.js +17 -2
- package/dist/cjs/pm-plugins/text-predictor.js +290 -178
- package/dist/es2019/pm-plugins/autocomplete-plugin.js +64 -22
- package/dist/es2019/pm-plugins/debug-mode.js +16 -1
- package/dist/es2019/pm-plugins/text-predictor.js +91 -3
- package/dist/esm/pm-plugins/autocomplete-plugin.js +82 -31
- package/dist/esm/pm-plugins/debug-mode.js +16 -1
- package/dist/esm/pm-plugins/text-predictor.js +290 -178
- package/dist/types/pm-plugins/debug-mode.d.ts +19 -0
- package/dist/types/pm-plugins/text-predictor.d.ts +36 -1
- package/package.json +2 -2
- package/src/pm-plugins/autocomplete-plugin.ts +67 -21
- package/src/pm-plugins/debug-mode.ts +26 -1
- package/src/pm-plugins/text-predictor.ts +116 -2
|
@@ -25,14 +25,17 @@ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length)
|
|
|
25
25
|
* Falls back to cold mode (freq-only) when vectors not yet loaded.
|
|
26
26
|
*
|
|
27
27
|
* Session personalization (L1): words the user types are incrementally boosted
|
|
28
|
-
* via incrementSessionFreq(), called on word boundaries from the plugin
|
|
28
|
+
* via incrementSessionFreq(), called on word boundaries from the plugin, and
|
|
29
|
+
* words in ingested context text via ingestDocumentPage(). What the session has
|
|
30
|
+
* boosted is visible at any time from the console: `__atlCtcDebug__.session()`,
|
|
31
|
+
* or `__atlCtcDebug__.session('poll')` for one family — see inspectSessionBoosts.
|
|
29
32
|
*/
|
|
30
33
|
|
|
31
34
|
import { EXPERIENCE_NAME, failExp, startExp, succeedExp } from '../analytics/ufo';
|
|
32
35
|
import { fetchAutocompleteArtifactBinary, fetchAutocompleteArtifactJson } from './artifact-loader';
|
|
33
36
|
import { ARTIFACT_NAME } from './artifacts-manifest';
|
|
34
37
|
import { createCanonicalContextPositionCache, deriveCanonicalCandidateContext, deriveWhitespaceBoundaryContext, logSoftmaxAt, logSumExp, selectBoundaryPrimeRequests } from './canonical-lm-scoring';
|
|
35
|
-
import { CTC_STYLES, ctcSection, ctcTag, isAutocompleteDebugEnabled, isAutocompleteDebugVerbose } from './debug-mode';
|
|
38
|
+
import { CTC_STYLES, ctcSection, ctcTag, isAutocompleteDebugEnabled, isAutocompleteDebugVerbose, registerCtcSessionInspector } from './debug-mode';
|
|
36
39
|
import { loadGrammarDataAsync, rankCandidates, STAGE1_WEIGHT, STAGE2_WEIGHT, MIN_STAGE1_SCORE, MIN_WINNER_MARGIN } from './scoring-pipeline';
|
|
37
40
|
import { getBoundaryLmState, getCanonicalSurfaceCount, getCanonicalSurfaceTokenIds, getDefaultSlowLaneClientStatus, getProgressiveSurfaceEvidence, getStoredContextInput, getStoredContextVector, getStoredLmLogits, getSurfaceScore, isCanonicalSurfaceScoringSupported, primeBoundaryLm, requestProgressiveSurfaceScores } from './slow-lane-client';
|
|
38
41
|
|
|
@@ -356,6 +359,65 @@ var WeightedWordTrie = /*#__PURE__*/function () {
|
|
|
356
359
|
node.sessionFreq += 1;
|
|
357
360
|
return true;
|
|
358
361
|
}
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* Every word carrying a session boost, optionally limited to one prefix's
|
|
365
|
+
* subtree. Unlike `getCandidates` a word equal to the prefix is included,
|
|
366
|
+
* since the question here is what the session holds rather than what could
|
|
367
|
+
* still be typed.
|
|
368
|
+
*
|
|
369
|
+
* Walks the trie instead of reading an index, so nothing has to be kept in
|
|
370
|
+
* step on the write path for the sake of being able to ask.
|
|
371
|
+
*/
|
|
372
|
+
}, {
|
|
373
|
+
key: "collectSessionBoosted",
|
|
374
|
+
value: function collectSessionBoosted() {
|
|
375
|
+
var prefix = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
376
|
+
var node = this.root;
|
|
377
|
+
var _iterator5 = _createForOfIteratorHelper(prefix.toLowerCase()),
|
|
378
|
+
_step5;
|
|
379
|
+
try {
|
|
380
|
+
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
381
|
+
var char = _step5.value;
|
|
382
|
+
var next = node.children.get(char);
|
|
383
|
+
if (!next) {
|
|
384
|
+
return [];
|
|
385
|
+
}
|
|
386
|
+
node = next;
|
|
387
|
+
}
|
|
388
|
+
} catch (err) {
|
|
389
|
+
_iterator5.e(err);
|
|
390
|
+
} finally {
|
|
391
|
+
_iterator5.f();
|
|
392
|
+
}
|
|
393
|
+
var boosted = [];
|
|
394
|
+
var stack = [node];
|
|
395
|
+
while (stack.length > 0) {
|
|
396
|
+
var current = stack.pop();
|
|
397
|
+
if (!current) {
|
|
398
|
+
continue;
|
|
399
|
+
}
|
|
400
|
+
if (current.word !== null && current.sessionFreq > 0) {
|
|
401
|
+
boosted.push({
|
|
402
|
+
word: current.word,
|
|
403
|
+
node: current
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
var _iterator6 = _createForOfIteratorHelper(current.children.values()),
|
|
407
|
+
_step6;
|
|
408
|
+
try {
|
|
409
|
+
for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
|
|
410
|
+
var child = _step6.value;
|
|
411
|
+
stack.push(child);
|
|
412
|
+
}
|
|
413
|
+
} catch (err) {
|
|
414
|
+
_iterator6.e(err);
|
|
415
|
+
} finally {
|
|
416
|
+
_iterator6.f();
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
return boosted;
|
|
420
|
+
}
|
|
359
421
|
}]);
|
|
360
422
|
}(); // L1/L2 Trie (Session + Atlassian Domain)
|
|
361
423
|
var wordTrie = new WeightedWordTrie();
|
|
@@ -377,19 +439,19 @@ var phraseTrie = new WeightedWordTrie();
|
|
|
377
439
|
* expects a simple array of strings: ["about", "above", "actually", ...]
|
|
378
440
|
*/
|
|
379
441
|
export var initL3Vocabulary = function initL3Vocabulary(l3Words) {
|
|
380
|
-
var
|
|
381
|
-
|
|
442
|
+
var _iterator7 = _createForOfIteratorHelper(l3Words),
|
|
443
|
+
_step7;
|
|
382
444
|
try {
|
|
383
|
-
for (
|
|
384
|
-
var word =
|
|
445
|
+
for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
|
|
446
|
+
var word = _step7.value;
|
|
385
447
|
// Insert with a tiny baseline frequency so it mathematically
|
|
386
448
|
// loses to any domain word in Stage 1, but still scores above 0.
|
|
387
449
|
l3Trie.insert(word, L3_BASELINE_FREQ, 0, 0);
|
|
388
450
|
}
|
|
389
451
|
} catch (err) {
|
|
390
|
-
|
|
452
|
+
_iterator7.e(err);
|
|
391
453
|
} finally {
|
|
392
|
-
|
|
454
|
+
_iterator7.f();
|
|
393
455
|
}
|
|
394
456
|
recallGeneration++;
|
|
395
457
|
ctcTag('init', "L3 general English loaded: ".concat(l3Words.length, " words"));
|
|
@@ -470,20 +532,20 @@ var computeContextVectorLocal = function computeContextVectorLocal(textBefore) {
|
|
|
470
532
|
var tokens = tokenize(textBefore);
|
|
471
533
|
var words = tokens.slice(-CONTEXT_WORDS);
|
|
472
534
|
var vectors = [];
|
|
473
|
-
var
|
|
474
|
-
|
|
535
|
+
var _iterator8 = _createForOfIteratorHelper(words),
|
|
536
|
+
_step8;
|
|
475
537
|
try {
|
|
476
|
-
for (
|
|
477
|
-
var word =
|
|
538
|
+
for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
|
|
539
|
+
var word = _step8.value;
|
|
478
540
|
var _v = getWordVector(word);
|
|
479
541
|
if (_v) {
|
|
480
542
|
vectors.push(_v);
|
|
481
543
|
}
|
|
482
544
|
}
|
|
483
545
|
} catch (err) {
|
|
484
|
-
|
|
546
|
+
_iterator8.e(err);
|
|
485
547
|
} finally {
|
|
486
|
-
|
|
548
|
+
_iterator8.f();
|
|
487
549
|
}
|
|
488
550
|
if (vectors.length === 0) {
|
|
489
551
|
return null;
|
|
@@ -516,11 +578,11 @@ var getContextVectorForScoring = function getContextVectorForScoring(textBefore)
|
|
|
516
578
|
var tokenize = function tokenize(text) {
|
|
517
579
|
var tokens = [];
|
|
518
580
|
// eslint-disable-next-line @atlassian/perf-linting/no-expensive-split-replace
|
|
519
|
-
var
|
|
520
|
-
|
|
581
|
+
var _iterator9 = _createForOfIteratorHelper(text.toLowerCase().split(WHITESPACE_SPLIT_REGEX)),
|
|
582
|
+
_step9;
|
|
521
583
|
try {
|
|
522
|
-
for (
|
|
523
|
-
var raw =
|
|
584
|
+
for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
|
|
585
|
+
var raw = _step9.value;
|
|
524
586
|
// eslint-disable-next-line @atlassian/perf-linting/no-expensive-split-replace
|
|
525
587
|
var clean = raw.replace(PUNCTUATION_BOUNDARY_REGEX, '');
|
|
526
588
|
if (clean.length >= 2) {
|
|
@@ -528,9 +590,9 @@ var tokenize = function tokenize(text) {
|
|
|
528
590
|
}
|
|
529
591
|
}
|
|
530
592
|
} catch (err) {
|
|
531
|
-
|
|
593
|
+
_iterator9.e(err);
|
|
532
594
|
} finally {
|
|
533
|
-
|
|
595
|
+
_iterator9.f();
|
|
534
596
|
}
|
|
535
597
|
return tokens;
|
|
536
598
|
};
|
|
@@ -634,11 +696,11 @@ var getPhraseCandidates = function getPhraseCandidates(trimmed) {
|
|
|
634
696
|
window: windowPrefix,
|
|
635
697
|
matches: matches.length
|
|
636
698
|
});
|
|
637
|
-
var
|
|
638
|
-
|
|
699
|
+
var _iterator0 = _createForOfIteratorHelper(matches),
|
|
700
|
+
_step0;
|
|
639
701
|
try {
|
|
640
|
-
for (
|
|
641
|
-
var _match =
|
|
702
|
+
for (_iterator0.s(); !(_step0 = _iterator0.n()).done;) {
|
|
703
|
+
var _match = _step0.value;
|
|
642
704
|
if (seen.has(_match.word)) {
|
|
643
705
|
continue;
|
|
644
706
|
}
|
|
@@ -651,9 +713,9 @@ var getPhraseCandidates = function getPhraseCandidates(trimmed) {
|
|
|
651
713
|
});
|
|
652
714
|
}
|
|
653
715
|
} catch (err) {
|
|
654
|
-
|
|
716
|
+
_iterator0.e(err);
|
|
655
717
|
} finally {
|
|
656
|
-
|
|
718
|
+
_iterator0.f();
|
|
657
719
|
}
|
|
658
720
|
}
|
|
659
721
|
logPhrasePath();
|
|
@@ -698,17 +760,17 @@ export var getLastPredictionDebug = function getLastPredictionDebug() {
|
|
|
698
760
|
return lastPredictionDebug;
|
|
699
761
|
};
|
|
700
762
|
export var initVocabulary = function initVocabulary(vocabulary) {
|
|
701
|
-
var
|
|
702
|
-
|
|
763
|
+
var _iterator1 = _createForOfIteratorHelper(vocabulary.terms),
|
|
764
|
+
_step1;
|
|
703
765
|
try {
|
|
704
|
-
for (
|
|
705
|
-
var term =
|
|
766
|
+
for (_iterator1.s(); !(_step1 = _iterator1.n()).done;) {
|
|
767
|
+
var term = _step1.value;
|
|
706
768
|
wordTrie.insert(term.word, term.freq, term.docFreq, term.authorFreq);
|
|
707
769
|
}
|
|
708
770
|
} catch (err) {
|
|
709
|
-
|
|
771
|
+
_iterator1.e(err);
|
|
710
772
|
} finally {
|
|
711
|
-
|
|
773
|
+
_iterator1.f();
|
|
712
774
|
}
|
|
713
775
|
isInitialized = true;
|
|
714
776
|
recallGeneration++;
|
|
@@ -775,23 +837,23 @@ export var ingestDocumentPage = function ingestDocumentPage(pageContent) {
|
|
|
775
837
|
}
|
|
776
838
|
var words = tokenize(pageContent);
|
|
777
839
|
var validBoostedWords = new Set();
|
|
778
|
-
var
|
|
779
|
-
|
|
840
|
+
var _iterator10 = _createForOfIteratorHelper(words),
|
|
841
|
+
_step10;
|
|
780
842
|
try {
|
|
781
|
-
for (
|
|
782
|
-
var word =
|
|
843
|
+
for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
|
|
844
|
+
var word = _step10.value;
|
|
783
845
|
var didBoost = wordTrie.incrementSessionFreq(word);
|
|
784
846
|
if (didBoost) {
|
|
785
847
|
validBoostedWords.add(word);
|
|
786
848
|
}
|
|
787
849
|
}
|
|
788
850
|
} catch (err) {
|
|
789
|
-
|
|
851
|
+
_iterator10.e(err);
|
|
790
852
|
} finally {
|
|
791
|
-
|
|
853
|
+
_iterator10.f();
|
|
792
854
|
}
|
|
793
855
|
if (isAutocompleteDebugEnabled() && validBoostedWords.size > 0) {
|
|
794
|
-
ctcTag('init', "L1 session primed ".concat(validBoostedWords.size, " words from page"), CTC_STYLES.brand);
|
|
856
|
+
ctcTag('init', "L1 session primed ".concat(validBoostedWords.size, " words from page \xB7 __atlCtcDebug__.session() to inspect"), CTC_STYLES.brand);
|
|
795
857
|
if (isAutocompleteDebugVerbose()) {
|
|
796
858
|
// eslint-disable-next-line no-console
|
|
797
859
|
console.dir(Array.from(validBoostedWords).sort());
|
|
@@ -799,6 +861,56 @@ export var ingestDocumentPage = function ingestDocumentPage(pageContent) {
|
|
|
799
861
|
}
|
|
800
862
|
};
|
|
801
863
|
|
|
864
|
+
/**
|
|
865
|
+
* How many boosted words `inspectSessionBoosts` lists.
|
|
866
|
+
*
|
|
867
|
+
* A page ingest can boost thousands, and a list that long is not read. The
|
|
868
|
+
* strongest boosts are the ones that change an ordering, and `boosted` still
|
|
869
|
+
* reports the full size, so the cap loses nothing but volume.
|
|
870
|
+
*/
|
|
871
|
+
var MAX_LISTED_SESSION_WORDS = 50;
|
|
872
|
+
/**
|
|
873
|
+
* Read the session's L1 boosts, optionally narrowed to a prefix.
|
|
874
|
+
*
|
|
875
|
+
* Installed as `__atlCtcDebug__.session()`, with `__atlCtcDebug__.session('poll')`
|
|
876
|
+
* to ask about one family. Returned rather than logged, so the console renders it
|
|
877
|
+
* as an inspectable object and a caller can assert on it.
|
|
878
|
+
*
|
|
879
|
+
* Only words the vocabulary already holds can carry a boost, because both writers
|
|
880
|
+
* go through `incrementSessionFreq` and it only finds existing nodes. An ingested
|
|
881
|
+
* word absent from the vocabulary is therefore missing from here and always will
|
|
882
|
+
* be.
|
|
883
|
+
*/
|
|
884
|
+
export var inspectSessionBoosts = function inspectSessionBoosts(prefix) {
|
|
885
|
+
var boosted = wordTrie.collectSessionBoosted(prefix !== null && prefix !== void 0 ? prefix : '');
|
|
886
|
+
return _objectSpread(_objectSpread({
|
|
887
|
+
boosted: boosted.length,
|
|
888
|
+
limit: MAX_LISTED_SESSION_WORDS
|
|
889
|
+
}, prefix === undefined ? {} : {
|
|
890
|
+
prefix: prefix
|
|
891
|
+
}), {}, {
|
|
892
|
+
words: boosted.sort(function (a, b) {
|
|
893
|
+
return b.node.sessionFreq - a.node.sessionFreq || a.word.localeCompare(b.word, 'en', {
|
|
894
|
+
numeric: true,
|
|
895
|
+
sensitivity: 'base'
|
|
896
|
+
});
|
|
897
|
+
}).slice(0, MAX_LISTED_SESSION_WORDS).map(function (_ref) {
|
|
898
|
+
var node = _ref.node,
|
|
899
|
+
word = _ref.word;
|
|
900
|
+
return {
|
|
901
|
+
sessionFreq: node.sessionFreq,
|
|
902
|
+
sessionOnly: node.tenantFreq === 0,
|
|
903
|
+
surface: word,
|
|
904
|
+
tenantFreq: node.tenantFreq
|
|
905
|
+
};
|
|
906
|
+
})
|
|
907
|
+
});
|
|
908
|
+
};
|
|
909
|
+
|
|
910
|
+
// At module scope so the console answers before the first keystroke, which is
|
|
911
|
+
// when someone reaching for it usually asks.
|
|
912
|
+
registerCtcSessionInspector(inspectSessionBoosts);
|
|
913
|
+
|
|
802
914
|
/**
|
|
803
915
|
* Result of a prediction: the ghost tail to insert plus an immutable record of
|
|
804
916
|
* the evidence that authorized the UI commitment.
|
|
@@ -830,20 +942,20 @@ var computeCanonicalRecall = function computeCanonicalRecall(trimmed, currentWor
|
|
|
830
942
|
var existingWords = new Set(wordCandidates.map(function (c) {
|
|
831
943
|
return c.word;
|
|
832
944
|
}));
|
|
833
|
-
var
|
|
834
|
-
|
|
945
|
+
var _iterator11 = _createForOfIteratorHelper(l3Candidates),
|
|
946
|
+
_step11;
|
|
835
947
|
try {
|
|
836
|
-
for (
|
|
837
|
-
var l3c =
|
|
948
|
+
for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) {
|
|
949
|
+
var l3c = _step11.value;
|
|
838
950
|
if (wordCandidates.length >= MAX_CANDIDATES) break;
|
|
839
951
|
if (!existingWords.has(l3c.word)) {
|
|
840
952
|
wordCandidates.push(l3c);
|
|
841
953
|
}
|
|
842
954
|
}
|
|
843
955
|
} catch (err) {
|
|
844
|
-
|
|
956
|
+
_iterator11.e(err);
|
|
845
957
|
} finally {
|
|
846
|
-
|
|
958
|
+
_iterator11.f();
|
|
847
959
|
}
|
|
848
960
|
}
|
|
849
961
|
|
|
@@ -855,9 +967,9 @@ var computeCanonicalRecall = function computeCanonicalRecall(trimmed, currentWor
|
|
|
855
967
|
// Unify: a word completes the current partial token; a phrase completes its
|
|
856
968
|
// matched multi-word window. Track the prefix length per term so the ghost
|
|
857
969
|
// tail is sliced correctly regardless of term type.
|
|
858
|
-
var matched = [].concat(_toConsumableArray(wordCandidates.map(function (
|
|
859
|
-
var word =
|
|
860
|
-
node =
|
|
970
|
+
var matched = [].concat(_toConsumableArray(wordCandidates.map(function (_ref2) {
|
|
971
|
+
var word = _ref2.word,
|
|
972
|
+
node = _ref2.node;
|
|
861
973
|
return {
|
|
862
974
|
word: word,
|
|
863
975
|
node: node,
|
|
@@ -870,19 +982,19 @@ var computeCanonicalRecall = function computeCanonicalRecall(trimmed, currentWor
|
|
|
870
982
|
return _objectSpread(_objectSpread({}, candidate), deriveCanonicalCandidateContext(trimmed, candidate.matchedPrefixLen, candidate.word, getCanonicalSurfaceTokenIds, candidate.surfaceStart, positionCache));
|
|
871
983
|
});
|
|
872
984
|
var prefixLenByWord = new Map();
|
|
873
|
-
var
|
|
874
|
-
|
|
985
|
+
var _iterator12 = _createForOfIteratorHelper(canonicalMatched),
|
|
986
|
+
_step12;
|
|
875
987
|
try {
|
|
876
|
-
for (
|
|
877
|
-
var m =
|
|
988
|
+
for (_iterator12.s(); !(_step12 = _iterator12.n()).done;) {
|
|
989
|
+
var m = _step12.value;
|
|
878
990
|
if (!prefixLenByWord.has(m.word)) {
|
|
879
991
|
prefixLenByWord.set(m.word, m.matchedPrefixLen);
|
|
880
992
|
}
|
|
881
993
|
}
|
|
882
994
|
} catch (err) {
|
|
883
|
-
|
|
995
|
+
_iterator12.e(err);
|
|
884
996
|
} finally {
|
|
885
|
-
|
|
997
|
+
_iterator12.f();
|
|
886
998
|
}
|
|
887
999
|
return {
|
|
888
1000
|
canonicalMatched: canonicalMatched,
|
|
@@ -976,9 +1088,9 @@ export var predict = function predict(textBefore) {
|
|
|
976
1088
|
var mode = contextVector ? 'warm' : 'cold';
|
|
977
1089
|
|
|
978
1090
|
// Build ScoringCandidate array from matched terms (words + phrases)
|
|
979
|
-
var scoringCandidates = canonicalMatched.map(function (
|
|
980
|
-
var word =
|
|
981
|
-
node =
|
|
1091
|
+
var scoringCandidates = canonicalMatched.map(function (_ref3) {
|
|
1092
|
+
var word = _ref3.word,
|
|
1093
|
+
node = _ref3.node;
|
|
982
1094
|
return {
|
|
983
1095
|
word: word,
|
|
984
1096
|
tenantFreq: node.tenantFreq,
|
|
@@ -998,9 +1110,9 @@ export var predict = function predict(textBefore) {
|
|
|
998
1110
|
var currentWordSeparator = (_canonicalMatched$fin = canonicalMatched.find(function (candidate) {
|
|
999
1111
|
return candidate.node.termType === 'word';
|
|
1000
1112
|
})) === null || _canonicalMatched$fin === void 0 ? void 0 : _canonicalMatched$fin.separatorKind;
|
|
1001
|
-
var prefixLmLogits = lmLogits && currentWordSeparator === 'whitespace' ? Object.fromEntries(Object.entries(lmLogits).filter(function (
|
|
1002
|
-
var
|
|
1003
|
-
word =
|
|
1113
|
+
var prefixLmLogits = lmLogits && currentWordSeparator === 'whitespace' ? Object.fromEntries(Object.entries(lmLogits).filter(function (_ref4) {
|
|
1114
|
+
var _ref5 = _slicedToArray(_ref4, 1),
|
|
1115
|
+
word = _ref5[0];
|
|
1004
1116
|
return word.startsWith(prefix);
|
|
1005
1117
|
})) : null;
|
|
1006
1118
|
var canonicalScoringSupported = isCanonicalSurfaceScoringSupported();
|
|
@@ -1011,29 +1123,29 @@ export var predict = function predict(textBefore) {
|
|
|
1011
1123
|
}))).sort();
|
|
1012
1124
|
var familyKey = eligibleContextKeys.join("\x01");
|
|
1013
1125
|
var primeRequests = selectBoundaryPrimeRequests(familyKey, canonicalMatched, PHRASE_MAX_WORDS);
|
|
1014
|
-
var
|
|
1015
|
-
|
|
1126
|
+
var _iterator13 = _createForOfIteratorHelper(primeRequests),
|
|
1127
|
+
_step13;
|
|
1016
1128
|
try {
|
|
1017
|
-
for (
|
|
1018
|
-
var request =
|
|
1129
|
+
for (_iterator13.s(); !(_step13 = _iterator13.n()).done;) {
|
|
1130
|
+
var request = _step13.value;
|
|
1019
1131
|
primeBoundaryLm(request);
|
|
1020
1132
|
}
|
|
1021
1133
|
} catch (err) {
|
|
1022
|
-
|
|
1134
|
+
_iterator13.e(err);
|
|
1023
1135
|
} finally {
|
|
1024
|
-
|
|
1136
|
+
_iterator13.f();
|
|
1025
1137
|
}
|
|
1026
1138
|
var runtimeBySurface = new Map(canonicalMatched.map(function (candidate) {
|
|
1027
1139
|
return [candidate.word, candidate];
|
|
1028
1140
|
}));
|
|
1029
1141
|
var canonicalEvidence = new Map();
|
|
1030
1142
|
var firstTokenGroups = new Map();
|
|
1031
|
-
var
|
|
1032
|
-
|
|
1143
|
+
var _iterator14 = _createForOfIteratorHelper(canonicalMatched),
|
|
1144
|
+
_step14;
|
|
1033
1145
|
try {
|
|
1034
|
-
for (
|
|
1146
|
+
for (_iterator14.s(); !(_step14 = _iterator14.n()).done;) {
|
|
1035
1147
|
var _firstTokenGroups$get;
|
|
1036
|
-
var _candidate =
|
|
1148
|
+
var _candidate = _step14.value;
|
|
1037
1149
|
if (_candidate.canonicalTokenIds === null) {
|
|
1038
1150
|
continue;
|
|
1039
1151
|
}
|
|
@@ -1061,28 +1173,28 @@ export var predict = function predict(textBefore) {
|
|
|
1061
1173
|
firstTokenGroups.set(_candidate.contextKey, _group2);
|
|
1062
1174
|
}
|
|
1063
1175
|
} catch (err) {
|
|
1064
|
-
|
|
1176
|
+
_iterator14.e(err);
|
|
1065
1177
|
} finally {
|
|
1066
|
-
|
|
1178
|
+
_iterator14.f();
|
|
1067
1179
|
}
|
|
1068
|
-
var
|
|
1069
|
-
|
|
1180
|
+
var _iterator15 = _createForOfIteratorHelper(firstTokenGroups),
|
|
1181
|
+
_step15;
|
|
1070
1182
|
try {
|
|
1071
|
-
for (
|
|
1072
|
-
var
|
|
1073
|
-
_contextKey =
|
|
1074
|
-
_group3 =
|
|
1183
|
+
for (_iterator15.s(); !(_step15 = _iterator15.n()).done;) {
|
|
1184
|
+
var _step15$value = _slicedToArray(_step15.value, 2),
|
|
1185
|
+
_contextKey = _step15$value[0],
|
|
1186
|
+
_group3 = _step15$value[1];
|
|
1075
1187
|
var boundary = getBoundaryLmState(_contextKey);
|
|
1076
1188
|
if (!boundary) {
|
|
1077
1189
|
continue;
|
|
1078
1190
|
}
|
|
1079
1191
|
var maxLogit = -Infinity;
|
|
1080
|
-
var
|
|
1081
|
-
|
|
1192
|
+
var _iterator22 = _createForOfIteratorHelper(_group3),
|
|
1193
|
+
_step22;
|
|
1082
1194
|
try {
|
|
1083
|
-
for (
|
|
1195
|
+
for (_iterator22.s(); !(_step22 = _iterator22.n()).done;) {
|
|
1084
1196
|
var _candidate2$canonical;
|
|
1085
|
-
var _candidate2 =
|
|
1197
|
+
var _candidate2 = _step22.value;
|
|
1086
1198
|
var tokenId = (_candidate2$canonical = _candidate2.canonicalTokenIds) === null || _candidate2$canonical === void 0 ? void 0 : _candidate2$canonical[0];
|
|
1087
1199
|
var rawLogit = tokenId === undefined ? undefined : boundary.rawLogits[tokenId];
|
|
1088
1200
|
if (rawLogit !== undefined && Number.isFinite(rawLogit) && rawLogit > maxLogit) {
|
|
@@ -1090,19 +1202,19 @@ export var predict = function predict(textBefore) {
|
|
|
1090
1202
|
}
|
|
1091
1203
|
}
|
|
1092
1204
|
} catch (err) {
|
|
1093
|
-
|
|
1205
|
+
_iterator22.e(err);
|
|
1094
1206
|
} finally {
|
|
1095
|
-
|
|
1207
|
+
_iterator22.f();
|
|
1096
1208
|
}
|
|
1097
1209
|
if (!Number.isFinite(maxLogit)) {
|
|
1098
1210
|
continue;
|
|
1099
1211
|
}
|
|
1100
|
-
var
|
|
1101
|
-
|
|
1212
|
+
var _iterator23 = _createForOfIteratorHelper(_group3),
|
|
1213
|
+
_step23;
|
|
1102
1214
|
try {
|
|
1103
|
-
for (
|
|
1215
|
+
for (_iterator23.s(); !(_step23 = _iterator23.n()).done;) {
|
|
1104
1216
|
var _candidate3$canonical, _candidate3$canonical2, _candidate3$canonical3;
|
|
1105
|
-
var _candidate3 =
|
|
1217
|
+
var _candidate3 = _step23.value;
|
|
1106
1218
|
var _tokenId = (_candidate3$canonical = _candidate3.canonicalTokenIds) === null || _candidate3$canonical === void 0 ? void 0 : _candidate3$canonical[0];
|
|
1107
1219
|
var _rawLogit = _tokenId === undefined ? undefined : boundary.rawLogits[_tokenId];
|
|
1108
1220
|
if (_rawLogit === undefined || !Number.isFinite(_rawLogit)) {
|
|
@@ -1141,15 +1253,15 @@ export var predict = function predict(textBefore) {
|
|
|
1141
1253
|
});
|
|
1142
1254
|
}
|
|
1143
1255
|
} catch (err) {
|
|
1144
|
-
|
|
1256
|
+
_iterator23.e(err);
|
|
1145
1257
|
} finally {
|
|
1146
|
-
|
|
1258
|
+
_iterator23.f();
|
|
1147
1259
|
}
|
|
1148
1260
|
}
|
|
1149
1261
|
} catch (err) {
|
|
1150
|
-
|
|
1262
|
+
_iterator15.e(err);
|
|
1151
1263
|
} finally {
|
|
1152
|
-
|
|
1264
|
+
_iterator15.f();
|
|
1153
1265
|
}
|
|
1154
1266
|
var _rankCandidates = rankCandidates(scoringCandidates, contextVector, function (w) {
|
|
1155
1267
|
return getWordVector(w);
|
|
@@ -1170,12 +1282,12 @@ export var predict = function predict(textBefore) {
|
|
|
1170
1282
|
});
|
|
1171
1283
|
if (canonicalScoringSupported && progressiveEligible.length > 0) {
|
|
1172
1284
|
var byContext = new Map();
|
|
1173
|
-
var
|
|
1174
|
-
|
|
1285
|
+
var _iterator16 = _createForOfIteratorHelper(progressiveEligible),
|
|
1286
|
+
_step16;
|
|
1175
1287
|
try {
|
|
1176
|
-
for (
|
|
1288
|
+
for (_iterator16.s(); !(_step16 = _iterator16.n()).done;) {
|
|
1177
1289
|
var _byContext$get;
|
|
1178
|
-
var candidate =
|
|
1290
|
+
var candidate = _step16.value;
|
|
1179
1291
|
var runtime = runtimeBySurface.get(candidate.word);
|
|
1180
1292
|
if (!runtime || runtime.canonicalTokenIds === null) {
|
|
1181
1293
|
continue;
|
|
@@ -1188,25 +1300,25 @@ export var predict = function predict(textBefore) {
|
|
|
1188
1300
|
byContext.set(runtime.contextKey, group);
|
|
1189
1301
|
}
|
|
1190
1302
|
} catch (err) {
|
|
1191
|
-
|
|
1303
|
+
_iterator16.e(err);
|
|
1192
1304
|
} finally {
|
|
1193
|
-
|
|
1305
|
+
_iterator16.f();
|
|
1194
1306
|
}
|
|
1195
|
-
var
|
|
1196
|
-
|
|
1307
|
+
var _iterator17 = _createForOfIteratorHelper(byContext),
|
|
1308
|
+
_step17;
|
|
1197
1309
|
try {
|
|
1198
|
-
for (
|
|
1199
|
-
var
|
|
1200
|
-
contextKey =
|
|
1201
|
-
_group =
|
|
1310
|
+
for (_iterator17.s(); !(_step17 = _iterator17.n()).done;) {
|
|
1311
|
+
var _step17$value = _slicedToArray(_step17.value, 2),
|
|
1312
|
+
contextKey = _step17$value[0],
|
|
1313
|
+
_group = _step17$value[1];
|
|
1202
1314
|
requestProgressiveSurfaceScores({
|
|
1203
1315
|
familyKey: familyKey,
|
|
1204
1316
|
contextKey: contextKey,
|
|
1205
1317
|
prompt: _group[0].runtime.contextBeforeSurface,
|
|
1206
|
-
candidates: _group.map(function (
|
|
1318
|
+
candidates: _group.map(function (_ref6) {
|
|
1207
1319
|
var _runtime$canonicalTok;
|
|
1208
|
-
var runtime =
|
|
1209
|
-
rankHint =
|
|
1320
|
+
var runtime = _ref6.runtime,
|
|
1321
|
+
rankHint = _ref6.rankHint;
|
|
1210
1322
|
return {
|
|
1211
1323
|
surface: runtime.word,
|
|
1212
1324
|
tokenIds: (_runtime$canonicalTok = runtime.canonicalTokenIds) !== null && _runtime$canonicalTok !== void 0 ? _runtime$canonicalTok : [],
|
|
@@ -1216,9 +1328,9 @@ export var predict = function predict(textBefore) {
|
|
|
1216
1328
|
});
|
|
1217
1329
|
}
|
|
1218
1330
|
} catch (err) {
|
|
1219
|
-
|
|
1331
|
+
_iterator17.e(err);
|
|
1220
1332
|
} finally {
|
|
1221
|
-
|
|
1333
|
+
_iterator17.f();
|
|
1222
1334
|
}
|
|
1223
1335
|
}
|
|
1224
1336
|
|
|
@@ -1307,12 +1419,12 @@ export var predict = function predict(textBefore) {
|
|
|
1307
1419
|
var contextRequestedCount = new Map();
|
|
1308
1420
|
var bestTotalByContext = new Map();
|
|
1309
1421
|
var bestCandidateByContext = new Map();
|
|
1310
|
-
var
|
|
1311
|
-
|
|
1422
|
+
var _iterator18 = _createForOfIteratorHelper(ranked),
|
|
1423
|
+
_step18;
|
|
1312
1424
|
try {
|
|
1313
|
-
for (
|
|
1425
|
+
for (_iterator18.s(); !(_step18 = _iterator18.n()).done;) {
|
|
1314
1426
|
var _contextRequestedCoun2, _judged$total;
|
|
1315
|
-
var _candidate4 =
|
|
1427
|
+
var _candidate4 = _step18.value;
|
|
1316
1428
|
var _runtime = runtimeBySurface.get(_candidate4.word);
|
|
1317
1429
|
if (!_runtime || _runtime.canonicalTokenIds === null) {
|
|
1318
1430
|
continue;
|
|
@@ -1351,9 +1463,9 @@ export var predict = function predict(textBefore) {
|
|
|
1351
1463
|
* costs one lookup per space rather than a comparison against every member.
|
|
1352
1464
|
*/
|
|
1353
1465
|
} catch (err) {
|
|
1354
|
-
|
|
1466
|
+
_iterator18.e(err);
|
|
1355
1467
|
} finally {
|
|
1356
|
-
|
|
1468
|
+
_iterator18.f();
|
|
1357
1469
|
}
|
|
1358
1470
|
var extendsAPoolMember = function extendsAPoolMember(surface, pool) {
|
|
1359
1471
|
for (var space = surface.indexOf(' '); space !== -1; space = surface.indexOf(' ', space + 1)) {
|
|
@@ -1388,22 +1500,22 @@ export var predict = function predict(textBefore) {
|
|
|
1388
1500
|
// it continues, because the cap alone would leave it looking exactly as
|
|
1389
1501
|
// certain as its prefix while saying nothing about its own tail.
|
|
1390
1502
|
var underReadExtensions = new Set();
|
|
1391
|
-
var
|
|
1392
|
-
|
|
1503
|
+
var _iterator19 = _createForOfIteratorHelper(contextSurfaces),
|
|
1504
|
+
_step19;
|
|
1393
1505
|
try {
|
|
1394
|
-
for (
|
|
1395
|
-
var
|
|
1396
|
-
_contextKey2 =
|
|
1397
|
-
_surfaces =
|
|
1506
|
+
for (_iterator19.s(); !(_step19 = _iterator19.n()).done;) {
|
|
1507
|
+
var _step19$value = _slicedToArray(_step19.value, 2),
|
|
1508
|
+
_contextKey2 = _step19$value[0],
|
|
1509
|
+
_surfaces = _step19$value[1];
|
|
1398
1510
|
var pool = new Set(_surfaces);
|
|
1399
|
-
var
|
|
1511
|
+
var _iterator24 = _createForOfIteratorHelper(_toConsumableArray(_surfaces).sort(function (a, b) {
|
|
1400
1512
|
return a.length - b.length;
|
|
1401
1513
|
})),
|
|
1402
|
-
|
|
1514
|
+
_step24;
|
|
1403
1515
|
try {
|
|
1404
|
-
for (
|
|
1516
|
+
for (_iterator24.s(); !(_step24 = _iterator24.n()).done;) {
|
|
1405
1517
|
var _getProgressiveSurfac, _getProgressiveSurfac2, _runtimeBySurface$get8, _runtimeBySurface$get9;
|
|
1406
|
-
var surface =
|
|
1518
|
+
var surface = _step24.value;
|
|
1407
1519
|
var own = optimisticTotalByWord.get(surface);
|
|
1408
1520
|
if (own === undefined) {
|
|
1409
1521
|
continue;
|
|
@@ -1435,9 +1547,9 @@ export var predict = function predict(textBefore) {
|
|
|
1435
1547
|
}
|
|
1436
1548
|
}
|
|
1437
1549
|
} catch (err) {
|
|
1438
|
-
|
|
1550
|
+
_iterator24.e(err);
|
|
1439
1551
|
} finally {
|
|
1440
|
-
|
|
1552
|
+
_iterator24.f();
|
|
1441
1553
|
}
|
|
1442
1554
|
}
|
|
1443
1555
|
|
|
@@ -1450,9 +1562,9 @@ export var predict = function predict(textBefore) {
|
|
|
1450
1562
|
* depths.
|
|
1451
1563
|
*/
|
|
1452
1564
|
} catch (err) {
|
|
1453
|
-
|
|
1565
|
+
_iterator19.e(err);
|
|
1454
1566
|
} finally {
|
|
1455
|
-
|
|
1567
|
+
_iterator19.f();
|
|
1456
1568
|
}
|
|
1457
1569
|
var judgedEvidenceFor = function judgedEvidenceFor(candidate) {
|
|
1458
1570
|
return underReadExtensions.has(candidate.word) ? null : readJudgedEvidence(candidate);
|
|
@@ -1479,20 +1591,20 @@ export var predict = function predict(textBefore) {
|
|
|
1479
1591
|
// `contextTotals`, so how contested a context is still counts every scored
|
|
1480
1592
|
// candidate.
|
|
1481
1593
|
var logSumExpByContext = new Map();
|
|
1482
|
-
var
|
|
1483
|
-
|
|
1594
|
+
var _iterator20 = _createForOfIteratorHelper(contextSurfaces),
|
|
1595
|
+
_step20;
|
|
1484
1596
|
try {
|
|
1485
|
-
for (
|
|
1486
|
-
var
|
|
1487
|
-
_contextKey3 =
|
|
1488
|
-
_surfaces2 =
|
|
1597
|
+
for (_iterator20.s(); !(_step20 = _iterator20.n()).done;) {
|
|
1598
|
+
var _step20$value = _slicedToArray(_step20.value, 2),
|
|
1599
|
+
_contextKey3 = _step20$value[0],
|
|
1600
|
+
_surfaces2 = _step20$value[1];
|
|
1489
1601
|
var _pool = new Set(_surfaces2);
|
|
1490
1602
|
var minimalTotals = [];
|
|
1491
|
-
var
|
|
1492
|
-
|
|
1603
|
+
var _iterator25 = _createForOfIteratorHelper(_surfaces2),
|
|
1604
|
+
_step25;
|
|
1493
1605
|
try {
|
|
1494
|
-
for (
|
|
1495
|
-
var _surface =
|
|
1606
|
+
for (_iterator25.s(); !(_step25 = _iterator25.n()).done;) {
|
|
1607
|
+
var _surface = _step25.value;
|
|
1496
1608
|
var total = optimisticTotalByWord.get(_surface);
|
|
1497
1609
|
if (total !== undefined && !extendsAPoolMember(_surface, _pool)) {
|
|
1498
1610
|
minimalTotals.push(total);
|
|
@@ -1501,9 +1613,9 @@ export var predict = function predict(textBefore) {
|
|
|
1501
1613
|
// An extension is strictly longer than what it extends, so the shortest
|
|
1502
1614
|
// member of any non-empty pool is always minimal and this is never empty.
|
|
1503
1615
|
} catch (err) {
|
|
1504
|
-
|
|
1616
|
+
_iterator25.e(err);
|
|
1505
1617
|
} finally {
|
|
1506
|
-
|
|
1618
|
+
_iterator25.f();
|
|
1507
1619
|
}
|
|
1508
1620
|
logSumExpByContext.set(_contextKey3, logSumExp(minimalTotals));
|
|
1509
1621
|
}
|
|
@@ -1515,9 +1627,9 @@ export var predict = function predict(textBefore) {
|
|
|
1515
1627
|
* eventual posterior, or a verified total for the posterior itself.
|
|
1516
1628
|
*/
|
|
1517
1629
|
} catch (err) {
|
|
1518
|
-
|
|
1630
|
+
_iterator20.e(err);
|
|
1519
1631
|
} finally {
|
|
1520
|
-
|
|
1632
|
+
_iterator20.f();
|
|
1521
1633
|
}
|
|
1522
1634
|
var posteriorFor = function posteriorFor(candidate, total) {
|
|
1523
1635
|
var runtime = runtimeBySurface.get(candidate.word);
|
|
@@ -1647,9 +1759,9 @@ export var predict = function predict(textBefore) {
|
|
|
1647
1759
|
// The gate is the model's own confidence in the surface; the blended score
|
|
1648
1760
|
// only orders what has already cleared it, so a strong corpus prior can no
|
|
1649
1761
|
// longer carry a surface the model is unsure of onto the screen.
|
|
1650
|
-
.filter(function (
|
|
1651
|
-
var candidate =
|
|
1652
|
-
posterior =
|
|
1762
|
+
.filter(function (_ref7) {
|
|
1763
|
+
var candidate = _ref7.candidate,
|
|
1764
|
+
posterior = _ref7.posterior;
|
|
1653
1765
|
return posterior >= MIN_LM_POSTERIOR[candidate.termType];
|
|
1654
1766
|
});
|
|
1655
1767
|
/**
|
|
@@ -1677,15 +1789,15 @@ export var predict = function predict(textBefore) {
|
|
|
1677
1789
|
// cleared both. A candidate refused here stays in `ranked` and so still
|
|
1678
1790
|
// counts as competition below — promoting the runner-up in place of an
|
|
1679
1791
|
// implausible leader would show something worse, not something better.
|
|
1680
|
-
var plausible = gateCleared.filter(function (
|
|
1681
|
-
var candidate =
|
|
1792
|
+
var plausible = gateCleared.filter(function (_ref8) {
|
|
1793
|
+
var candidate = _ref8.candidate;
|
|
1682
1794
|
return isPlausibleSurface(candidate);
|
|
1683
1795
|
});
|
|
1684
1796
|
// Applied after the gate rather than folded into it, so the two populations
|
|
1685
1797
|
// stay separable: a surface refused here cleared its threshold and was
|
|
1686
1798
|
// refused for having had nothing to clear it against.
|
|
1687
|
-
var eligible = plausible.filter(function (
|
|
1688
|
-
var candidate =
|
|
1799
|
+
var eligible = plausible.filter(function (_ref9) {
|
|
1800
|
+
var candidate = _ref9.candidate;
|
|
1689
1801
|
return !canonicalLmSupported || scoredPoolSize(candidate) >= MIN_SCORED_POOL_SIZE || requestedPoolSize(candidate) <= 1;
|
|
1690
1802
|
}).sort(function (a, b) {
|
|
1691
1803
|
return b.score - a.score;
|
|
@@ -1851,9 +1963,9 @@ export var predict = function predict(textBefore) {
|
|
|
1851
1963
|
'below-posterior-gate': "posterior below ".concat(MIN_LM_POSTERIOR[((_posteriorLeader$cand = posteriorLeader === null || posteriorLeader === void 0 ? void 0 : posteriorLeader.candidate) !== null && _posteriorLeader$cand !== void 0 ? _posteriorLeader$cand : ranked[0]).termType], " (best ").concat(((_posteriorLeader$post = posteriorLeader === null || posteriorLeader === void 0 ? void 0 : posteriorLeader.posterior) !== null && _posteriorLeader$post !== void 0 ? _posteriorLeader$post : 0).toFixed(2), ")"),
|
|
1852
1964
|
'cold-competitor': 'competitor has no LM evidence yet',
|
|
1853
1965
|
'empty-completion': 'empty completion',
|
|
1854
|
-
'implausible-surface': "mean per-token log-probability below ".concat(MIN_MEAN_TOKEN_LOG_PROBABILITY, " (best ").concat(gateCleared.map(function (
|
|
1966
|
+
'implausible-surface': "mean per-token log-probability below ".concat(MIN_MEAN_TOKEN_LOG_PROBABILITY, " (best ").concat(gateCleared.map(function (_ref0) {
|
|
1855
1967
|
var _judgedEvidenceFor$me, _judgedEvidenceFor4;
|
|
1856
|
-
var candidate =
|
|
1968
|
+
var candidate = _ref0.candidate;
|
|
1857
1969
|
return (_judgedEvidenceFor$me = (_judgedEvidenceFor4 = judgedEvidenceFor(candidate)) === null || _judgedEvidenceFor4 === void 0 ? void 0 : _judgedEvidenceFor4.mean) !== null && _judgedEvidenceFor$me !== void 0 ? _judgedEvidenceFor$me : -Infinity;
|
|
1858
1970
|
}).reduce(function (best, mean) {
|
|
1859
1971
|
return Math.max(best, mean);
|
|
@@ -1941,10 +2053,10 @@ export var predict = function predict(textBefore) {
|
|
|
1941
2053
|
if (verbose && logitCount > 0 && lmLogits) {
|
|
1942
2054
|
var rawLmTop = Object.entries(lmLogits).sort(function (a, b) {
|
|
1943
2055
|
return b[1] - a[1];
|
|
1944
|
-
}).slice(0, 5).map(function (
|
|
1945
|
-
var
|
|
1946
|
-
word =
|
|
1947
|
-
score =
|
|
2056
|
+
}).slice(0, 5).map(function (_ref1) {
|
|
2057
|
+
var _ref10 = _slicedToArray(_ref1, 2),
|
|
2058
|
+
word = _ref10[0],
|
|
2059
|
+
score = _ref10[1];
|
|
1948
2060
|
return "".concat(word, ":").concat(score.toFixed(3));
|
|
1949
2061
|
}).join(', ');
|
|
1950
2062
|
ctcSection(' rawLM', "\uD83E\uDDE0 ".concat(rawLmTop));
|
|
@@ -1956,17 +2068,17 @@ export var predict = function predict(textBefore) {
|
|
|
1956
2068
|
bigram: 0,
|
|
1957
2069
|
phrase: 0
|
|
1958
2070
|
};
|
|
1959
|
-
var
|
|
1960
|
-
|
|
2071
|
+
var _iterator21 = _createForOfIteratorHelper(canonicalMatched),
|
|
2072
|
+
_step21;
|
|
1961
2073
|
try {
|
|
1962
|
-
for (
|
|
1963
|
-
var m =
|
|
2074
|
+
for (_iterator21.s(); !(_step21 = _iterator21.n()).done;) {
|
|
2075
|
+
var m = _step21.value;
|
|
1964
2076
|
genByType[m.node.termType] += 1;
|
|
1965
2077
|
}
|
|
1966
2078
|
} catch (err) {
|
|
1967
|
-
|
|
2079
|
+
_iterator21.e(err);
|
|
1968
2080
|
} finally {
|
|
1969
|
-
|
|
2081
|
+
_iterator21.f();
|
|
1970
2082
|
}
|
|
1971
2083
|
ctcSection('GENERATE', "matched ".concat(canonicalMatched.length, " \u2192 word:").concat(genByType.word, " bigram:").concat(genByType.bigram, " phrase:").concat(genByType.phrase).concat(canonicalLmSupported ? ' · display needs exact surface evidence' : ''));
|
|
1972
2084
|
|
|
@@ -2025,8 +2137,8 @@ export var predict = function predict(textBefore) {
|
|
|
2025
2137
|
return judgedPosterior(candidate) >= MIN_LM_POSTERIOR[termType];
|
|
2026
2138
|
});
|
|
2027
2139
|
var plausiblePassed = floorPassed.filter(isPlausibleSurface);
|
|
2028
|
-
return "".concat(termType, " m:").concat(genByType[termType], " r:").concat(typeRanked.length, " exact:").concat(exact.length, " abs:").concat(absolute.length, " stable:").concat(stabilized.length, " suffix:").concat(longEnough.length, " floor:").concat(floorPassed.length, " plausible:").concat(plausiblePassed.length, " eligible:").concat(eligible.filter(function (
|
|
2029
|
-
var candidate =
|
|
2140
|
+
return "".concat(termType, " m:").concat(genByType[termType], " r:").concat(typeRanked.length, " exact:").concat(exact.length, " abs:").concat(absolute.length, " stable:").concat(stabilized.length, " suffix:").concat(longEnough.length, " floor:").concat(floorPassed.length, " plausible:").concat(plausiblePassed.length, " eligible:").concat(eligible.filter(function (_ref11) {
|
|
2141
|
+
var candidate = _ref11.candidate;
|
|
2030
2142
|
return candidate.termType === termType;
|
|
2031
2143
|
}).length);
|
|
2032
2144
|
};
|
|
@@ -2035,11 +2147,11 @@ export var predict = function predict(textBefore) {
|
|
|
2035
2147
|
// One line per context: how many candidates share the normaliser, and how
|
|
2036
2148
|
// much of the mass the leader holds. A leader well under its threshold
|
|
2037
2149
|
// means the context is contested, which is the abstention we want.
|
|
2038
|
-
var contextLeaders = Array.from(bestCandidateByContext.entries()).slice(0, PHRASE_MAX_WORDS).map(function (
|
|
2150
|
+
var contextLeaders = Array.from(bestCandidateByContext.entries()).slice(0, PHRASE_MAX_WORDS).map(function (_ref12) {
|
|
2039
2151
|
var _contextTotals$get$le2, _contextTotals$get2;
|
|
2040
|
-
var
|
|
2041
|
-
contextKey =
|
|
2042
|
-
leader =
|
|
2152
|
+
var _ref13 = _slicedToArray(_ref12, 2),
|
|
2153
|
+
contextKey = _ref13[0],
|
|
2154
|
+
leader = _ref13[1];
|
|
2043
2155
|
var shortlistSize = (_contextTotals$get$le2 = (_contextTotals$get2 = contextTotals.get(contextKey)) === null || _contextTotals$get2 === void 0 ? void 0 : _contextTotals$get2.length) !== null && _contextTotals$get$le2 !== void 0 ? _contextTotals$get$le2 : 0;
|
|
2044
2156
|
var evidenceKind = hasExactEvidence(leader) ? 'exact' : 'upper';
|
|
2045
2157
|
return "".concat(contextKey.slice(0, 32), " \u2192 n=").concat(shortlistSize, " ").concat(leader.termType, ":\"").concat(leader.word, "\" ").concat(evidenceKind, " p=").concat(optimisticPosterior(leader).toFixed(3), "/").concat(MIN_LM_POSTERIOR[leader.termType]);
|
|
@@ -2269,7 +2381,7 @@ var normalizePhraseArtifact = function normalizePhraseArtifact(payload) {
|
|
|
2269
2381
|
return null;
|
|
2270
2382
|
};
|
|
2271
2383
|
export var loadVectorsAsync = /*#__PURE__*/function () {
|
|
2272
|
-
var
|
|
2384
|
+
var _ref14 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(options) {
|
|
2273
2385
|
var _options$isLocalLLM;
|
|
2274
2386
|
var isLocalLLM, surface, buffer, float32, wordIndexPayload, wordIndex, nWords, dim, _t;
|
|
2275
2387
|
return _regeneratorRuntime.wrap(function (_context) {
|
|
@@ -2344,7 +2456,7 @@ export var loadVectorsAsync = /*#__PURE__*/function () {
|
|
|
2344
2456
|
}, _callee, null, [[2, 5]]);
|
|
2345
2457
|
}));
|
|
2346
2458
|
return function loadVectorsAsync(_x) {
|
|
2347
|
-
return
|
|
2459
|
+
return _ref14.apply(this, arguments);
|
|
2348
2460
|
};
|
|
2349
2461
|
}();
|
|
2350
2462
|
export var initVectors = function initVectors(store) {
|
|
@@ -2368,7 +2480,7 @@ export var initVectors = function initVectors(store) {
|
|
|
2368
2480
|
* A promise that resolves once both fetches have settled
|
|
2369
2481
|
*/
|
|
2370
2482
|
export var loadPhraseArtifacts = /*#__PURE__*/function () {
|
|
2371
|
-
var
|
|
2483
|
+
var _ref15 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(options) {
|
|
2372
2484
|
var _options$isLocalLLM2;
|
|
2373
2485
|
var isLocalLLM, loadOne, _yield$Promise$allSet, _yield$Promise$allSet2, bigramsResult, phrasesResult, bigramCount, phraseCount;
|
|
2374
2486
|
return _regeneratorRuntime.wrap(function (_context3) {
|
|
@@ -2386,7 +2498,7 @@ export var loadPhraseArtifacts = /*#__PURE__*/function () {
|
|
|
2386
2498
|
isLocalLLM: isLocalLLM
|
|
2387
2499
|
});
|
|
2388
2500
|
loadOne = /*#__PURE__*/function () {
|
|
2389
|
-
var
|
|
2501
|
+
var _ref16 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(artifactName, termType, label) {
|
|
2390
2502
|
var payload, normalized;
|
|
2391
2503
|
return _regeneratorRuntime.wrap(function (_context2) {
|
|
2392
2504
|
while (1) switch (_context2.prev = _context2.next) {
|
|
@@ -2415,7 +2527,7 @@ export var loadPhraseArtifacts = /*#__PURE__*/function () {
|
|
|
2415
2527
|
}, _callee2);
|
|
2416
2528
|
}));
|
|
2417
2529
|
return function loadOne(_x3, _x4, _x5) {
|
|
2418
|
-
return
|
|
2530
|
+
return _ref16.apply(this, arguments);
|
|
2419
2531
|
};
|
|
2420
2532
|
}();
|
|
2421
2533
|
_context3.next = 2;
|
|
@@ -2457,7 +2569,7 @@ export var loadPhraseArtifacts = /*#__PURE__*/function () {
|
|
|
2457
2569
|
}, _callee3);
|
|
2458
2570
|
}));
|
|
2459
2571
|
return function loadPhraseArtifacts(_x2) {
|
|
2460
|
-
return
|
|
2572
|
+
return _ref15.apply(this, arguments);
|
|
2461
2573
|
};
|
|
2462
2574
|
}();
|
|
2463
2575
|
var vocabularyLoadPromise;
|
|
@@ -2523,10 +2635,10 @@ export var loadDefaultVocabulary = function loadDefaultVocabulary(options) {
|
|
|
2523
2635
|
_yield$Promise$all2 = _slicedToArray(_yield$Promise$all, 2);
|
|
2524
2636
|
vocabularyData = _yield$Promise$all2[0];
|
|
2525
2637
|
l3VocabularyData = _yield$Promise$all2[1];
|
|
2526
|
-
terms = Object.entries(vocabularyData.words).map(function (
|
|
2527
|
-
var
|
|
2528
|
-
word =
|
|
2529
|
-
stats =
|
|
2638
|
+
terms = Object.entries(vocabularyData.words).map(function (_ref18) {
|
|
2639
|
+
var _ref19 = _slicedToArray(_ref18, 2),
|
|
2640
|
+
word = _ref19[0],
|
|
2641
|
+
stats = _ref19[1];
|
|
2530
2642
|
return {
|
|
2531
2643
|
word: word,
|
|
2532
2644
|
freq: stats.freq,
|