From 26444e729104b9f9dfdf8f78fd4ceaad701fd211 Mon Sep 17 00:00:00 2001 From: Joshua Horton Date: Fri, 15 Aug 2025 14:04:52 -0500 Subject: [PATCH] fix(web): fix empty context handling --- .../worker-thread/src/main/correction/context-state.ts | 10 ++++------ .../src/main/correction/context-tokenization.ts | 2 +- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/web/src/engine/predictive-text/worker-thread/src/main/correction/context-state.ts b/web/src/engine/predictive-text/worker-thread/src/main/correction/context-state.ts index f9154a27f1..6d9ff73eea 100644 --- a/web/src/engine/predictive-text/worker-thread/src/main/correction/context-state.ts +++ b/web/src/engine/predictive-text/worker-thread/src/main/correction/context-state.ts @@ -181,13 +181,11 @@ export class ContextState { // Apply all transforms to the base context state const transformSequenceDistribution = tokenizeAndFilterDistribution(context, lexicalModel, transformDistribution); + const postContext = transformDistribution?.[0] ? applyTransform(transformDistribution[0].sample, context) : context; - if(transformDistribution?.[0]) { - context = applyTransform(transformDistribution[0].sample, context); - } // Note for future: the next line's pattern asserts that there is only one true tokenization. // We may eventually allow for multiple potential tokenizations (per epic-dict-breaker) - const tokenizedContext = determineModelTokenizer(lexicalModel)(context).left; + const tokenizedContext = determineModelTokenizer(lexicalModel)(postContext).left; if(tokenizedContext.length == 0) { tokenizedContext.push({text: ''}); } @@ -203,7 +201,7 @@ export class ContextState { } const resultTokenization = this.tokenization.transitionTo( - determineModelTokenizer(lexicalModel)(context).left, + tokenizedContext, alignmentResults, lexicalModel, transformSequenceDistribution @@ -242,7 +240,7 @@ export class ContextState { preservationTransform = preservationTransform ? buildMergedTransform(preservationTransform, primaryInput): primaryInput; } - const state = new ContextState(context, lexicalModel); + const state = new ContextState(postContext, lexicalModel); state.tokenization = resultTokenization; state.appliedInput = transformDistribution?.[0].sample; transition.finalize(state, transformDistribution, preservationTransform); diff --git a/web/src/engine/predictive-text/worker-thread/src/main/correction/context-tokenization.ts b/web/src/engine/predictive-text/worker-thread/src/main/correction/context-tokenization.ts index 3f903357b0..a6ad9757f5 100644 --- a/web/src/engine/predictive-text/worker-thread/src/main/correction/context-tokenization.ts +++ b/web/src/engine/predictive-text/worker-thread/src/main/correction/context-tokenization.ts @@ -317,7 +317,7 @@ export class ContextTokenization { * with the tokenization represented by the current instance. * @param alignment The alignment, as determined by a prior call to `computeAlignment`. * @param lexicalModel The active lexical model - * @param alignedTransformDistribution The tokenized version of the input Transform instance accounting + * @param alignedTransformDistribution The tokenized version of the input distribution accounting * for the difference between the context represented by this instance and that of `tokenizedContext`. * @returns */