Transformers.js documentation

generation/stopping_criteria

Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

generation/stopping_criteria


generation/stopping_criteria.StoppingCriteria

Abstract base class for all stopping criteria that can be applied during generation.

Kind: static class of generation/stopping_criteria


stoppingCriteria._call(input_ids, scores) ⇒ <code> Array. < boolean > </code>

Kind: instance method of StoppingCriteria
Returns: Array.<boolean> - A list of booleans indicating whether each sequence should be stopped.

ParamTypeDescription
input_idsArray.<Array<number>>

(number[][] of shape (batch_size, sequence_length)): Indices of input sequence tokens in the vocabulary.

scoresArray.<Array<number>>

scores (number[][] of shape (batch_size, config.vocab_size)): Prediction scores of a language modeling head. These can be scores for each vocabulary token before SoftMax or scores for each vocabulary token after SoftMax.


generation/stopping_criteria.StoppingCriteriaList

Kind: static class of generation/stopping_criteria


new StoppingCriteriaList()

Constructs a new instance of StoppingCriteriaList.


stoppingCriteriaList.push(item)

Adds a new stopping criterion to the list.

Kind: instance method of StoppingCriteriaList

ParamTypeDescription
itemStoppingCriteria

The stopping criterion to add.


stoppingCriteriaList.extend(items)

Adds multiple stopping criteria to the list.

Kind: instance method of StoppingCriteriaList

ParamTypeDescription
itemsStoppingCriteria | StoppingCriteriaList | Array<StoppingCriteria>

The stopping criteria to add.


generation/stopping_criteria.MaxLengthCriteria

This class can be used to stop generation whenever the full generated number of tokens exceeds max_length. Keep in mind for decoder-only type of transformers, this will include the initial prompted tokens.

Kind: static class of generation/stopping_criteria


new MaxLengthCriteria(max_length, [max_position_embeddings])

ParamTypeDefaultDescription
max_lengthnumber

The maximum length that the output sequence can have in number of tokens.

[max_position_embeddings]number

The maximum model length, as defined by the model's config.max_position_embeddings attribute.


generation/stopping_criteria.EosTokenCriteria

This class can be used to stop generation whenever the “end-of-sequence” token is generated. By default, it uses the model.generation_config.eos_token_id.

Kind: static class of generation/stopping_criteria


new EosTokenCriteria(eos_token_id)

ParamTypeDescription
eos_token_idnumber | Array<number>

The id of the end-of-sequence token. Optionally, use a list to set multiple end-of-sequence tokens.


eosTokenCriteria._call(input_ids, scores) ⇒ <code> Array. < boolean > </code>

Kind: instance method of EosTokenCriteria

ParamType
input_idsArray.<Array<number>>
scoresArray.<Array<number>>

generation/stopping_criteria.InterruptableStoppingCriteria

This class can be used to stop generation whenever the user interrupts the process.

Kind: static class of generation/stopping_criteria


< > Update on GitHub