Skip to content

Class: InputLookupTokenPredictor

Defined in: evaluator/LlamaContext/tokenPredictors/InputLookupTokenPredictor.ts:22

Attempts to find the last few generated tokens in the input (prompt) tokens to predict the next tokens.

This is useful in input-grounded tasks (when the model frequently repeats some of the input tokens in the output, such as in text summarization or modifying code).

This works in all completion classes, including LlamaChatSession, LlamaChat, and LlamaCompletion.

Based on https://github.com/apoorvumang/prompt-lookup-decoding.

See

Using Token Predictors: Input Lookup Token Predictor

Extends

Constructors

new InputLookupTokenPredictor()

ts
new InputLookupTokenPredictor(options: {
  patternLength: {
     min: number;
     max: number;
    };
  predictionLength: {
     min: number;
     max: number;
    };
 }): InputLookupTokenPredictor

Defined in: evaluator/LlamaContext/tokenPredictors/InputLookupTokenPredictor.ts:33

Parameters

ParameterTypeDescription
options{ patternLength: { min: number; max: number; }; predictionLength: { min: number; max: number; }; }-
options.patternLength?{ min: number; max: number; }-
options.patternLength.min?numberMin pattern length to look for in the input tokens. Defaults to 1.
options.patternLength.max?numberMax pattern length to look for in the input tokens. Set to 0 to disable the max pattern size. Defaults to 0.
options.predictionLength?{ min: number; max: number; }-
options.predictionLength.min?numberMinimum number of tokens to predict. Defaults to 1.
options.predictionLength.max?numberMaximum number of tokens to predict. Defaults to 3.

Returns

InputLookupTokenPredictor

Overrides

TokenPredictor.constructor

Accessors

patternMinLength

Get Signature

ts
get patternMinLength(): number

Defined in: evaluator/LlamaContext/tokenPredictors/InputLookupTokenPredictor.ts:86

Returns

number


patternMaxLength

Get Signature

ts
get patternMaxLength(): number

Defined in: evaluator/LlamaContext/tokenPredictors/InputLookupTokenPredictor.ts:90

Returns

number


predictionMinLength

Get Signature

ts
get predictionMinLength(): number

Defined in: evaluator/LlamaContext/tokenPredictors/InputLookupTokenPredictor.ts:94

Returns

number


predictionMaxLength

Get Signature

ts
get predictionMaxLength(): number

Defined in: evaluator/LlamaContext/tokenPredictors/InputLookupTokenPredictor.ts:98

Returns

number

Methods

stop()

ts
stop(untilPredictionsExhausted?: boolean): 
  | void
  | Promise<void>

Defined in: evaluator/LlamaContext/TokenPredictor.ts:52

Stops the prediction process when it runs in the background.

Parameters

ParameterTypeDescription
untilPredictionsExhausted?booleanIf true, the prediction process should not resume until the current predictions are exhausted.

Returns

| void | Promise<void>

Inherited from

TokenPredictor.stop


reset()

ts
reset(__namedParameters: {
  stateTokens: Token[];
 }): void

Defined in: evaluator/LlamaContext/tokenPredictors/InputLookupTokenPredictor.ts:102

Resets the state of the predictor.

Called before the generation starts.

Parameters

ParameterType
__namedParameters{ stateTokens: Token[]; }
__namedParameters.stateTokensToken[]

Returns

void

Overrides

TokenPredictor.reset


updateInputTokens()

ts
updateInputTokens(tokens: Token[]): void

Defined in: evaluator/LlamaContext/tokenPredictors/InputLookupTokenPredictor.ts:110

Called with the input tokens before the generation starts when using LlamaChatSession, LlamaChat, and LlamaCompletion.

Parameters

ParameterType
tokensToken[]

Returns

void

Overrides

TokenPredictor.updateInputTokens


pushTokens()

ts
pushTokens(tokens: Token[]): void

Defined in: evaluator/LlamaContext/tokenPredictors/InputLookupTokenPredictor.ts:116

Parameters

ParameterType
tokensToken[]

Returns

void

Overrides

TokenPredictor.pushTokens


predictTokens()

ts
predictTokens(): Token[]

Defined in: evaluator/LlamaContext/tokenPredictors/InputLookupTokenPredictor.ts:124

Predicts the next tokens based on the current state.

If the generation should wait until the minimum predications are ready, this method should return a promise that resolves when the minimum predictions are ready.

A background prediction process can be started when this function is called, so that the next predictions will be ready when this function is called again.

Returns

Token[]

Overrides

TokenPredictor.predictTokens


dispose()

ts
dispose(): void

Defined in: evaluator/LlamaContext/tokenPredictors/InputLookupTokenPredictor.ts:169

Returns

void

Overrides

TokenPredictor.dispose