@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
|
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.predict = exports.noteSuggestionAccepted = exports.loadVectorsAsync = exports.loadPhraseArtifacts = exports.loadDefaultVocabulary = exports.initVocabulary = exports.initVectors = exports.initPhrases = exports.initL3Vocabulary = exports.ingestDocumentPage = exports.incrementSessionFreq = exports.getPredictorStatus = exports.getLastPredictionDebug = void 0;
|
|
7
|
+
exports.predict = exports.noteSuggestionAccepted = exports.loadVectorsAsync = exports.loadPhraseArtifacts = exports.loadDefaultVocabulary = exports.inspectSessionBoosts = exports.initVocabulary = exports.initVectors = exports.initPhrases = exports.initL3Vocabulary = exports.ingestDocumentPage = exports.incrementSessionFreq = exports.getPredictorStatus = exports.getLastPredictionDebug = void 0;
|
|
8
8
|
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
9
9
|
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
10
10
|
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
@@ -38,7 +38,10 @@ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length)
|
|
|
38
38
|
* Falls back to cold mode (freq-only) when vectors not yet loaded.
|
|
39
39
|
*
|
|
40
40
|
* Session personalization (L1): words the user types are incrementally boosted
|
|
41
|
-
* via incrementSessionFreq(), called on word boundaries from the plugin
|
|
41
|
+
* via incrementSessionFreq(), called on word boundaries from the plugin, and
|
|
42
|
+
* words in ingested context text via ingestDocumentPage(). What the session has
|
|
43
|
+
* boosted is visible at any time from the console: `__atlCtcDebug__.session()`,
|
|
44
|
+
* or `__atlCtcDebug__.session('poll')` for one family — see inspectSessionBoosts.
|
|
42
45
|
*/
|
|
43
46
|
// ─── Constants ───────────────────────────────────────────────────────────────
|
|
44
47
|
|
|
@@ -360,6 +363,65 @@ var WeightedWordTrie = /*#__PURE__*/function () {
|
|
|
360
363
|
node.sessionFreq += 1;
|
|
361
364
|
return true;
|
|
362
365
|
}
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* Every word carrying a session boost, optionally limited to one prefix's
|
|
369
|
+
* subtree. Unlike `getCandidates` a word equal to the prefix is included,
|
|
370
|
+
* since the question here is what the session holds rather than what could
|
|
371
|
+
* still be typed.
|
|
372
|
+
*
|
|
373
|
+
* Walks the trie instead of reading an index, so nothing has to be kept in
|
|
374
|
+
* step on the write path for the sake of being able to ask.
|
|
375
|
+
*/
|
|
376
|
+
}, {
|
|
377
|
+
key: "collectSessionBoosted",
|
|
378
|
+
value: function collectSessionBoosted() {
|
|
379
|
+
var prefix = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
380
|
+
var node = this.root;
|
|
381
|
+
var _iterator5 = _createForOfIteratorHelper(prefix.toLowerCase()),
|
|
382
|
+
_step5;
|
|
383
|
+
try {
|
|
384
|
+
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
385
|
+
var char = _step5.value;
|
|
386
|
+
var next = node.children.get(char);
|
|
387
|
+
if (!next) {
|
|
388
|
+
return [];
|
|
389
|
+
}
|
|
390
|
+
node = next;
|
|
391
|
+
}
|
|
392
|
+
} catch (err) {
|
|
393
|
+
_iterator5.e(err);
|
|
394
|
+
} finally {
|
|
395
|
+
_iterator5.f();
|
|
396
|
+
}
|
|
397
|
+
var boosted = [];
|
|
398
|
+
var stack = [node];
|
|
399
|
+
while (stack.length > 0) {
|
|
400
|
+
var current = stack.pop();
|
|
401
|
+
if (!current) {
|
|
402
|
+
continue;
|
|
403
|
+
}
|
|
404
|
+
if (current.word !== null && current.sessionFreq > 0) {
|
|
405
|
+
boosted.push({
|
|
406
|
+
word: current.word,
|
|
407
|
+
node: current
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
var _iterator6 = _createForOfIteratorHelper(current.children.values()),
|
|
411
|
+
_step6;
|
|
412
|
+
try {
|
|
413
|
+
for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
|
|
414
|
+
var child = _step6.value;
|
|
415
|
+
stack.push(child);
|
|
416
|
+
}
|
|
417
|
+
} catch (err) {
|
|
418
|
+
_iterator6.e(err);
|
|
419
|
+
} finally {
|
|
420
|
+
_iterator6.f();
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
return boosted;
|
|
424
|
+
}
|
|
363
425
|
}]);
|
|
364
426
|
}(); // L1/L2 Trie (Session + Atlassian Domain)
|
|
365
427
|
var wordTrie = new WeightedWordTrie();
|
|
@@ -381,19 +443,19 @@ var phraseTrie = new WeightedWordTrie();
|
|
|
381
443
|
* expects a simple array of strings: ["about", "above", "actually", ...]
|
|
382
444
|
*/
|
|
383
445
|
var initL3Vocabulary = exports.initL3Vocabulary = function initL3Vocabulary(l3Words) {
|
|
384
|
-
var
|
|
385
|
-
|
|
446
|
+
var _iterator7 = _createForOfIteratorHelper(l3Words),
|
|
447
|
+
_step7;
|
|
386
448
|
try {
|
|
387
|
-
for (
|
|
388
|
-
var word =
|
|
449
|
+
for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
|
|
450
|
+
var word = _step7.value;
|
|
389
451
|
// Insert with a tiny baseline frequency so it mathematically
|
|
390
452
|
// loses to any domain word in Stage 1, but still scores above 0.
|
|
391
453
|
l3Trie.insert(word, L3_BASELINE_FREQ, 0, 0);
|
|
392
454
|
}
|
|
393
455
|
} catch (err) {
|
|
394
|
-
|
|
456
|
+
_iterator7.e(err);
|
|
395
457
|
} finally {
|
|
396
|
-
|
|
458
|
+
_iterator7.f();
|
|
397
459
|
}
|
|
398
460
|
recallGeneration++;
|
|
399
461
|
(0, _debugMode.ctcTag)('init', "L3 general English loaded: ".concat(l3Words.length, " words"));
|
|
@@ -474,20 +536,20 @@ var computeContextVectorLocal = function computeContextVectorLocal(textBefore) {
|
|
|
474
536
|
var tokens = tokenize(textBefore);
|
|
475
537
|
var words = tokens.slice(-CONTEXT_WORDS);
|
|
476
538
|
var vectors = [];
|
|
477
|
-
var
|
|
478
|
-
|
|
539
|
+
var _iterator8 = _createForOfIteratorHelper(words),
|
|
540
|
+
_step8;
|
|
479
541
|
try {
|
|
480
|
-
for (
|
|
481
|
-
var word =
|
|
542
|
+
for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
|
|
543
|
+
var word = _step8.value;
|
|
482
544
|
var _v = getWordVector(word);
|
|
483
545
|
if (_v) {
|
|
484
546
|
vectors.push(_v);
|
|
485
547
|
}
|
|
486
548
|
}
|
|
487
549
|
} catch (err) {
|
|
488
|
-
|
|
550
|
+
_iterator8.e(err);
|
|
489
551
|
} finally {
|
|
490
|
-
|
|
552
|
+
_iterator8.f();
|
|
491
553
|
}
|
|
492
554
|
if (vectors.length === 0) {
|
|
493
555
|
return null;
|
|
@@ -520,11 +582,11 @@ var getContextVectorForScoring = function getContextVectorForScoring(textBefore)
|
|
|
520
582
|
var tokenize = function tokenize(text) {
|
|
521
583
|
var tokens = [];
|
|
522
584
|
// eslint-disable-next-line @atlassian/perf-linting/no-expensive-split-replace
|
|
523
|
-
var
|
|
524
|
-
|
|
585
|
+
var _iterator9 = _createForOfIteratorHelper(text.toLowerCase().split(WHITESPACE_SPLIT_REGEX)),
|
|
586
|
+
_step9;
|
|
525
587
|
try {
|
|
526
|
-
for (
|
|
527
|
-
var raw =
|
|
588
|
+
for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
|
|
589
|
+
var raw = _step9.value;
|
|
528
590
|
// eslint-disable-next-line @atlassian/perf-linting/no-expensive-split-replace
|
|
529
591
|
var clean = raw.replace(PUNCTUATION_BOUNDARY_REGEX, '');
|
|
530
592
|
if (clean.length >= 2) {
|
|
@@ -532,9 +594,9 @@ var tokenize = function tokenize(text) {
|
|
|
532
594
|
}
|
|
533
595
|
}
|
|
534
596
|
} catch (err) {
|
|
535
|
-
|
|
597
|
+
_iterator9.e(err);
|
|
536
598
|
} finally {
|
|
537
|
-
|
|
599
|
+
_iterator9.f();
|
|
538
600
|
}
|
|
539
601
|
return tokens;
|
|
540
602
|
};
|
|
@@ -638,11 +700,11 @@ var getPhraseCandidates = function getPhraseCandidates(trimmed) {
|
|
|
638
700
|
window: windowPrefix,
|
|
639
701
|
matches: matches.length
|
|
640
702
|
});
|
|
641
|
-
var
|
|
642
|
-
|
|
703
|
+
var _iterator0 = _createForOfIteratorHelper(matches),
|
|
704
|
+
_step0;
|
|
643
705
|
try {
|
|
644
|
-
for (
|
|
645
|
-
var _match =
|
|
706
|
+
for (_iterator0.s(); !(_step0 = _iterator0.n()).done;) {
|
|
707
|
+
var _match = _step0.value;
|
|
646
708
|
if (seen.has(_match.word)) {
|
|
647
709
|
continue;
|
|
648
710
|
}
|
|
@@ -655,9 +717,9 @@ var getPhraseCandidates = function getPhraseCandidates(trimmed) {
|
|
|
655
717
|
});
|
|
656
718
|
}
|
|
657
719
|
} catch (err) {
|
|
658
|
-
|
|
720
|
+
_iterator0.e(err);
|
|
659
721
|
} finally {
|
|
660
|
-
|
|
722
|
+
_iterator0.f();
|
|
661
723
|
}
|
|
662
724
|
}
|
|
663
725
|
logPhrasePath();
|
|
@@ -702,17 +764,17 @@ var getLastPredictionDebug = exports.getLastPredictionDebug = function getLastPr
|
|
|
702
764
|
return lastPredictionDebug;
|
|
703
765
|
};
|
|
704
766
|
var initVocabulary = exports.initVocabulary = function initVocabulary(vocabulary) {
|
|
705
|
-
var
|
|
706
|
-
|
|
767
|
+
var _iterator1 = _createForOfIteratorHelper(vocabulary.terms),
|
|
768
|
+
_step1;
|
|
707
769
|
try {
|
|
708
|
-
for (
|
|
709
|
-
var term =
|
|
770
|
+
for (_iterator1.s(); !(_step1 = _iterator1.n()).done;) {
|
|
771
|
+
var term = _step1.value;
|
|
710
772
|
wordTrie.insert(term.word, term.freq, term.docFreq, term.authorFreq);
|
|
711
773
|
}
|
|
712
774
|
} catch (err) {
|
|
713
|
-
|
|
775
|
+
_iterator1.e(err);
|
|
714
776
|
} finally {
|
|
715
|
-
|
|
777
|
+
_iterator1.f();
|
|
716
778
|
}
|
|
717
779
|
isInitialized = true;
|
|
718
780
|
recallGeneration++;
|
|
@@ -779,23 +841,23 @@ var ingestDocumentPage = exports.ingestDocumentPage = function ingestDocumentPag
|
|
|
779
841
|
}
|
|
780
842
|
var words = tokenize(pageContent);
|
|
781
843
|
var validBoostedWords = new Set();
|
|
782
|
-
var
|
|
783
|
-
|
|
844
|
+
var _iterator10 = _createForOfIteratorHelper(words),
|
|
845
|
+
_step10;
|
|
784
846
|
try {
|
|
785
|
-
for (
|
|
786
|
-
var word =
|
|
847
|
+
for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
|
|
848
|
+
var word = _step10.value;
|
|
787
849
|
var didBoost = wordTrie.incrementSessionFreq(word);
|
|
788
850
|
if (didBoost) {
|
|
789
851
|
validBoostedWords.add(word);
|
|
790
852
|
}
|
|
791
853
|
}
|
|
792
854
|
} catch (err) {
|
|
793
|
-
|
|
855
|
+
_iterator10.e(err);
|
|
794
856
|
} finally {
|
|
795
|
-
|
|
857
|
+
_iterator10.f();
|
|
796
858
|
}
|
|
797
859
|
if ((0, _debugMode.isAutocompleteDebugEnabled)() && validBoostedWords.size > 0) {
|
|
798
|
-
(0, _debugMode.ctcTag)('init', "L1 session primed ".concat(validBoostedWords.size, " words from page"), _debugMode.CTC_STYLES.brand);
|
|
860
|
+
(0, _debugMode.ctcTag)('init', "L1 session primed ".concat(validBoostedWords.size, " words from page \xB7 __atlCtcDebug__.session() to inspect"), _debugMode.CTC_STYLES.brand);
|
|
799
861
|
if ((0, _debugMode.isAutocompleteDebugVerbose)()) {
|
|
800
862
|
// eslint-disable-next-line no-console
|
|
801
863
|
console.dir(Array.from(validBoostedWords).sort());
|
|
@@ -803,6 +865,56 @@ var ingestDocumentPage = exports.ingestDocumentPage = function ingestDocumentPag
|
|
|
803
865
|
}
|
|
804
866
|
};
|
|
805
867
|
|
|
868
|
+
/**
|
|
869
|
+
* How many boosted words `inspectSessionBoosts` lists.
|
|
870
|
+
*
|
|
871
|
+
* A page ingest can boost thousands, and a list that long is not read. The
|
|
872
|
+
* strongest boosts are the ones that change an ordering, and `boosted` still
|
|
873
|
+
* reports the full size, so the cap loses nothing but volume.
|
|
874
|
+
*/
|
|
875
|
+
var MAX_LISTED_SESSION_WORDS = 50;
|
|
876
|
+
/**
|
|
877
|
+
* Read the session's L1 boosts, optionally narrowed to a prefix.
|
|
878
|
+
*
|
|
879
|
+
* Installed as `__atlCtcDebug__.session()`, with `__atlCtcDebug__.session('poll')`
|
|
880
|
+
* to ask about one family. Returned rather than logged, so the console renders it
|
|
881
|
+
* as an inspectable object and a caller can assert on it.
|
|
882
|
+
*
|
|
883
|
+
* Only words the vocabulary already holds can carry a boost, because both writers
|
|
884
|
+
* go through `incrementSessionFreq` and it only finds existing nodes. An ingested
|
|
885
|
+
* word absent from the vocabulary is therefore missing from here and always will
|
|
886
|
+
* be.
|
|
887
|
+
*/
|
|
888
|
+
var inspectSessionBoosts = exports.inspectSessionBoosts = function inspectSessionBoosts(prefix) {
|
|
889
|
+
var boosted = wordTrie.collectSessionBoosted(prefix !== null && prefix !== void 0 ? prefix : '');
|
|
890
|
+
return _objectSpread(_objectSpread({
|
|
891
|
+
boosted: boosted.length,
|
|
892
|
+
limit: MAX_LISTED_SESSION_WORDS
|
|
893
|
+
}, prefix === undefined ? {} : {
|
|
894
|
+
prefix: prefix
|
|
895
|
+
}), {}, {
|
|
896
|
+
words: boosted.sort(function (a, b) {
|
|
897
|
+
return b.node.sessionFreq - a.node.sessionFreq || a.word.localeCompare(b.word, 'en', {
|
|
898
|
+
numeric: true,
|
|
899
|
+
sensitivity: 'base'
|
|
900
|
+
});
|
|
901
|
+
}).slice(0, MAX_LISTED_SESSION_WORDS).map(function (_ref) {
|
|
902
|
+
var node = _ref.node,
|
|
903
|
+
word = _ref.word;
|
|
904
|
+
return {
|
|
905
|
+
sessionFreq: node.sessionFreq,
|
|
906
|
+
sessionOnly: node.tenantFreq === 0,
|
|
907
|
+
surface: word,
|
|
908
|
+
tenantFreq: node.tenantFreq
|
|
909
|
+
};
|
|
910
|
+
})
|
|
911
|
+
});
|
|
912
|
+
};
|
|
913
|
+
|
|
914
|
+
// At module scope so the console answers before the first keystroke, which is
|
|
915
|
+
// when someone reaching for it usually asks.
|
|
916
|
+
(0, _debugMode.registerCtcSessionInspector)(inspectSessionBoosts);
|
|
917
|
+
|
|
806
918
|
/**
|
|
807
919
|
* Result of a prediction: the ghost tail to insert plus an immutable record of
|
|
808
920
|
* the evidence that authorized the UI commitment.
|
|
@@ -834,20 +946,20 @@ var computeCanonicalRecall = function computeCanonicalRecall(trimmed, currentWor
|
|
|
834
946
|
var existingWords = new Set(wordCandidates.map(function (c) {
|
|
835
947
|
return c.word;
|
|
836
948
|
}));
|
|
837
|
-
var
|
|
838
|
-
|
|
949
|
+
var _iterator11 = _createForOfIteratorHelper(l3Candidates),
|
|
950
|
+
_step11;
|
|
839
951
|
try {
|
|
840
|
-
for (
|
|
841
|
-
var l3c =
|
|
952
|
+
for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) {
|
|
953
|
+
var l3c = _step11.value;
|
|
842
954
|
if (wordCandidates.length >= MAX_CANDIDATES) break;
|
|
843
955
|
if (!existingWords.has(l3c.word)) {
|
|
844
956
|
wordCandidates.push(l3c);
|
|
845
957
|
}
|
|
846
958
|
}
|
|
847
959
|
} catch (err) {
|
|
848
|
-
|
|
960
|
+
_iterator11.e(err);
|
|
849
961
|
} finally {
|
|
850
|
-
|
|
962
|
+
_iterator11.f();
|
|
851
963
|
}
|
|
852
964
|
}
|
|
853
965
|
|
|
@@ -859,9 +971,9 @@ var computeCanonicalRecall = function computeCanonicalRecall(trimmed, currentWor
|
|
|
859
971
|
// Unify: a word completes the current partial token; a phrase completes its
|
|
860
972
|
// matched multi-word window. Track the prefix length per term so the ghost
|
|
861
973
|
// tail is sliced correctly regardless of term type.
|
|
862
|
-
var matched = [].concat((0, _toConsumableArray2.default)(wordCandidates.map(function (
|
|
863
|
-
var word =
|
|
864
|
-
node =
|
|
974
|
+
var matched = [].concat((0, _toConsumableArray2.default)(wordCandidates.map(function (_ref2) {
|
|
975
|
+
var word = _ref2.word,
|
|
976
|
+
node = _ref2.node;
|
|
865
977
|
return {
|
|
866
978
|
word: word,
|
|
867
979
|
node: node,
|
|
@@ -874,19 +986,19 @@ var computeCanonicalRecall = function computeCanonicalRecall(trimmed, currentWor
|
|
|
874
986
|
return _objectSpread(_objectSpread({}, candidate), (0, _canonicalLmScoring.deriveCanonicalCandidateContext)(trimmed, candidate.matchedPrefixLen, candidate.word, _slowLaneClient.getCanonicalSurfaceTokenIds, candidate.surfaceStart, positionCache));
|
|
875
987
|
});
|
|
876
988
|
var prefixLenByWord = new Map();
|
|
877
|
-
var
|
|
878
|
-
|
|
989
|
+
var _iterator12 = _createForOfIteratorHelper(canonicalMatched),
|
|
990
|
+
_step12;
|
|
879
991
|
try {
|
|
880
|
-
for (
|
|
881
|
-
var m =
|
|
992
|
+
for (_iterator12.s(); !(_step12 = _iterator12.n()).done;) {
|
|
993
|
+
var m = _step12.value;
|
|
882
994
|
if (!prefixLenByWord.has(m.word)) {
|
|
883
995
|
prefixLenByWord.set(m.word, m.matchedPrefixLen);
|
|
884
996
|
}
|
|
885
997
|
}
|
|
886
998
|
} catch (err) {
|
|
887
|
-
|
|
999
|
+
_iterator12.e(err);
|
|
888
1000
|
} finally {
|
|
889
|
-
|
|
1001
|
+
_iterator12.f();
|
|
890
1002
|
}
|
|
891
1003
|
return {
|
|
892
1004
|
canonicalMatched: canonicalMatched,
|
|
@@ -980,9 +1092,9 @@ var predict = exports.predict = function predict(textBefore) {
|
|
|
980
1092
|
var mode = contextVector ? 'warm' : 'cold';
|
|
981
1093
|
|
|
982
1094
|
// Build ScoringCandidate array from matched terms (words + phrases)
|
|
983
|
-
var scoringCandidates = canonicalMatched.map(function (
|
|
984
|
-
var word =
|
|
985
|
-
node =
|
|
1095
|
+
var scoringCandidates = canonicalMatched.map(function (_ref3) {
|
|
1096
|
+
var word = _ref3.word,
|
|
1097
|
+
node = _ref3.node;
|
|
986
1098
|
return {
|
|
987
1099
|
word: word,
|
|
988
1100
|
tenantFreq: node.tenantFreq,
|
|
@@ -1002,9 +1114,9 @@ var predict = exports.predict = function predict(textBefore) {
|
|
|
1002
1114
|
var currentWordSeparator = (_canonicalMatched$fin = canonicalMatched.find(function (candidate) {
|
|
1003
1115
|
return candidate.node.termType === 'word';
|
|
1004
1116
|
})) === null || _canonicalMatched$fin === void 0 ? void 0 : _canonicalMatched$fin.separatorKind;
|
|
1005
|
-
var prefixLmLogits = lmLogits && currentWordSeparator === 'whitespace' ? Object.fromEntries(Object.entries(lmLogits).filter(function (
|
|
1006
|
-
var
|
|
1007
|
-
word =
|
|
1117
|
+
var prefixLmLogits = lmLogits && currentWordSeparator === 'whitespace' ? Object.fromEntries(Object.entries(lmLogits).filter(function (_ref4) {
|
|
1118
|
+
var _ref5 = (0, _slicedToArray2.default)(_ref4, 1),
|
|
1119
|
+
word = _ref5[0];
|
|
1008
1120
|
return word.startsWith(prefix);
|
|
1009
1121
|
})) : null;
|
|
1010
1122
|
var canonicalScoringSupported = (0, _slowLaneClient.isCanonicalSurfaceScoringSupported)();
|
|
@@ -1015,29 +1127,29 @@ var predict = exports.predict = function predict(textBefore) {
|
|
|
1015
1127
|
}))).sort();
|
|
1016
1128
|
var familyKey = eligibleContextKeys.join("\x01");
|
|
1017
1129
|
var primeRequests = (0, _canonicalLmScoring.selectBoundaryPrimeRequests)(familyKey, canonicalMatched, PHRASE_MAX_WORDS);
|
|
1018
|
-
var
|
|
1019
|
-
|
|
1130
|
+
var _iterator13 = _createForOfIteratorHelper(primeRequests),
|
|
1131
|
+
_step13;
|
|
1020
1132
|
try {
|
|
1021
|
-
for (
|
|
1022
|
-
var request =
|
|
1133
|
+
for (_iterator13.s(); !(_step13 = _iterator13.n()).done;) {
|
|
1134
|
+
var request = _step13.value;
|
|
1023
1135
|
(0, _slowLaneClient.primeBoundaryLm)(request);
|
|
1024
1136
|
}
|
|
1025
1137
|
} catch (err) {
|
|
1026
|
-
|
|
1138
|
+
_iterator13.e(err);
|
|
1027
1139
|
} finally {
|
|
1028
|
-
|
|
1140
|
+
_iterator13.f();
|
|
1029
1141
|
}
|
|
1030
1142
|
var runtimeBySurface = new Map(canonicalMatched.map(function (candidate) {
|
|
1031
1143
|
return [candidate.word, candidate];
|
|
1032
1144
|
}));
|
|
1033
1145
|
var canonicalEvidence = new Map();
|
|
1034
1146
|
var firstTokenGroups = new Map();
|
|
1035
|
-
var
|
|
1036
|
-
|
|
1147
|
+
var _iterator14 = _createForOfIteratorHelper(canonicalMatched),
|
|
1148
|
+
_step14;
|
|
1037
1149
|
try {
|
|
1038
|
-
for (
|
|
1150
|
+
for (_iterator14.s(); !(_step14 = _iterator14.n()).done;) {
|
|
1039
1151
|
var _firstTokenGroups$get;
|
|
1040
|
-
var _candidate =
|
|
1152
|
+
var _candidate = _step14.value;
|
|
1041
1153
|
if (_candidate.canonicalTokenIds === null) {
|
|
1042
1154
|
continue;
|
|
1043
1155
|
}
|
|
@@ -1065,28 +1177,28 @@ var predict = exports.predict = function predict(textBefore) {
|
|
|
1065
1177
|
firstTokenGroups.set(_candidate.contextKey, _group2);
|
|
1066
1178
|
}
|
|
1067
1179
|
} catch (err) {
|
|
1068
|
-
|
|
1180
|
+
_iterator14.e(err);
|
|
1069
1181
|
} finally {
|
|
1070
|
-
|
|
1182
|
+
_iterator14.f();
|
|
1071
1183
|
}
|
|
1072
|
-
var
|
|
1073
|
-
|
|
1184
|
+
var _iterator15 = _createForOfIteratorHelper(firstTokenGroups),
|
|
1185
|
+
_step15;
|
|
1074
1186
|
try {
|
|
1075
|
-
for (
|
|
1076
|
-
var
|
|
1077
|
-
_contextKey =
|
|
1078
|
-
_group3 =
|
|
1187
|
+
for (_iterator15.s(); !(_step15 = _iterator15.n()).done;) {
|
|
1188
|
+
var _step15$value = (0, _slicedToArray2.default)(_step15.value, 2),
|
|
1189
|
+
_contextKey = _step15$value[0],
|
|
1190
|
+
_group3 = _step15$value[1];
|
|
1079
1191
|
var boundary = (0, _slowLaneClient.getBoundaryLmState)(_contextKey);
|
|
1080
1192
|
if (!boundary) {
|
|
1081
1193
|
continue;
|
|
1082
1194
|
}
|
|
1083
1195
|
var maxLogit = -Infinity;
|
|
1084
|
-
var
|
|
1085
|
-
|
|
1196
|
+
var _iterator22 = _createForOfIteratorHelper(_group3),
|
|
1197
|
+
_step22;
|
|
1086
1198
|
try {
|
|
1087
|
-
for (
|
|
1199
|
+
for (_iterator22.s(); !(_step22 = _iterator22.n()).done;) {
|
|
1088
1200
|
var _candidate2$canonical;
|
|
1089
|
-
var _candidate2 =
|
|
1201
|
+
var _candidate2 = _step22.value;
|
|
1090
1202
|
var tokenId = (_candidate2$canonical = _candidate2.canonicalTokenIds) === null || _candidate2$canonical === void 0 ? void 0 : _candidate2$canonical[0];
|
|
1091
1203
|
var rawLogit = tokenId === undefined ? undefined : boundary.rawLogits[tokenId];
|
|
1092
1204
|
if (rawLogit !== undefined && Number.isFinite(rawLogit) && rawLogit > maxLogit) {
|
|
@@ -1094,19 +1206,19 @@ var predict = exports.predict = function predict(textBefore) {
|
|
|
1094
1206
|
}
|
|
1095
1207
|
}
|
|
1096
1208
|
} catch (err) {
|
|
1097
|
-
|
|
1209
|
+
_iterator22.e(err);
|
|
1098
1210
|
} finally {
|
|
1099
|
-
|
|
1211
|
+
_iterator22.f();
|
|
1100
1212
|
}
|
|
1101
1213
|
if (!Number.isFinite(maxLogit)) {
|
|
1102
1214
|
continue;
|
|
1103
1215
|
}
|
|
1104
|
-
var
|
|
1105
|
-
|
|
1216
|
+
var _iterator23 = _createForOfIteratorHelper(_group3),
|
|
1217
|
+
_step23;
|
|
1106
1218
|
try {
|
|
1107
|
-
for (
|
|
1219
|
+
for (_iterator23.s(); !(_step23 = _iterator23.n()).done;) {
|
|
1108
1220
|
var _candidate3$canonical, _candidate3$canonical2, _candidate3$canonical3;
|
|
1109
|
-
var _candidate3 =
|
|
1221
|
+
var _candidate3 = _step23.value;
|
|
1110
1222
|
var _tokenId = (_candidate3$canonical = _candidate3.canonicalTokenIds) === null || _candidate3$canonical === void 0 ? void 0 : _candidate3$canonical[0];
|
|
1111
1223
|
var _rawLogit = _tokenId === undefined ? undefined : boundary.rawLogits[_tokenId];
|
|
1112
1224
|
if (_rawLogit === undefined || !Number.isFinite(_rawLogit)) {
|
|
@@ -1145,15 +1257,15 @@ var predict = exports.predict = function predict(textBefore) {
|
|
|
1145
1257
|
});
|
|
1146
1258
|
}
|
|
1147
1259
|
} catch (err) {
|
|
1148
|
-
|
|
1260
|
+
_iterator23.e(err);
|
|
1149
1261
|
} finally {
|
|
1150
|
-
|
|
1262
|
+
_iterator23.f();
|
|
1151
1263
|
}
|
|
1152
1264
|
}
|
|
1153
1265
|
} catch (err) {
|
|
1154
|
-
|
|
1266
|
+
_iterator15.e(err);
|
|
1155
1267
|
} finally {
|
|
1156
|
-
|
|
1268
|
+
_iterator15.f();
|
|
1157
1269
|
}
|
|
1158
1270
|
var _rankCandidates = (0, _scoringPipeline.rankCandidates)(scoringCandidates, contextVector, function (w) {
|
|
1159
1271
|
return getWordVector(w);
|
|
@@ -1174,12 +1286,12 @@ var predict = exports.predict = function predict(textBefore) {
|
|
|
1174
1286
|
});
|
|
1175
1287
|
if (canonicalScoringSupported && progressiveEligible.length > 0) {
|
|
1176
1288
|
var byContext = new Map();
|
|
1177
|
-
var
|
|
1178
|
-
|
|
1289
|
+
var _iterator16 = _createForOfIteratorHelper(progressiveEligible),
|
|
1290
|
+
_step16;
|
|
1179
1291
|
try {
|
|
1180
|
-
for (
|
|
1292
|
+
for (_iterator16.s(); !(_step16 = _iterator16.n()).done;) {
|
|
1181
1293
|
var _byContext$get;
|
|
1182
|
-
var candidate =
|
|
1294
|
+
var candidate = _step16.value;
|
|
1183
1295
|
var runtime = runtimeBySurface.get(candidate.word);
|
|
1184
1296
|
if (!runtime || runtime.canonicalTokenIds === null) {
|
|
1185
1297
|
continue;
|
|
@@ -1192,25 +1304,25 @@ var predict = exports.predict = function predict(textBefore) {
|
|
|
1192
1304
|
byContext.set(runtime.contextKey, group);
|
|
1193
1305
|
}
|
|
1194
1306
|
} catch (err) {
|
|
1195
|
-
|
|
1307
|
+
_iterator16.e(err);
|
|
1196
1308
|
} finally {
|
|
1197
|
-
|
|
1309
|
+
_iterator16.f();
|
|
1198
1310
|
}
|
|
1199
|
-
var
|
|
1200
|
-
|
|
1311
|
+
var _iterator17 = _createForOfIteratorHelper(byContext),
|
|
1312
|
+
_step17;
|
|
1201
1313
|
try {
|
|
1202
|
-
for (
|
|
1203
|
-
var
|
|
1204
|
-
contextKey =
|
|
1205
|
-
_group =
|
|
1314
|
+
for (_iterator17.s(); !(_step17 = _iterator17.n()).done;) {
|
|
1315
|
+
var _step17$value = (0, _slicedToArray2.default)(_step17.value, 2),
|
|
1316
|
+
contextKey = _step17$value[0],
|
|
1317
|
+
_group = _step17$value[1];
|
|
1206
1318
|
(0, _slowLaneClient.requestProgressiveSurfaceScores)({
|
|
1207
1319
|
familyKey: familyKey,
|
|
1208
1320
|
contextKey: contextKey,
|
|
1209
1321
|
prompt: _group[0].runtime.contextBeforeSurface,
|
|
1210
|
-
candidates: _group.map(function (
|
|
1322
|
+
candidates: _group.map(function (_ref6) {
|
|
1211
1323
|
var _runtime$canonicalTok;
|
|
1212
|
-
var runtime =
|
|
1213
|
-
rankHint =
|
|
1324
|
+
var runtime = _ref6.runtime,
|
|
1325
|
+
rankHint = _ref6.rankHint;
|
|
1214
1326
|
return {
|
|
1215
1327
|
surface: runtime.word,
|
|
1216
1328
|
tokenIds: (_runtime$canonicalTok = runtime.canonicalTokenIds) !== null && _runtime$canonicalTok !== void 0 ? _runtime$canonicalTok : [],
|
|
@@ -1220,9 +1332,9 @@ var predict = exports.predict = function predict(textBefore) {
|
|
|
1220
1332
|
});
|
|
1221
1333
|
}
|
|
1222
1334
|
} catch (err) {
|
|
1223
|
-
|
|
1335
|
+
_iterator17.e(err);
|
|
1224
1336
|
} finally {
|
|
1225
|
-
|
|
1337
|
+
_iterator17.f();
|
|
1226
1338
|
}
|
|
1227
1339
|
}
|
|
1228
1340
|
|
|
@@ -1311,12 +1423,12 @@ var predict = exports.predict = function predict(textBefore) {
|
|
|
1311
1423
|
var contextRequestedCount = new Map();
|
|
1312
1424
|
var bestTotalByContext = new Map();
|
|
1313
1425
|
var bestCandidateByContext = new Map();
|
|
1314
|
-
var
|
|
1315
|
-
|
|
1426
|
+
var _iterator18 = _createForOfIteratorHelper(ranked),
|
|
1427
|
+
_step18;
|
|
1316
1428
|
try {
|
|
1317
|
-
for (
|
|
1429
|
+
for (_iterator18.s(); !(_step18 = _iterator18.n()).done;) {
|
|
1318
1430
|
var _contextRequestedCoun2, _judged$total;
|
|
1319
|
-
var _candidate4 =
|
|
1431
|
+
var _candidate4 = _step18.value;
|
|
1320
1432
|
var _runtime = runtimeBySurface.get(_candidate4.word);
|
|
1321
1433
|
if (!_runtime || _runtime.canonicalTokenIds === null) {
|
|
1322
1434
|
continue;
|
|
@@ -1355,9 +1467,9 @@ var predict = exports.predict = function predict(textBefore) {
|
|
|
1355
1467
|
* costs one lookup per space rather than a comparison against every member.
|
|
1356
1468
|
*/
|
|
1357
1469
|
} catch (err) {
|
|
1358
|
-
|
|
1470
|
+
_iterator18.e(err);
|
|
1359
1471
|
} finally {
|
|
1360
|
-
|
|
1472
|
+
_iterator18.f();
|
|
1361
1473
|
}
|
|
1362
1474
|
var extendsAPoolMember = function extendsAPoolMember(surface, pool) {
|
|
1363
1475
|
for (var space = surface.indexOf(' '); space !== -1; space = surface.indexOf(' ', space + 1)) {
|
|
@@ -1392,22 +1504,22 @@ var predict = exports.predict = function predict(textBefore) {
|
|
|
1392
1504
|
// it continues, because the cap alone would leave it looking exactly as
|
|
1393
1505
|
// certain as its prefix while saying nothing about its own tail.
|
|
1394
1506
|
var underReadExtensions = new Set();
|
|
1395
|
-
var
|
|
1396
|
-
|
|
1507
|
+
var _iterator19 = _createForOfIteratorHelper(contextSurfaces),
|
|
1508
|
+
_step19;
|
|
1397
1509
|
try {
|
|
1398
|
-
for (
|
|
1399
|
-
var
|
|
1400
|
-
_contextKey2 =
|
|
1401
|
-
_surfaces =
|
|
1510
|
+
for (_iterator19.s(); !(_step19 = _iterator19.n()).done;) {
|
|
1511
|
+
var _step19$value = (0, _slicedToArray2.default)(_step19.value, 2),
|
|
1512
|
+
_contextKey2 = _step19$value[0],
|
|
1513
|
+
_surfaces = _step19$value[1];
|
|
1402
1514
|
var pool = new Set(_surfaces);
|
|
1403
|
-
var
|
|
1515
|
+
var _iterator24 = _createForOfIteratorHelper((0, _toConsumableArray2.default)(_surfaces).sort(function (a, b) {
|
|
1404
1516
|
return a.length - b.length;
|
|
1405
1517
|
})),
|
|
1406
|
-
|
|
1518
|
+
_step24;
|
|
1407
1519
|
try {
|
|
1408
|
-
for (
|
|
1520
|
+
for (_iterator24.s(); !(_step24 = _iterator24.n()).done;) {
|
|
1409
1521
|
var _getProgressiveSurfac, _getProgressiveSurfac2, _runtimeBySurface$get8, _runtimeBySurface$get9;
|
|
1410
|
-
var surface =
|
|
1522
|
+
var surface = _step24.value;
|
|
1411
1523
|
var own = optimisticTotalByWord.get(surface);
|
|
1412
1524
|
if (own === undefined) {
|
|
1413
1525
|
continue;
|
|
@@ -1439,9 +1551,9 @@ var predict = exports.predict = function predict(textBefore) {
|
|
|
1439
1551
|
}
|
|
1440
1552
|
}
|
|
1441
1553
|
} catch (err) {
|
|
1442
|
-
|
|
1554
|
+
_iterator24.e(err);
|
|
1443
1555
|
} finally {
|
|
1444
|
-
|
|
1556
|
+
_iterator24.f();
|
|
1445
1557
|
}
|
|
1446
1558
|
}
|
|
1447
1559
|
|
|
@@ -1454,9 +1566,9 @@ var predict = exports.predict = function predict(textBefore) {
|
|
|
1454
1566
|
* depths.
|
|
1455
1567
|
*/
|
|
1456
1568
|
} catch (err) {
|
|
1457
|
-
|
|
1569
|
+
_iterator19.e(err);
|
|
1458
1570
|
} finally {
|
|
1459
|
-
|
|
1571
|
+
_iterator19.f();
|
|
1460
1572
|
}
|
|
1461
1573
|
var judgedEvidenceFor = function judgedEvidenceFor(candidate) {
|
|
1462
1574
|
return underReadExtensions.has(candidate.word) ? null : readJudgedEvidence(candidate);
|
|
@@ -1483,20 +1595,20 @@ var predict = exports.predict = function predict(textBefore) {
|
|
|
1483
1595
|
// `contextTotals`, so how contested a context is still counts every scored
|
|
1484
1596
|
// candidate.
|
|
1485
1597
|
var logSumExpByContext = new Map();
|
|
1486
|
-
var
|
|
1487
|
-
|
|
1598
|
+
var _iterator20 = _createForOfIteratorHelper(contextSurfaces),
|
|
1599
|
+
_step20;
|
|
1488
1600
|
try {
|
|
1489
|
-
for (
|
|
1490
|
-
var
|
|
1491
|
-
_contextKey3 =
|
|
1492
|
-
_surfaces2 =
|
|
1601
|
+
for (_iterator20.s(); !(_step20 = _iterator20.n()).done;) {
|
|
1602
|
+
var _step20$value = (0, _slicedToArray2.default)(_step20.value, 2),
|
|
1603
|
+
_contextKey3 = _step20$value[0],
|
|
1604
|
+
_surfaces2 = _step20$value[1];
|
|
1493
1605
|
var _pool = new Set(_surfaces2);
|
|
1494
1606
|
var minimalTotals = [];
|
|
1495
|
-
var
|
|
1496
|
-
|
|
1607
|
+
var _iterator25 = _createForOfIteratorHelper(_surfaces2),
|
|
1608
|
+
_step25;
|
|
1497
1609
|
try {
|
|
1498
|
-
for (
|
|
1499
|
-
var _surface =
|
|
1610
|
+
for (_iterator25.s(); !(_step25 = _iterator25.n()).done;) {
|
|
1611
|
+
var _surface = _step25.value;
|
|
1500
1612
|
var total = optimisticTotalByWord.get(_surface);
|
|
1501
1613
|
if (total !== undefined && !extendsAPoolMember(_surface, _pool)) {
|
|
1502
1614
|
minimalTotals.push(total);
|
|
@@ -1505,9 +1617,9 @@ var predict = exports.predict = function predict(textBefore) {
|
|
|
1505
1617
|
// An extension is strictly longer than what it extends, so the shortest
|
|
1506
1618
|
// member of any non-empty pool is always minimal and this is never empty.
|
|
1507
1619
|
} catch (err) {
|
|
1508
|
-
|
|
1620
|
+
_iterator25.e(err);
|
|
1509
1621
|
} finally {
|
|
1510
|
-
|
|
1622
|
+
_iterator25.f();
|
|
1511
1623
|
}
|
|
1512
1624
|
logSumExpByContext.set(_contextKey3, (0, _canonicalLmScoring.logSumExp)(minimalTotals));
|
|
1513
1625
|
}
|
|
@@ -1519,9 +1631,9 @@ var predict = exports.predict = function predict(textBefore) {
|
|
|
1519
1631
|
* eventual posterior, or a verified total for the posterior itself.
|
|
1520
1632
|
*/
|
|
1521
1633
|
} catch (err) {
|
|
1522
|
-
|
|
1634
|
+
_iterator20.e(err);
|
|
1523
1635
|
} finally {
|
|
1524
|
-
|
|
1636
|
+
_iterator20.f();
|
|
1525
1637
|
}
|
|
1526
1638
|
var posteriorFor = function posteriorFor(candidate, total) {
|
|
1527
1639
|
var runtime = runtimeBySurface.get(candidate.word);
|
|
@@ -1651,9 +1763,9 @@ var predict = exports.predict = function predict(textBefore) {
|
|
|
1651
1763
|
// The gate is the model's own confidence in the surface; the blended score
|
|
1652
1764
|
// only orders what has already cleared it, so a strong corpus prior can no
|
|
1653
1765
|
// longer carry a surface the model is unsure of onto the screen.
|
|
1654
|
-
.filter(function (
|
|
1655
|
-
var candidate =
|
|
1656
|
-
posterior =
|
|
1766
|
+
.filter(function (_ref7) {
|
|
1767
|
+
var candidate = _ref7.candidate,
|
|
1768
|
+
posterior = _ref7.posterior;
|
|
1657
1769
|
return posterior >= MIN_LM_POSTERIOR[candidate.termType];
|
|
1658
1770
|
});
|
|
1659
1771
|
/**
|
|
@@ -1681,15 +1793,15 @@ var predict = exports.predict = function predict(textBefore) {
|
|
|
1681
1793
|
// cleared both. A candidate refused here stays in `ranked` and so still
|
|
1682
1794
|
// counts as competition below — promoting the runner-up in place of an
|
|
1683
1795
|
// implausible leader would show something worse, not something better.
|
|
1684
|
-
var plausible = gateCleared.filter(function (
|
|
1685
|
-
var candidate =
|
|
1796
|
+
var plausible = gateCleared.filter(function (_ref8) {
|
|
1797
|
+
var candidate = _ref8.candidate;
|
|
1686
1798
|
return isPlausibleSurface(candidate);
|
|
1687
1799
|
});
|
|
1688
1800
|
// Applied after the gate rather than folded into it, so the two populations
|
|
1689
1801
|
// stay separable: a surface refused here cleared its threshold and was
|
|
1690
1802
|
// refused for having had nothing to clear it against.
|
|
1691
|
-
var eligible = plausible.filter(function (
|
|
1692
|
-
var candidate =
|
|
1803
|
+
var eligible = plausible.filter(function (_ref9) {
|
|
1804
|
+
var candidate = _ref9.candidate;
|
|
1693
1805
|
return !canonicalLmSupported || scoredPoolSize(candidate) >= MIN_SCORED_POOL_SIZE || requestedPoolSize(candidate) <= 1;
|
|
1694
1806
|
}).sort(function (a, b) {
|
|
1695
1807
|
return b.score - a.score;
|
|
@@ -1855,9 +1967,9 @@ var predict = exports.predict = function predict(textBefore) {
|
|
|
1855
1967
|
'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), ")"),
|
|
1856
1968
|
'cold-competitor': 'competitor has no LM evidence yet',
|
|
1857
1969
|
'empty-completion': 'empty completion',
|
|
1858
|
-
'implausible-surface': "mean per-token log-probability below ".concat(MIN_MEAN_TOKEN_LOG_PROBABILITY, " (best ").concat(gateCleared.map(function (
|
|
1970
|
+
'implausible-surface': "mean per-token log-probability below ".concat(MIN_MEAN_TOKEN_LOG_PROBABILITY, " (best ").concat(gateCleared.map(function (_ref0) {
|
|
1859
1971
|
var _judgedEvidenceFor$me, _judgedEvidenceFor4;
|
|
1860
|
-
var candidate =
|
|
1972
|
+
var candidate = _ref0.candidate;
|
|
1861
1973
|
return (_judgedEvidenceFor$me = (_judgedEvidenceFor4 = judgedEvidenceFor(candidate)) === null || _judgedEvidenceFor4 === void 0 ? void 0 : _judgedEvidenceFor4.mean) !== null && _judgedEvidenceFor$me !== void 0 ? _judgedEvidenceFor$me : -Infinity;
|
|
1862
1974
|
}).reduce(function (best, mean) {
|
|
1863
1975
|
return Math.max(best, mean);
|
|
@@ -1945,10 +2057,10 @@ var predict = exports.predict = function predict(textBefore) {
|
|
|
1945
2057
|
if (verbose && logitCount > 0 && lmLogits) {
|
|
1946
2058
|
var rawLmTop = Object.entries(lmLogits).sort(function (a, b) {
|
|
1947
2059
|
return b[1] - a[1];
|
|
1948
|
-
}).slice(0, 5).map(function (
|
|
1949
|
-
var
|
|
1950
|
-
word =
|
|
1951
|
-
score =
|
|
2060
|
+
}).slice(0, 5).map(function (_ref1) {
|
|
2061
|
+
var _ref10 = (0, _slicedToArray2.default)(_ref1, 2),
|
|
2062
|
+
word = _ref10[0],
|
|
2063
|
+
score = _ref10[1];
|
|
1952
2064
|
return "".concat(word, ":").concat(score.toFixed(3));
|
|
1953
2065
|
}).join(', ');
|
|
1954
2066
|
(0, _debugMode.ctcSection)(' rawLM', "\uD83E\uDDE0 ".concat(rawLmTop));
|
|
@@ -1960,17 +2072,17 @@ var predict = exports.predict = function predict(textBefore) {
|
|
|
1960
2072
|
bigram: 0,
|
|
1961
2073
|
phrase: 0
|
|
1962
2074
|
};
|
|
1963
|
-
var
|
|
1964
|
-
|
|
2075
|
+
var _iterator21 = _createForOfIteratorHelper(canonicalMatched),
|
|
2076
|
+
_step21;
|
|
1965
2077
|
try {
|
|
1966
|
-
for (
|
|
1967
|
-
var m =
|
|
2078
|
+
for (_iterator21.s(); !(_step21 = _iterator21.n()).done;) {
|
|
2079
|
+
var m = _step21.value;
|
|
1968
2080
|
genByType[m.node.termType] += 1;
|
|
1969
2081
|
}
|
|
1970
2082
|
} catch (err) {
|
|
1971
|
-
|
|
2083
|
+
_iterator21.e(err);
|
|
1972
2084
|
} finally {
|
|
1973
|
-
|
|
2085
|
+
_iterator21.f();
|
|
1974
2086
|
}
|
|
1975
2087
|
(0, _debugMode.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' : ''));
|
|
1976
2088
|
|
|
@@ -2029,8 +2141,8 @@ var predict = exports.predict = function predict(textBefore) {
|
|
|
2029
2141
|
return judgedPosterior(candidate) >= MIN_LM_POSTERIOR[termType];
|
|
2030
2142
|
});
|
|
2031
2143
|
var plausiblePassed = floorPassed.filter(isPlausibleSurface);
|
|
2032
|
-
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 (
|
|
2033
|
-
var candidate =
|
|
2144
|
+
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) {
|
|
2145
|
+
var candidate = _ref11.candidate;
|
|
2034
2146
|
return candidate.termType === termType;
|
|
2035
2147
|
}).length);
|
|
2036
2148
|
};
|
|
@@ -2039,11 +2151,11 @@ var predict = exports.predict = function predict(textBefore) {
|
|
|
2039
2151
|
// One line per context: how many candidates share the normaliser, and how
|
|
2040
2152
|
// much of the mass the leader holds. A leader well under its threshold
|
|
2041
2153
|
// means the context is contested, which is the abstention we want.
|
|
2042
|
-
var contextLeaders = Array.from(bestCandidateByContext.entries()).slice(0, PHRASE_MAX_WORDS).map(function (
|
|
2154
|
+
var contextLeaders = Array.from(bestCandidateByContext.entries()).slice(0, PHRASE_MAX_WORDS).map(function (_ref12) {
|
|
2043
2155
|
var _contextTotals$get$le2, _contextTotals$get2;
|
|
2044
|
-
var
|
|
2045
|
-
contextKey =
|
|
2046
|
-
leader =
|
|
2156
|
+
var _ref13 = (0, _slicedToArray2.default)(_ref12, 2),
|
|
2157
|
+
contextKey = _ref13[0],
|
|
2158
|
+
leader = _ref13[1];
|
|
2047
2159
|
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;
|
|
2048
2160
|
var evidenceKind = hasExactEvidence(leader) ? 'exact' : 'upper';
|
|
2049
2161
|
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]);
|
|
@@ -2273,7 +2385,7 @@ var normalizePhraseArtifact = function normalizePhraseArtifact(payload) {
|
|
|
2273
2385
|
return null;
|
|
2274
2386
|
};
|
|
2275
2387
|
var loadVectorsAsync = exports.loadVectorsAsync = /*#__PURE__*/function () {
|
|
2276
|
-
var
|
|
2388
|
+
var _ref14 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(options) {
|
|
2277
2389
|
var _options$isLocalLLM;
|
|
2278
2390
|
var isLocalLLM, surface, buffer, float32, wordIndexPayload, wordIndex, nWords, dim, _t;
|
|
2279
2391
|
return _regenerator.default.wrap(function (_context) {
|
|
@@ -2348,7 +2460,7 @@ var loadVectorsAsync = exports.loadVectorsAsync = /*#__PURE__*/function () {
|
|
|
2348
2460
|
}, _callee, null, [[2, 5]]);
|
|
2349
2461
|
}));
|
|
2350
2462
|
return function loadVectorsAsync(_x) {
|
|
2351
|
-
return
|
|
2463
|
+
return _ref14.apply(this, arguments);
|
|
2352
2464
|
};
|
|
2353
2465
|
}();
|
|
2354
2466
|
var initVectors = exports.initVectors = function initVectors(store) {
|
|
@@ -2372,7 +2484,7 @@ var initVectors = exports.initVectors = function initVectors(store) {
|
|
|
2372
2484
|
* A promise that resolves once both fetches have settled
|
|
2373
2485
|
*/
|
|
2374
2486
|
var loadPhraseArtifacts = exports.loadPhraseArtifacts = /*#__PURE__*/function () {
|
|
2375
|
-
var
|
|
2487
|
+
var _ref15 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(options) {
|
|
2376
2488
|
var _options$isLocalLLM2;
|
|
2377
2489
|
var isLocalLLM, loadOne, _yield$Promise$allSet, _yield$Promise$allSet2, bigramsResult, phrasesResult, bigramCount, phraseCount;
|
|
2378
2490
|
return _regenerator.default.wrap(function (_context3) {
|
|
@@ -2390,7 +2502,7 @@ var loadPhraseArtifacts = exports.loadPhraseArtifacts = /*#__PURE__*/function ()
|
|
|
2390
2502
|
isLocalLLM: isLocalLLM
|
|
2391
2503
|
});
|
|
2392
2504
|
loadOne = /*#__PURE__*/function () {
|
|
2393
|
-
var
|
|
2505
|
+
var _ref16 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(artifactName, termType, label) {
|
|
2394
2506
|
var payload, normalized;
|
|
2395
2507
|
return _regenerator.default.wrap(function (_context2) {
|
|
2396
2508
|
while (1) switch (_context2.prev = _context2.next) {
|
|
@@ -2419,7 +2531,7 @@ var loadPhraseArtifacts = exports.loadPhraseArtifacts = /*#__PURE__*/function ()
|
|
|
2419
2531
|
}, _callee2);
|
|
2420
2532
|
}));
|
|
2421
2533
|
return function loadOne(_x3, _x4, _x5) {
|
|
2422
|
-
return
|
|
2534
|
+
return _ref16.apply(this, arguments);
|
|
2423
2535
|
};
|
|
2424
2536
|
}();
|
|
2425
2537
|
_context3.next = 2;
|
|
@@ -2461,7 +2573,7 @@ var loadPhraseArtifacts = exports.loadPhraseArtifacts = /*#__PURE__*/function ()
|
|
|
2461
2573
|
}, _callee3);
|
|
2462
2574
|
}));
|
|
2463
2575
|
return function loadPhraseArtifacts(_x2) {
|
|
2464
|
-
return
|
|
2576
|
+
return _ref15.apply(this, arguments);
|
|
2465
2577
|
};
|
|
2466
2578
|
}();
|
|
2467
2579
|
var vocabularyLoadPromise;
|
|
@@ -2527,10 +2639,10 @@ var loadDefaultVocabulary = exports.loadDefaultVocabulary = function loadDefault
|
|
|
2527
2639
|
_yield$Promise$all2 = (0, _slicedToArray2.default)(_yield$Promise$all, 2);
|
|
2528
2640
|
vocabularyData = _yield$Promise$all2[0];
|
|
2529
2641
|
l3VocabularyData = _yield$Promise$all2[1];
|
|
2530
|
-
terms = Object.entries(vocabularyData.words).map(function (
|
|
2531
|
-
var
|
|
2532
|
-
word =
|
|
2533
|
-
stats =
|
|
2642
|
+
terms = Object.entries(vocabularyData.words).map(function (_ref18) {
|
|
2643
|
+
var _ref19 = (0, _slicedToArray2.default)(_ref18, 2),
|
|
2644
|
+
word = _ref19[0],
|
|
2645
|
+
stats = _ref19[1];
|
|
2534
2646
|
return {
|
|
2535
2647
|
word: word,
|
|
2536
2648
|
freq: stats.freq,
|