> For the complete documentation index, see [llms.txt](https://boinc-ai.gitbook.io/transformers.js/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://boinc-ai.gitbook.io/transformers.js/api-reference/utilities/generation.md).

# Generation

## utils/generation

Classes, functions, and utilities for generation.

**Todo**

* Describe how to create a custom `GenerationConfig`.
* [utils/generation](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation)
  * *static*
    * [.LogitsProcessorList](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.LogitsProcessorList) ⇐ `Callable`
      * [`new LogitsProcessorList()`](https://huggingface.co/docs/transformers.js/api/utils/generation#new_module_utils/generation.LogitsProcessorList_new)
      * [`.push(item)`](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.LogitsProcessorList+push)
      * [`.extend(items)`](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.LogitsProcessorList+extend)
      * [`._call(input_ids, batchedLogits)`](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.LogitsProcessorList+_call)
    * [.LogitsProcessor](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.LogitsProcessor) ⇐ `Callable`
      * [*`._call(input_ids, logits)`*](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.LogitsProcessor+_call)
    * [.ForceTokensLogitsProcessor](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.ForceTokensLogitsProcessor) ⇐ `LogitsProcessor`
      * [`new ForceTokensLogitsProcessor(forced_decoder_ids)`](https://huggingface.co/docs/transformers.js/api/utils/generation#new_module_utils/generation.ForceTokensLogitsProcessor_new)
      * [`._call(input_ids, logits)`](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.ForceTokensLogitsProcessor+_call) ⇒ `Tensor`
    * [.ForcedBOSTokenLogitsProcessor](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.ForcedBOSTokenLogitsProcessor) ⇐ `LogitsProcessor`
      * [`new ForcedBOSTokenLogitsProcessor(bos_token_id)`](https://huggingface.co/docs/transformers.js/api/utils/generation#new_module_utils/generation.ForcedBOSTokenLogitsProcessor_new)
      * [`._call(input_ids, logits)`](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.ForcedBOSTokenLogitsProcessor+_call) ⇒ `Object`
    * [.ForcedEOSTokenLogitsProcessor](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.ForcedEOSTokenLogitsProcessor) ⇐ `LogitsProcessor`
      * [`new ForcedEOSTokenLogitsProcessor(max_length, forced_eos_token_id)`](https://huggingface.co/docs/transformers.js/api/utils/generation#new_module_utils/generation.ForcedEOSTokenLogitsProcessor_new)
      * [`._call(input_ids, logits)`](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.ForcedEOSTokenLogitsProcessor+_call)
    * [.SuppressTokensAtBeginLogitsProcessor](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.SuppressTokensAtBeginLogitsProcessor) ⇐ `LogitsProcessor`
      * [`new SuppressTokensAtBeginLogitsProcessor(begin_suppress_tokens, begin_index)`](https://huggingface.co/docs/transformers.js/api/utils/generation#new_module_utils/generation.SuppressTokensAtBeginLogitsProcessor_new)
      * [`._call(input_ids, logits)`](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.SuppressTokensAtBeginLogitsProcessor+_call) ⇒ `Object`
    * [.WhisperTimeStampLogitsProcessor](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.WhisperTimeStampLogitsProcessor) ⇐ `LogitsProcessor`
      * [`new WhisperTimeStampLogitsProcessor(generate_config)`](https://huggingface.co/docs/transformers.js/api/utils/generation#new_module_utils/generation.WhisperTimeStampLogitsProcessor_new)
      * [`._call(input_ids, logits)`](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.WhisperTimeStampLogitsProcessor+_call) ⇒ `Tensor`
    * [.NoRepeatNGramLogitsProcessor](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.NoRepeatNGramLogitsProcessor) ⇐ `LogitsProcessor`
      * [`new NoRepeatNGramLogitsProcessor(no_repeat_ngram_size)`](https://huggingface.co/docs/transformers.js/api/utils/generation#new_module_utils/generation.NoRepeatNGramLogitsProcessor_new)
      * [`.getNgrams(prevInputIds)`](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.NoRepeatNGramLogitsProcessor+getNgrams) ⇒ `Map.<string, Array<number>>`
      * [`.getGeneratedNgrams(bannedNgrams, prevInputIds)`](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.NoRepeatNGramLogitsProcessor+getGeneratedNgrams) ⇒ `Array.<number>`
      * [`.calcBannedNgramTokens(prevInputIds)`](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.NoRepeatNGramLogitsProcessor+calcBannedNgramTokens) ⇒ `Array.<number>`
      * [`._call(input_ids, logits)`](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.NoRepeatNGramLogitsProcessor+_call) ⇒ `Object`
    * [.RepetitionPenaltyLogitsProcessor](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.RepetitionPenaltyLogitsProcessor) ⇐ `LogitsProcessor`
      * [`new RepetitionPenaltyLogitsProcessor(penalty)`](https://huggingface.co/docs/transformers.js/api/utils/generation#new_module_utils/generation.RepetitionPenaltyLogitsProcessor_new)
      * [`._call(input_ids, logits)`](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.RepetitionPenaltyLogitsProcessor+_call) ⇒ `Object`
    * [.MinLengthLogitsProcessor](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.MinLengthLogitsProcessor) ⇐ `LogitsProcessor`
      * [`new MinLengthLogitsProcessor(min_length, eos_token_id)`](https://huggingface.co/docs/transformers.js/api/utils/generation#new_module_utils/generation.MinLengthLogitsProcessor_new)
      * [`._call(input_ids, logits)`](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.MinLengthLogitsProcessor+_call) ⇒ `Object`
    * [.MinNewTokensLengthLogitsProcessor](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.MinNewTokensLengthLogitsProcessor) ⇐ `LogitsProcessor`
      * [`new MinNewTokensLengthLogitsProcessor(prompt_length_to_skip, min_new_tokens, eos_token_id)`](https://huggingface.co/docs/transformers.js/api/utils/generation#new_module_utils/generation.MinNewTokensLengthLogitsProcessor_new)
      * [`._call(input_ids, logits)`](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.MinNewTokensLengthLogitsProcessor+_call) ⇒ `Object`
    * [.GenerationConfig](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.GenerationConfig)
      * [`new GenerationConfig([kwargs])`](https://huggingface.co/docs/transformers.js/api/utils/generation#new_module_utils/generation.GenerationConfig_new)
    * [.Sampler](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.Sampler)
      * [`new Sampler(generation_config)`](https://huggingface.co/docs/transformers.js/api/utils/generation#new_module_utils/generation.Sampler_new)
      * *instance*
        * [`._call(logits, index)`](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.Sampler+_call) ⇒ `void`
        * [`.sample(logits, index)`](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.Sampler+sample)
        * [`.getLogits(logits, index)`](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.Sampler+getLogits) ⇒ `Array`
        * [`.randomSelect(probabilities)`](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.Sampler+randomSelect) ⇒ `number`
      * *static*
        * [`.getSampler(generation_config)`](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.Sampler.getSampler) ⇒ `Sampler`
  * *inner*
    * [\~GreedySampler](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation..GreedySampler) ⇐ `Sampler`
      * [`.sample(logits, [index])`](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation..GreedySampler+sample) ⇒ `Array`
    * [\~MultinomialSampler](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation..MultinomialSampler) ⇐ `Sampler`
      * [`.sample(logits, index)`](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation..MultinomialSampler+sample) ⇒ `Array`
    * [\~BeamSearchSampler](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation..BeamSearchSampler) ⇐ `Sampler`
      * [`.sample(logits, index)`](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation..BeamSearchSampler+sample) ⇒ `Array`

***

### utils/generation.LogitsProcessorList ⇐ \<code> Callable \</code>

A class representing a list of logits processors. A logits processor is a function that modifies the logits output of a language model. This class provides methods for adding new processors and applying all processors to a batch of logits.

**Kind**: static class of [`utils/generation`](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation)\
**Extends**: `Callable`

* [.LogitsProcessorList](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.LogitsProcessorList) ⇐ `Callable`
  * [`new LogitsProcessorList()`](https://huggingface.co/docs/transformers.js/api/utils/generation#new_module_utils/generation.LogitsProcessorList_new)
  * [`.push(item)`](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.LogitsProcessorList+push)
  * [`.extend(items)`](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.LogitsProcessorList+extend)
  * [`._call(input_ids, batchedLogits)`](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.LogitsProcessorList+_call)

***

#### new LogitsProcessorList()

Constructs a new instance of `LogitsProcessorList`.

***

#### logitsProcessorList.push(item)

Adds a new logits processor to the list.

**Kind**: instance method of [`LogitsProcessorList`](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.LogitsProcessorList)

| Param | Type              | Description                           |
| ----- | ----------------- | ------------------------------------- |
| item  | `LogitsProcessor` | The logits processor function to add. |

***

#### logitsProcessorList.extend(items)

Adds multiple logits processors to the list.

**Kind**: instance method of [`LogitsProcessorList`](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.LogitsProcessorList)

| Param | Type                      | Description                            |
| ----- | ------------------------- | -------------------------------------- |
| items | `Array.<LogitsProcessor>` | The logits processor functions to add. |

***

#### logitsProcessorList.\_call(input\_ids, batchedLogits)

Applies all logits processors in the list to a batch of logits, modifying them in-place.

**Kind**: instance method of [`LogitsProcessorList`](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.LogitsProcessorList)

| Param         | Type                    | Description                                                                               |
| ------------- | ----------------------- | ----------------------------------------------------------------------------------------- |
| input\_ids    | `Array.<number>`        | The input IDs for the language model.                                                     |
| batchedLogits | `Array.<Array<number>>` | A 2D array of logits, where each row corresponds to a single input sequence in the batch. |

***

### utils/generation.LogitsProcessor ⇐ \<code> Callable \</code>

Base class for processing logits.

**Kind**: static class of [`utils/generation`](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation)\
**Extends**: `Callable`

***

#### logitsProcessor.\_call(input\_ids, logits)

Apply the processor to the input logits.

**Kind**: instance abstract method of [`LogitsProcessor`](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.LogitsProcessor)\
**Throws**:

* `Error` Throws an error if \`\_call\` is not implemented in the subclass.

| Param      | Type     | Description            |
| ---------- | -------- | ---------------------- |
| input\_ids | `Array`  | The input ids.         |
| logits     | `Tensor` | The logits to process. |

***

### utils/generation.ForceTokensLogitsProcessor ⇐ \<code> LogitsProcessor \</code>

A logits processor that forces a specific token to be generated by the decoder.

**Kind**: static class of [`utils/generation`](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation)\
**Extends**: `LogitsProcessor`

* [.ForceTokensLogitsProcessor](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.ForceTokensLogitsProcessor) ⇐ `LogitsProcessor`
  * [`new ForceTokensLogitsProcessor(forced_decoder_ids)`](https://huggingface.co/docs/transformers.js/api/utils/generation#new_module_utils/generation.ForceTokensLogitsProcessor_new)
  * [`._call(input_ids, logits)`](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.ForceTokensLogitsProcessor+_call) ⇒ `Tensor`

***

#### new ForceTokensLogitsProcessor(forced\_decoder\_ids)

Constructs a new instance of `ForceTokensLogitsProcessor`.

| Param                | Type    | Description                              |
| -------------------- | ------- | ---------------------------------------- |
| forced\_decoder\_ids | `Array` | The ids of tokens that should be forced. |

***

#### forceTokensLogitsProcessor.\_call(input\_ids, logits) ⇒ \<code> Tensor \</code>

Apply the processor to the input logits.

**Kind**: instance method of [`ForceTokensLogitsProcessor`](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.ForceTokensLogitsProcessor)\
**Returns**: `Tensor` - The processed logits.

| Param      | Type     | Description            |
| ---------- | -------- | ---------------------- |
| input\_ids | `Array`  | The input ids.         |
| logits     | `Tensor` | The logits to process. |

***

### utils/generation.ForcedBOSTokenLogitsProcessor ⇐ \<code> LogitsProcessor \</code>

A LogitsProcessor that forces a BOS token at the beginning of the generated sequence.

**Kind**: static class of [`utils/generation`](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation)\
**Extends**: `LogitsProcessor`

* [.ForcedBOSTokenLogitsProcessor](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.ForcedBOSTokenLogitsProcessor) ⇐ `LogitsProcessor`
  * [`new ForcedBOSTokenLogitsProcessor(bos_token_id)`](https://huggingface.co/docs/transformers.js/api/utils/generation#new_module_utils/generation.ForcedBOSTokenLogitsProcessor_new)
  * [`._call(input_ids, logits)`](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.ForcedBOSTokenLogitsProcessor+_call) ⇒ `Object`

***

#### new ForcedBOSTokenLogitsProcessor(bos\_token\_id)

Create a ForcedBOSTokenLogitsProcessor.

| Param          | Type     | Description                                             |
| -------------- | -------- | ------------------------------------------------------- |
| bos\_token\_id | `number` | The ID of the beginning-of-sequence token to be forced. |

***

#### forcedBOSTokenLogitsProcessor.\_call(input\_ids, logits) ⇒ \<code> Object \</code>

Apply the BOS token forcing to the logits.

**Kind**: instance method of [`ForcedBOSTokenLogitsProcessor`](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.ForcedBOSTokenLogitsProcessor)\
**Returns**: `Object` - The logits with BOS token forcing.

| Param      | Type     | Description    |
| ---------- | -------- | -------------- |
| input\_ids | `Array`  | The input IDs. |
| logits     | `Object` | The logits.    |

***

### utils/generation.ForcedEOSTokenLogitsProcessor ⇐ \<code> LogitsProcessor \</code>

A logits processor that forces end-of-sequence token probability to 1.

**Kind**: static class of [`utils/generation`](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation)\
**Extends**: `LogitsProcessor`

* [.ForcedEOSTokenLogitsProcessor](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.ForcedEOSTokenLogitsProcessor) ⇐ `LogitsProcessor`
  * [`new ForcedEOSTokenLogitsProcessor(max_length, forced_eos_token_id)`](https://huggingface.co/docs/transformers.js/api/utils/generation#new_module_utils/generation.ForcedEOSTokenLogitsProcessor_new)
  * [`._call(input_ids, logits)`](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.ForcedEOSTokenLogitsProcessor+_call)

***

#### new ForcedEOSTokenLogitsProcessor(max\_length, forced\_eos\_token\_id)

Create a ForcedEOSTokenLogitsProcessor.

| Param                  | Type                        | Description                                       |
| ---------------------- | --------------------------- | ------------------------------------------------- |
| max\_length            | `number`                    | Max length of the sequence.                       |
| forced\_eos\_token\_id | `number` \| `Array<number>` | The ID of the end-of-sequence token to be forced. |

***

#### forcedEOSTokenLogitsProcessor.\_call(input\_ids, logits)

Apply the processor to input\_ids and logits.

**Kind**: instance method of [`ForcedEOSTokenLogitsProcessor`](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.ForcedEOSTokenLogitsProcessor)

| Param      | Type             | Description        |
| ---------- | ---------------- | ------------------ |
| input\_ids | `Array.<number>` | The input ids.     |
| logits     | `Tensor`         | The logits tensor. |

***

### utils/generation.SuppressTokensAtBeginLogitsProcessor ⇐ \<code> LogitsProcessor \</code>

A LogitsProcessor that suppresses a list of tokens as soon as the `generate` function starts generating using `begin_index` tokens. This should ensure that the tokens defined by `begin_suppress_tokens` at not sampled at the begining of the generation.

**Kind**: static class of [`utils/generation`](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation)\
**Extends**: `LogitsProcessor`

* [.SuppressTokensAtBeginLogitsProcessor](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.SuppressTokensAtBeginLogitsProcessor) ⇐ `LogitsProcessor`
  * [`new SuppressTokensAtBeginLogitsProcessor(begin_suppress_tokens, begin_index)`](https://huggingface.co/docs/transformers.js/api/utils/generation#new_module_utils/generation.SuppressTokensAtBeginLogitsProcessor_new)
  * [`._call(input_ids, logits)`](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.SuppressTokensAtBeginLogitsProcessor+_call) ⇒ `Object`

***

#### new SuppressTokensAtBeginLogitsProcessor(begin\_suppress\_tokens, begin\_index)

Create a SuppressTokensAtBeginLogitsProcessor.

| Param                   | Type             | Description                                                 |
| ----------------------- | ---------------- | ----------------------------------------------------------- |
| begin\_suppress\_tokens | `Array.<number>` | The IDs of the tokens to suppress.                          |
| begin\_index            | `number`         | The number of tokens to generate before suppressing tokens. |

***

#### suppressTokensAtBeginLogitsProcessor.\_call(input\_ids, logits) ⇒ \<code> Object \</code>

Apply the BOS token forcing to the logits.

**Kind**: instance method of [`SuppressTokensAtBeginLogitsProcessor`](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.SuppressTokensAtBeginLogitsProcessor)\
**Returns**: `Object` - The logits with BOS token forcing.

| Param      | Type     | Description    |
| ---------- | -------- | -------------- |
| input\_ids | `Array`  | The input IDs. |
| logits     | `Object` | The logits.    |

***

### utils/generation.WhisperTimeStampLogitsProcessor ⇐ \<code> LogitsProcessor \</code>

A LogitsProcessor that handles adding timestamps to generated text.

**Kind**: static class of [`utils/generation`](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation)\
**Extends**: `LogitsProcessor`

* [.WhisperTimeStampLogitsProcessor](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.WhisperTimeStampLogitsProcessor) ⇐ `LogitsProcessor`
  * [`new WhisperTimeStampLogitsProcessor(generate_config)`](https://huggingface.co/docs/transformers.js/api/utils/generation#new_module_utils/generation.WhisperTimeStampLogitsProcessor_new)
  * [`._call(input_ids, logits)`](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.WhisperTimeStampLogitsProcessor+_call) ⇒ `Tensor`

***

#### new WhisperTimeStampLogitsProcessor(generate\_config)

Constructs a new WhisperTimeStampLogitsProcessor.

| Param                                              | Type                    | Description                                                                                                                                                                   |
| -------------------------------------------------- | ----------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| generate\_config                                   | `Object`                | The config object passed to the `generate()` method of a transformer model.                                                                                                   |
| generate\_config.eos\_token\_id                    | `number`                | The ID of the end-of-sequence token.                                                                                                                                          |
| generate\_config.no\_timestamps\_token\_id         | `number`                | The ID of the token used to indicate that a token should not have a timestamp.                                                                                                |
| \[generate\_config.forced\_decoder\_ids]           | `Array.<Array<number>>` | An array of two-element arrays representing decoder IDs that are forced to appear in the output. The second element of each array indicates whether the token is a timestamp. |
| \[generate\_config.max\_initial\_timestamp\_index] | `number`                | The maximum index at which an initial timestamp can appear.                                                                                                                   |

***

#### whisperTimeStampLogitsProcessor.\_call(input\_ids, logits) ⇒ \<code> Tensor \</code>

Modify the logits to handle timestamp tokens.

**Kind**: instance method of [`WhisperTimeStampLogitsProcessor`](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.WhisperTimeStampLogitsProcessor)\
**Returns**: `Tensor` - The modified logits.

| Param      | Type     | Description                     |
| ---------- | -------- | ------------------------------- |
| input\_ids | `Array`  | The input sequence of tokens.   |
| logits     | `Tensor` | The logits output by the model. |

***

### utils/generation.NoRepeatNGramLogitsProcessor ⇐ \<code> LogitsProcessor \</code>

A logits processor that disallows ngrams of a certain size to be repeated.

**Kind**: static class of [`utils/generation`](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation)\
**Extends**: `LogitsProcessor`

* [.NoRepeatNGramLogitsProcessor](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.NoRepeatNGramLogitsProcessor) ⇐ `LogitsProcessor`
  * [`new NoRepeatNGramLogitsProcessor(no_repeat_ngram_size)`](https://huggingface.co/docs/transformers.js/api/utils/generation#new_module_utils/generation.NoRepeatNGramLogitsProcessor_new)
  * [`.getNgrams(prevInputIds)`](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.NoRepeatNGramLogitsProcessor+getNgrams) ⇒ `Map.<string, Array<number>>`
  * [`.getGeneratedNgrams(bannedNgrams, prevInputIds)`](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.NoRepeatNGramLogitsProcessor+getGeneratedNgrams) ⇒ `Array.<number>`
  * [`.calcBannedNgramTokens(prevInputIds)`](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.NoRepeatNGramLogitsProcessor+calcBannedNgramTokens) ⇒ `Array.<number>`
  * [`._call(input_ids, logits)`](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.NoRepeatNGramLogitsProcessor+_call) ⇒ `Object`

***

#### new NoRepeatNGramLogitsProcessor(no\_repeat\_ngram\_size)

Create a NoRepeatNGramLogitsProcessor.

| Param                   | Type     | Description                                                            |
| ----------------------- | -------- | ---------------------------------------------------------------------- |
| no\_repeat\_ngram\_size | `number` | The no-repeat-ngram size. All ngrams of this size can only occur once. |

***

#### noRepeatNGramLogitsProcessor.getNgrams(prevInputIds) ⇒ \<code> Map. < string, Array < number > > \</code>

Generate n-grams from a sequence of token ids.

**Kind**: instance method of [`NoRepeatNGramLogitsProcessor`](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.NoRepeatNGramLogitsProcessor)\
**Returns**: `Map.<string, Array<number>>` - Map of generated n-grams

| Param        | Type             | Description                |
| ------------ | ---------------- | -------------------------- |
| prevInputIds | `Array.<number>` | List of previous input ids |

***

#### noRepeatNGramLogitsProcessor.getGeneratedNgrams(bannedNgrams, prevInputIds) ⇒ \<code> Array. < number > \</code>

Generate n-grams from a sequence of token ids.

**Kind**: instance method of [`NoRepeatNGramLogitsProcessor`](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.NoRepeatNGramLogitsProcessor)\
**Returns**: `Array.<number>` - Map of generated n-grams

| Param        | Type                          | Description                |
| ------------ | ----------------------------- | -------------------------- |
| bannedNgrams | `Map.<string, Array<number>>` | Map of banned n-grams      |
| prevInputIds | `Array.<number>`              | List of previous input ids |

***

#### noRepeatNGramLogitsProcessor.calcBannedNgramTokens(prevInputIds) ⇒ \<code> Array. < number > \</code>

Calculate banned n-gram tokens

**Kind**: instance method of [`NoRepeatNGramLogitsProcessor`](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.NoRepeatNGramLogitsProcessor)\
**Returns**: `Array.<number>` - Map of generated n-grams

| Param        | Type             | Description                |
| ------------ | ---------------- | -------------------------- |
| prevInputIds | `Array.<number>` | List of previous input ids |

***

#### noRepeatNGramLogitsProcessor.\_call(input\_ids, logits) ⇒ \<code> Object \</code>

Apply the no-repeat-ngram processor to the logits.

**Kind**: instance method of [`NoRepeatNGramLogitsProcessor`](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.NoRepeatNGramLogitsProcessor)\
**Returns**: `Object` - The logits with no-repeat-ngram processing.

| Param      | Type     | Description    |
| ---------- | -------- | -------------- |
| input\_ids | `Array`  | The input IDs. |
| logits     | `Object` | The logits.    |

***

### utils/generation.RepetitionPenaltyLogitsProcessor ⇐ \<code> LogitsProcessor \</code>

A logits processor that penalises repeated output tokens.

**Kind**: static class of [`utils/generation`](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation)\
**Extends**: `LogitsProcessor`

* [.RepetitionPenaltyLogitsProcessor](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.RepetitionPenaltyLogitsProcessor) ⇐ `LogitsProcessor`
  * [`new RepetitionPenaltyLogitsProcessor(penalty)`](https://huggingface.co/docs/transformers.js/api/utils/generation#new_module_utils/generation.RepetitionPenaltyLogitsProcessor_new)
  * [`._call(input_ids, logits)`](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.RepetitionPenaltyLogitsProcessor+_call) ⇒ `Object`

***

#### new RepetitionPenaltyLogitsProcessor(penalty)

Create a RepetitionPenaltyLogitsProcessor.

| Param   | Type     | Description                               |
| ------- | -------- | ----------------------------------------- |
| penalty | `number` | The penalty to apply for repeated tokens. |

***

#### repetitionPenaltyLogitsProcessor.\_call(input\_ids, logits) ⇒ \<code> Object \</code>

Apply the repetition penalty to the logits.

**Kind**: instance method of [`RepetitionPenaltyLogitsProcessor`](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.RepetitionPenaltyLogitsProcessor)\
**Returns**: `Object` - The logits with repetition penalty processing.

| Param      | Type     | Description    |
| ---------- | -------- | -------------- |
| input\_ids | `Array`  | The input IDs. |
| logits     | `Object` | The logits.    |

***

### utils/generation.MinLengthLogitsProcessor ⇐ \<code> LogitsProcessor \</code>

A logits processor that enforces a minimum number of tokens.

**Kind**: static class of [`utils/generation`](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation)\
**Extends**: `LogitsProcessor`

* [.MinLengthLogitsProcessor](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.MinLengthLogitsProcessor) ⇐ `LogitsProcessor`
  * [`new MinLengthLogitsProcessor(min_length, eos_token_id)`](https://huggingface.co/docs/transformers.js/api/utils/generation#new_module_utils/generation.MinLengthLogitsProcessor_new)
  * [`._call(input_ids, logits)`](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.MinLengthLogitsProcessor+_call) ⇒ `Object`

***

#### new MinLengthLogitsProcessor(min\_length, eos\_token\_id)

Create a MinLengthLogitsProcessor.

| Param          | Type                        | Description                                                                             |
| -------------- | --------------------------- | --------------------------------------------------------------------------------------- |
| min\_length    | `number`                    | The minimum length below which the score of `eos_token_id` is set to negative infinity. |
| eos\_token\_id | `number` \| `Array<number>` | The ID/IDs of the end-of-sequence token.                                                |

***

#### minLengthLogitsProcessor.\_call(input\_ids, logits) ⇒ \<code> Object \</code>

Apply logit processor.

**Kind**: instance method of [`MinLengthLogitsProcessor`](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.MinLengthLogitsProcessor)\
**Returns**: `Object` - The processed logits.

| Param      | Type     | Description    |
| ---------- | -------- | -------------- |
| input\_ids | `Array`  | The input IDs. |
| logits     | `Object` | The logits.    |

***

### utils/generation.MinNewTokensLengthLogitsProcessor ⇐ \<code> LogitsProcessor \</code>

A logits processor that enforces a minimum number of new tokens.

**Kind**: static class of [`utils/generation`](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation)\
**Extends**: `LogitsProcessor`

* [.MinNewTokensLengthLogitsProcessor](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.MinNewTokensLengthLogitsProcessor) ⇐ `LogitsProcessor`
  * [`new MinNewTokensLengthLogitsProcessor(prompt_length_to_skip, min_new_tokens, eos_token_id)`](https://huggingface.co/docs/transformers.js/api/utils/generation#new_module_utils/generation.MinNewTokensLengthLogitsProcessor_new)
  * [`._call(input_ids, logits)`](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.MinNewTokensLengthLogitsProcessor+_call) ⇒ `Object`

***

#### new MinNewTokensLengthLogitsProcessor(prompt\_length\_to\_skip, min\_new\_tokens, eos\_token\_id)

Create a MinNewTokensLengthLogitsProcessor.

| Param                    | Type                        | Description                                                                                          |
| ------------------------ | --------------------------- | ---------------------------------------------------------------------------------------------------- |
| prompt\_length\_to\_skip | `number`                    | The input tokens length.                                                                             |
| min\_new\_tokens         | `number`                    | The minimum *new* tokens length below which the score of `eos_token_id` is set to negative infinity. |
| eos\_token\_id           | `number` \| `Array<number>` | The ID/IDs of the end-of-sequence token.                                                             |

***

#### minNewTokensLengthLogitsProcessor.\_call(input\_ids, logits) ⇒ \<code> Object \</code>

Apply logit processor.

**Kind**: instance method of [`MinNewTokensLengthLogitsProcessor`](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.MinNewTokensLengthLogitsProcessor)\
**Returns**: `Object` - The processed logits.

| Param      | Type     | Description    |
| ---------- | -------- | -------------- |
| input\_ids | `Array`  | The input IDs. |
| logits     | `Object` | The logits.    |

***

### utils/generation.GenerationConfig

Class that holds a configuration for a generation task.

**Kind**: static class of [`utils/generation`](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation)

***

#### new GenerationConfig(\[kwargs])

Create a GenerationConfig object

| Param                                         | Type                                                    | Default | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| --------------------------------------------- | ------------------------------------------------------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| \[kwargs]                                     | `Object`                                                | `{}`    | The configuration parameters. If not set, the default values are used.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| \[kwargs.max\_length]                         | `number`                                                | `20`    | The maximum length the generated tokens can have. Corresponds to the length of the input prompt + `max_new_tokens`. Its effect is overridden by `max_new_tokens`, if also set.                                                                                                                                                                                                                                                                                                                                                                                         |
| \[kwargs.max\_new\_tokens]                    | `number`                                                |         | The maximum numbers of tokens to generate, ignoring the number of tokens in the prompt.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| \[kwargs.min\_length]                         | `number`                                                | `0`     | The minimum length of the sequence to be generated. Corresponds to the length of the input prompt + `min_new_tokens`. Its effect is overridden by `min_new_tokens`, if also set.                                                                                                                                                                                                                                                                                                                                                                                       |
| \[kwargs.min\_new\_tokens]                    | `number`                                                |         | The minimum numbers of tokens to generate, ignoring the number of tokens in the prompt.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| \[kwargs.early\_stopping]                     | `boolean` \| `"never"`                                  | `false` | <p>Controls the stopping condition for beam-based methods, like beam-search. It accepts the following values:</p><ul><li><code>true</code>, where the generation stops as soon as there are <code>num\_beams</code> complete candidates;</li><li><code>false</code>, where an heuristic is applied and the generation stops when is it very unlikely to find better candidates;</li><li><code>"never"</code>, where the beam search procedure only stops when there cannot be better candidates (canonical beam search algorithm).</li></ul>                           |
| \[kwargs.max\_time]                           | `number`                                                |         | The maximum amount of time you allow the computation to run for in seconds. Generation will still finish the current pass after allocated time has been passed.                                                                                                                                                                                                                                                                                                                                                                                                        |
| \[kwargs.do\_sample]                          | `boolean`                                               | `false` | Whether or not to use sampling; use greedy decoding otherwise.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| \[kwargs.num\_beams]                          | `number`                                                | `1`     | Number of beams for beam search. 1 means no beam search.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| \[kwargs.num\_beam\_groups]                   | `number`                                                | `1`     | Number of groups to divide `num_beams` into in order to ensure diversity among different groups of beams. See [this paper](https://arxiv.org/pdf/1610.02424.pdf) for more details.                                                                                                                                                                                                                                                                                                                                                                                     |
| \[kwargs.penalty\_alpha]                      | `number`                                                |         | The values balance the model confidence and the degeneration penalty in contrastive search decoding.                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| \[kwargs.use\_cache]                          | `boolean`                                               | `true`  | Whether or not the model should use the past last key/values attentions (if applicable to the model) to speed up decoding.                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| \[kwargs.temperature]                         | `number`                                                | `1.0`   | The value used to modulate the next token probabilities.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| \[kwargs.top\_k]                              | `number`                                                | `50`    | The number of highest probability vocabulary tokens to keep for top-k-filtering.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| \[kwargs.top\_p]                              | `number`                                                | `1.0`   | If set to float < 1, only the smallest set of most probable tokens with probabilities that add up to `top_p` or higher are kept for generation.                                                                                                                                                                                                                                                                                                                                                                                                                        |
| \[kwargs.typical\_p]                          | `number`                                                | `1.0`   | Local typicality measures how similar the conditional probability of predicting a target token next is to the expected conditional probability of predicting a random token next, given the partial text already generated. If set to float < 1, the smallest set of the most locally typical tokens with probabilities that add up to `typical_p` or higher are kept for generation. See [this paper](https://arxiv.org/pdf/2202.00666.pdf) for more details.                                                                                                         |
| \[kwargs.epsilon\_cutoff]                     | `number`                                                | `0.0`   | If set to float strictly between 0 and 1, only tokens with a conditional probability greater than `epsilon_cutoff` will be sampled. In the paper, suggested values range from 3e-4 to 9e-4, depending on the size of the model. See [Truncation Sampling as Language Model Desmoothing](https://arxiv.org/abs/2210.15191) for more details.                                                                                                                                                                                                                            |
| \[kwargs.eta\_cutoff]                         | `number`                                                | `0.0`   | Eta sampling is a hybrid of locally typical sampling and epsilon sampling. If set to float strictly between 0 and 1, a token is only considered if it is greater than either `eta_cutoff` or `sqrt(eta_cutoff) * exp(-entropy(softmax(next_token_logits)))`. The latter term is intuitively the expected next token probability, scaled by `sqrt(eta_cutoff)`. In the paper, suggested values range from 3e-4 to 2e-3, depending on the size of the model. See [Truncation Sampling as Language Model Desmoothing](https://arxiv.org/abs/2210.15191) for more details. |
| \[kwargs.diversity\_penalty]                  | `number`                                                | `0.0`   | This value is subtracted from a beam's score if it generates a token same as any beam from other group at a particular time. Note that `diversity_penalty` is only effective if `group beam search` is enabled.                                                                                                                                                                                                                                                                                                                                                        |
| \[kwargs.repetition\_penalty]                 | `number`                                                | `1.0`   | The parameter for repetition penalty. 1.0 means no penalty. See [this paper](https://arxiv.org/pdf/1909.05858.pdf) for more details.                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| \[kwargs.encoder\_repetition\_penalty]        | `number`                                                | `1.0`   | The paramater for encoder\_repetition\_penalty. An exponential penalty on sequences that are not in the original input. 1.0 means no penalty.                                                                                                                                                                                                                                                                                                                                                                                                                          |
| \[kwargs.length\_penalty]                     | `number`                                                | `1.0`   | Exponential penalty to the length that is used with beam-based generation. It is applied as an exponent to the sequence length, which in turn is used to divide the score of the sequence. Since the score is the log likelihood of the sequence (i.e. negative), `length_penalty` > 0.0 promotes longer sequences, while `length_penalty` < 0.0 encourages shorter sequences.                                                                                                                                                                                         |
| \[kwargs.no\_repeat\_ngram\_size]             | `number`                                                | `0`     | If set to int > 0, all ngrams of that size can only occur once.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| \[kwargs.bad\_words\_ids]                     | `Array.<Array<number>>`                                 |         | List of token ids that are not allowed to be generated. In order to get the token ids of the words that should not appear in the generated text, use `(await tokenizer(bad_words, {add_prefix_space: true, add_special_tokens: false})).input_ids`.                                                                                                                                                                                                                                                                                                                    |
| \[kwargs.force\_words\_ids]                   | `Array<Array<number>>` \| `Array<Array<Array<number>>>` |         | List of token ids that must be generated. If given a `number[][]`, this is treated as a simple list of words that must be included, the opposite to `bad_words_ids`. If given `number[][][]`, this triggers a [disjunctive constraint](https://github.com/huggingface/transformers/issues/14081), where one can allow different forms of each word.                                                                                                                                                                                                                    |
| \[kwargs.renormalize\_logits]                 | `boolean`                                               | `false` | Whether to renormalize the logits after applying all the logits processors or warpers (including the custom ones). It's highly recommended to set this flag to `true` as the search algorithms suppose the score logits are normalized but some logit processors or warpers break the normalization.                                                                                                                                                                                                                                                                   |
| \[kwargs.constraints]                         | `Array.<Object>`                                        |         | Custom constraints that can be added to the generation to ensure that the output will contain the use of certain tokens as defined by `Constraint` objects, in the most sensible way possible.                                                                                                                                                                                                                                                                                                                                                                         |
| \[kwargs.forced\_bos\_token\_id]              | `number`                                                |         | The id of the token to force as the first generated token after the `decoder_start_token_id`. Useful for multilingual models like mBART where the first generated token needs to be the target language token.                                                                                                                                                                                                                                                                                                                                                         |
| \[kwargs.forced\_eos\_token\_id]              | `number` \| `Array<number>`                             |         | The id of the token to force as the last generated token when `max_length` is reached. Optionally, use a list to set multiple *end-of-sequence* tokens.                                                                                                                                                                                                                                                                                                                                                                                                                |
| \[kwargs.remove\_invalid\_values]             | `boolean`                                               | `false` | Whether to remove possible *nan* and *inf* outputs of the model to prevent the generation method to crash. Note that using `remove_invalid_values` can slow down generation.                                                                                                                                                                                                                                                                                                                                                                                           |
| \[kwargs.exponential\_decay\_length\_penalty] | `Array.<number>`                                        |         | This Tuple adds an exponentially increasing length penalty, after a certain amount of tokens have been generated. The tuple shall consist of: `(start_index, decay_factor)` where `start_index` indicates where penalty starts and `decay_factor` represents the factor of exponential decay.                                                                                                                                                                                                                                                                          |
| \[kwargs.suppress\_tokens]                    | `Array.<number>`                                        |         | A list of tokens that will be suppressed at generation. The `SupressTokens` logit processor will set their log probs to `-inf` so that they are not sampled.                                                                                                                                                                                                                                                                                                                                                                                                           |
| \[kwargs.begin\_suppress\_tokens]             | `Array.<number>`                                        |         | A list of tokens that will be suppressed at the beginning of the generation. The `SupressBeginTokens` logit processor will set their log probs to `-inf` so that they are not sampled.                                                                                                                                                                                                                                                                                                                                                                                 |
| \[kwargs.forced\_decoder\_ids]                | `Array.<Array<number>>`                                 |         | A list of pairs of integers which indicates a mapping from generation indices to token indices that will be forced before sampling. For example, `[[1, 123]]` means the second generated token will always be a token of index 123.                                                                                                                                                                                                                                                                                                                                    |
| \[kwargs.num\_return\_sequences]              | `number`                                                | `1`     | The number of independently computed returned sequences for each element in the batch.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| \[kwargs.output\_attentions]                  | `boolean`                                               | `false` | Whether or not to return the attentions tensors of all attention layers. See `attentions` under returned tensors for more details.                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| \[kwargs.output\_hidden\_states]              | `boolean`                                               | `false` | Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for more details.                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| \[kwargs.output\_scores]                      | `boolean`                                               | `false` | Whether or not to return the prediction scores. See `scores` under returned tensors for more details.                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| \[kwargs.return\_dict\_in\_generate]          | `boolean`                                               | `false` | Whether or not to return a `ModelOutput` instead of a plain tuple.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| \[kwargs.pad\_token\_id]                      | `number`                                                |         | The id of the *padding* token.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| \[kwargs.bos\_token\_id]                      | `number`                                                |         | The id of the *beginning-of-sequence* token.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| \[kwargs.eos\_token\_id]                      | `number` \| `Array<number>`                             |         | The id of the *end-of-sequence* token. Optionally, use a list to set multiple *end-of-sequence* tokens.                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| \[kwargs.encoder\_no\_repeat\_ngram\_size]    | `number`                                                | `0`     | If set to int > 0, all ngrams of that size that occur in the `encoder_input_ids` cannot occur in the `decoder_input_ids`.                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| \[kwargs.decoder\_start\_token\_id]           | `number`                                                |         | If an encoder-decoder model starts decoding with a different token than *bos*, the id of that token.                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| \[kwargs.generation\_kwargs]                  | `Object`                                                | `{}`    | Additional generation kwargs will be forwarded to the `generate` function of the model. Kwargs that are not present in `generate`'s signature will be used in the model forward pass.                                                                                                                                                                                                                                                                                                                                                                                  |

***

### utils/generation.Sampler

Sampler is a base class for all sampling methods used for text generation.

**Kind**: static class of [`utils/generation`](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation)

* [.Sampler](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.Sampler)
  * [`new Sampler(generation_config)`](https://huggingface.co/docs/transformers.js/api/utils/generation#new_module_utils/generation.Sampler_new)
  * *instance*
    * [`._call(logits, index)`](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.Sampler+_call) ⇒ `void`
    * [`.sample(logits, index)`](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.Sampler+sample)
    * [`.getLogits(logits, index)`](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.Sampler+getLogits) ⇒ `Array`
    * [`.randomSelect(probabilities)`](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.Sampler+randomSelect) ⇒ `number`
  * *static*
    * [`.getSampler(generation_config)`](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.Sampler.getSampler) ⇒ `Sampler`

***

#### new Sampler(generation\_config)

Creates a new Sampler object with the specified generation config.

| Param              | Type               | Description            |
| ------------------ | ------------------ | ---------------------- |
| generation\_config | `GenerationConfig` | The generation config. |

***

#### sampler.\_call(logits, index) ⇒ \<code> void \</code>

Executes the sampler, using the specified logits.

**Kind**: instance method of [`Sampler`](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.Sampler)

| Param  | Type     |
| ------ | -------- |
| logits | `Tensor` |
| index  | `number` |

***

#### sampler.sample(logits, index)

Abstract method for sampling the logits.

**Kind**: instance method of [`Sampler`](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.Sampler)\
**Throws**:

* `Error`

| Param  | Type     |
| ------ | -------- |
| logits | `Tensor` |
| index  | `number` |

***

#### sampler.getLogits(logits, index) ⇒ \<code> Array \</code>

Returns the specified logits as an array, with temperature applied.

**Kind**: instance method of [`Sampler`](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.Sampler)

| Param  | Type     |
| ------ | -------- |
| logits | `Tensor` |
| index  | `number` |

***

#### sampler.randomSelect(probabilities) ⇒ \<code> number \</code>

Selects an item randomly based on the specified probabilities.

**Kind**: instance method of [`Sampler`](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.Sampler)\
**Returns**: `number` - The index of the selected item.

| Param         | Type    | Description                                     |
| ------------- | ------- | ----------------------------------------------- |
| probabilities | `Array` | An array of probabilities to use for selection. |

***

#### Sampler.getSampler(generation\_config) ⇒ \<code> Sampler \</code>

Returns a Sampler object based on the specified options.

**Kind**: static method of [`Sampler`](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation.Sampler)\
**Returns**: `Sampler` - A Sampler object.

| Param              | Type               | Description                                   |
| ------------------ | ------------------ | --------------------------------------------- |
| generation\_config | `GenerationConfig` | An object containing options for the sampler. |

***

### utils/generation\~GreedySampler ⇐ \<code> Sampler \</code>

Class representing a Greedy Sampler.

**Kind**: inner class of [`utils/generation`](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation)\
**Extends**: `Sampler`

***

#### greedySampler.sample(logits, \[index]) ⇒ \<code> Array \</code>

Sample the maximum probability of a given logits tensor.

**Kind**: instance method of [`GreedySampler`](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation..GreedySampler)\
**Returns**: `Array` - An array with a single tuple, containing the index of the maximum value and a meaningless score (since this is a greedy search).

| Param    | Type     | Default |
| -------- | -------- | ------- |
| logits   | `Tensor` |         |
| \[index] | `number` | `-1`    |

***

### utils/generation\~MultinomialSampler ⇐ \<code> Sampler \</code>

Class representing a MultinomialSampler.

**Kind**: inner class of [`utils/generation`](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation)\
**Extends**: `Sampler`

***

#### multinomialSampler.sample(logits, index) ⇒ \<code> Array \</code>

Sample from the logits.

**Kind**: instance method of [`MultinomialSampler`](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation..MultinomialSampler)

| Param  | Type     |
| ------ | -------- |
| logits | `Tensor` |
| index  | `number` |

***

### utils/generation\~BeamSearchSampler ⇐ \<code> Sampler \</code>

Class representing a BeamSearchSampler.

**Kind**: inner class of [`utils/generation`](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation)\
**Extends**: `Sampler`

***

#### beamSearchSampler.sample(logits, index) ⇒ \<code> Array \</code>

Sample from the logits.

**Kind**: instance method of [`BeamSearchSampler`](https://huggingface.co/docs/transformers.js/api/utils/generation#module_utils/generation..BeamSearchSampler)

| Param  | Type     |
| ------ | -------- |
| logits | `Tensor` |
| index  | `number` |

<br>
