@huggingface/transformers 3.0.0-alpha.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.
Files changed (96) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +376 -0
  3. package/dist/ort-wasm-simd-threaded.jsep.wasm +0 -0
  4. package/dist/transformers.cjs +30741 -0
  5. package/dist/transformers.cjs.map +1 -0
  6. package/dist/transformers.js +33858 -0
  7. package/dist/transformers.js.map +1 -0
  8. package/dist/transformers.min.cjs +173 -0
  9. package/dist/transformers.min.cjs.map +1 -0
  10. package/dist/transformers.min.js +231 -0
  11. package/dist/transformers.min.js.map +1 -0
  12. package/package.json +92 -0
  13. package/src/backends/onnx.js +151 -0
  14. package/src/configs.js +360 -0
  15. package/src/env.js +152 -0
  16. package/src/generation/configuration_utils.js +381 -0
  17. package/src/generation/logits_process.js +716 -0
  18. package/src/generation/logits_sampler.js +204 -0
  19. package/src/generation/parameters.js +35 -0
  20. package/src/generation/stopping_criteria.js +156 -0
  21. package/src/generation/streamers.js +212 -0
  22. package/src/models/whisper/common_whisper.js +151 -0
  23. package/src/models/whisper/generation_whisper.js +89 -0
  24. package/src/models.js +7028 -0
  25. package/src/ops/registry.js +92 -0
  26. package/src/pipelines.js +3341 -0
  27. package/src/processors.js +2614 -0
  28. package/src/tokenizers.js +4395 -0
  29. package/src/transformers.js +28 -0
  30. package/src/utils/audio.js +704 -0
  31. package/src/utils/constants.js +2 -0
  32. package/src/utils/core.js +149 -0
  33. package/src/utils/data-structures.js +445 -0
  34. package/src/utils/devices.js +11 -0
  35. package/src/utils/dtypes.js +62 -0
  36. package/src/utils/generic.js +35 -0
  37. package/src/utils/hub.js +671 -0
  38. package/src/utils/image.js +745 -0
  39. package/src/utils/maths.js +1050 -0
  40. package/src/utils/tensor.js +1378 -0
  41. package/types/backends/onnx.d.ts +26 -0
  42. package/types/backends/onnx.d.ts.map +1 -0
  43. package/types/configs.d.ts +59 -0
  44. package/types/configs.d.ts.map +1 -0
  45. package/types/env.d.ts +106 -0
  46. package/types/env.d.ts.map +1 -0
  47. package/types/generation/configuration_utils.d.ts +320 -0
  48. package/types/generation/configuration_utils.d.ts.map +1 -0
  49. package/types/generation/logits_process.d.ts +354 -0
  50. package/types/generation/logits_process.d.ts.map +1 -0
  51. package/types/generation/logits_sampler.d.ts +51 -0
  52. package/types/generation/logits_sampler.d.ts.map +1 -0
  53. package/types/generation/parameters.d.ts +47 -0
  54. package/types/generation/parameters.d.ts.map +1 -0
  55. package/types/generation/stopping_criteria.d.ts +81 -0
  56. package/types/generation/stopping_criteria.d.ts.map +1 -0
  57. package/types/generation/streamers.d.ts +81 -0
  58. package/types/generation/streamers.d.ts.map +1 -0
  59. package/types/models/whisper/common_whisper.d.ts +8 -0
  60. package/types/models/whisper/common_whisper.d.ts.map +1 -0
  61. package/types/models/whisper/generation_whisper.d.ts +76 -0
  62. package/types/models/whisper/generation_whisper.d.ts.map +1 -0
  63. package/types/models.d.ts +3845 -0
  64. package/types/models.d.ts.map +1 -0
  65. package/types/ops/registry.d.ts +11 -0
  66. package/types/ops/registry.d.ts.map +1 -0
  67. package/types/pipelines.d.ts +2403 -0
  68. package/types/pipelines.d.ts.map +1 -0
  69. package/types/processors.d.ts +917 -0
  70. package/types/processors.d.ts.map +1 -0
  71. package/types/tokenizers.d.ts +999 -0
  72. package/types/tokenizers.d.ts.map +1 -0
  73. package/types/transformers.d.ts +13 -0
  74. package/types/transformers.d.ts.map +1 -0
  75. package/types/utils/audio.d.ts +130 -0
  76. package/types/utils/audio.d.ts.map +1 -0
  77. package/types/utils/constants.d.ts +2 -0
  78. package/types/utils/constants.d.ts.map +1 -0
  79. package/types/utils/core.d.ts +91 -0
  80. package/types/utils/core.d.ts.map +1 -0
  81. package/types/utils/data-structures.d.ts +236 -0
  82. package/types/utils/data-structures.d.ts.map +1 -0
  83. package/types/utils/devices.d.ts +8 -0
  84. package/types/utils/devices.d.ts.map +1 -0
  85. package/types/utils/dtypes.d.ts +22 -0
  86. package/types/utils/dtypes.d.ts.map +1 -0
  87. package/types/utils/generic.d.ts +11 -0
  88. package/types/utils/generic.d.ts.map +1 -0
  89. package/types/utils/hub.d.ts +191 -0
  90. package/types/utils/hub.d.ts.map +1 -0
  91. package/types/utils/image.d.ts +119 -0
  92. package/types/utils/image.d.ts.map +1 -0
  93. package/types/utils/maths.d.ts +280 -0
  94. package/types/utils/maths.d.ts.map +1 -0
  95. package/types/utils/tensor.d.ts +392 -0
  96. package/types/utils/tensor.d.ts.map +1 -0
package/src/env.js ADDED
@@ -0,0 +1,152 @@
1
+ /**
2
+ * @file Module used to configure Transformers.js.
3
+ *
4
+ * **Example:** Disable remote models.
5
+ * ```javascript
6
+ * import { env } from '@huggingface/transformers';
7
+ * env.allowRemoteModels = false;
8
+ * ```
9
+ *
10
+ * **Example:** Set local model path.
11
+ * ```javascript
12
+ * import { env } from '@huggingface/transformers';
13
+ * env.localModelPath = '/path/to/local/models/';
14
+ * ```
15
+ *
16
+ * **Example:** Set cache directory.
17
+ * ```javascript
18
+ * import { env } from '@huggingface/transformers';
19
+ * env.cacheDir = '/path/to/cache/directory/';
20
+ * ```
21
+ *
22
+ * @module env
23
+ */
24
+
25
+ import fs from 'fs';
26
+ import path from 'path';
27
+ import url from 'url';
28
+
29
+ const VERSION = '3.0.0-alpha.0';
30
+
31
+ // Check if various APIs are available (depends on environment)
32
+ const IS_BROWSER_ENV = typeof self !== 'undefined';
33
+ const IS_WEBWORKER_ENV = IS_BROWSER_ENV && self.constructor.name === 'DedicatedWorkerGlobalScope';
34
+ const IS_WEB_CACHE_AVAILABLE = IS_BROWSER_ENV && 'caches' in self;
35
+ const IS_WEBGPU_AVAILABLE = typeof navigator !== 'undefined' && 'gpu' in navigator;
36
+
37
+ const IS_PROCESS_AVAILABLE = typeof process !== 'undefined';
38
+ const IS_NODE_ENV = IS_PROCESS_AVAILABLE && process?.release?.name === 'node';
39
+ const IS_FS_AVAILABLE = !isEmpty(fs);
40
+ const IS_PATH_AVAILABLE = !isEmpty(path);
41
+
42
+ /**
43
+ * A read-only object containing information about the APIs available in the current environment.
44
+ */
45
+ export const apis = Object.freeze({
46
+ /** Whether we are running in a browser environment */
47
+ IS_BROWSER_ENV,
48
+
49
+ /** Whether we are running in a web worker environment */
50
+ IS_WEBWORKER_ENV,
51
+
52
+ /** Whether the Cache API is available */
53
+ IS_WEB_CACHE_AVAILABLE,
54
+
55
+ /** Whether the WebGPU API is available */
56
+ IS_WEBGPU_AVAILABLE,
57
+
58
+ /** Whether the Node.js process API is available */
59
+ IS_PROCESS_AVAILABLE,
60
+
61
+ /** Whether we are running in a Node.js environment */
62
+ IS_NODE_ENV,
63
+
64
+ /** Whether the filesystem API is available */
65
+ IS_FS_AVAILABLE,
66
+
67
+ /** Whether the path API is available */
68
+ IS_PATH_AVAILABLE,
69
+ });
70
+
71
+ const RUNNING_LOCALLY = IS_FS_AVAILABLE && IS_PATH_AVAILABLE;
72
+ const __dirname = RUNNING_LOCALLY
73
+ ? path.dirname(path.dirname(url.fileURLToPath(import.meta.url)))
74
+ : './';
75
+
76
+ // Only used for environments with access to file system
77
+ const DEFAULT_CACHE_DIR = RUNNING_LOCALLY
78
+ ? path.join(__dirname, '/.cache/')
79
+ : null;
80
+
81
+ // Set local model path, based on available APIs
82
+ const DEFAULT_LOCAL_MODEL_PATH = '/models/';
83
+ const localModelPath = RUNNING_LOCALLY
84
+ ? path.join(__dirname, DEFAULT_LOCAL_MODEL_PATH)
85
+ : DEFAULT_LOCAL_MODEL_PATH;
86
+
87
+ /**
88
+ * Global variable given visible to users to control execution. This provides users a simple way to configure Transformers.js.
89
+ * @typedef {Object} TransformersEnvironment
90
+ * @property {string} version This version of Transformers.js.
91
+ * @property {Object} backends Expose environment variables of different backends,
92
+ * allowing users to set these variables if they want to.
93
+ * @property {boolean} allowRemoteModels Whether to allow loading of remote files, defaults to `true`.
94
+ * If set to `false`, it will have the same effect as setting `local_files_only=true` when loading pipelines, models, tokenizers, processors, etc.
95
+ * @property {string} remoteHost Host URL to load models from. Defaults to the Hugging Face Hub.
96
+ * @property {string} remotePathTemplate Path template to fill in and append to `remoteHost` when loading models.
97
+ * @property {boolean} allowLocalModels Whether to allow loading of local files, defaults to `false` if running in-browser, and `true` otherwise.
98
+ * If set to `false`, it will skip the local file check and try to load the model from the remote host.
99
+ * @property {string} localModelPath Path to load local models from. Defaults to `/models/`.
100
+ * @property {boolean} useFS Whether to use the file system to load files. By default, it is `true` if available.
101
+ * @property {boolean} useBrowserCache Whether to use Cache API to cache models. By default, it is `true` if available.
102
+ * @property {boolean} useFSCache Whether to use the file system to cache files. By default, it is `true` if available.
103
+ * @property {string} cacheDir The directory to use for caching files with the file system. By default, it is `./.cache`.
104
+ * @property {boolean} useCustomCache Whether to use a custom cache system (defined by `customCache`), defaults to `false`.
105
+ * @property {Object} customCache The custom cache to use. Defaults to `null`. Note: this must be an object which
106
+ * implements the `match` and `put` functions of the Web Cache API. For more information, see https://developer.mozilla.org/en-US/docs/Web/API/Cache
107
+ */
108
+
109
+ /** @type {TransformersEnvironment} */
110
+ export const env = {
111
+ version: VERSION,
112
+
113
+ /////////////////// Backends settings ///////////////////
114
+ // NOTE: These will be populated later by the backends themselves.
115
+ backends: {
116
+ // onnxruntime-web/onnxruntime-node
117
+ onnx: {},
118
+
119
+ // TensorFlow.js
120
+ tfjs: {},
121
+ },
122
+
123
+
124
+ /////////////////// Model settings ///////////////////
125
+ allowRemoteModels: true,
126
+ remoteHost: 'https://huggingface.co/',
127
+ remotePathTemplate: '{model}/resolve/{revision}/',
128
+
129
+ allowLocalModels: !IS_BROWSER_ENV,
130
+ localModelPath: localModelPath,
131
+ useFS: IS_FS_AVAILABLE,
132
+
133
+ /////////////////// Cache settings ///////////////////
134
+ useBrowserCache: IS_WEB_CACHE_AVAILABLE,
135
+
136
+ useFSCache: IS_FS_AVAILABLE,
137
+ cacheDir: DEFAULT_CACHE_DIR,
138
+
139
+ useCustomCache: false,
140
+ customCache: null,
141
+ //////////////////////////////////////////////////////
142
+ }
143
+
144
+
145
+ /**
146
+ * @param {Object} obj
147
+ * @private
148
+ */
149
+ function isEmpty(obj) {
150
+ return Object.keys(obj).length === 0;
151
+ }
152
+
@@ -0,0 +1,381 @@
1
+
2
+ /**
3
+ * @module generation/configuration_utils
4
+ */
5
+
6
+ import { pick } from "../utils/core.js";
7
+
8
+ /**
9
+ * Class that holds a configuration for a generation task.
10
+ */
11
+ export class GenerationConfig {
12
+ // Parameters that control the length of the output
13
+ /**
14
+ * The maximum length the generated tokens can have.
15
+ * Corresponds to the length of the input prompt + `max_new_tokens`.
16
+ * Its effect is overridden by `max_new_tokens`, if also set.
17
+ * @type {number}
18
+ * @default 20
19
+ */
20
+ max_length = 20;
21
+
22
+ /**
23
+ * The maximum numbers of tokens to generate, ignoring the number of tokens in the prompt.
24
+ * @type {number}
25
+ * @default null
26
+ */
27
+ max_new_tokens = null;
28
+
29
+ /**
30
+ * The minimum length of the sequence to be generated.
31
+ * Corresponds to the length of the input prompt + `min_new_tokens`.
32
+ * Its effect is overridden by `min_new_tokens`, if also set.
33
+ * @type {number}
34
+ * @default 0
35
+ */
36
+ min_length = 0;
37
+
38
+ /**
39
+ * The minimum numbers of tokens to generate, ignoring the number of tokens in the prompt.
40
+ * @type {number}
41
+ * @default null
42
+ */
43
+ min_new_tokens = null;
44
+
45
+ /**
46
+ * Controls the stopping condition for beam-based methods, like beam-search. It accepts the following values:
47
+ * - `true`, where the generation stops as soon as there are `num_beams` complete candidates;
48
+ * - `false`, where an heuristic is applied and the generation stops when is it very unlikely to find better candidates;
49
+ * - `"never"`, where the beam search procedure only stops when there cannot be better candidates (canonical beam search algorithm).
50
+ * @type {boolean|"never"}
51
+ * @default false
52
+ */
53
+ early_stopping = false;
54
+
55
+ /**
56
+ * The maximum amount of time you allow the computation to run for in seconds.
57
+ * Generation will still finish the current pass after allocated time has been passed.
58
+ * @type {number}
59
+ * @default null
60
+ */
61
+ max_time = null;
62
+
63
+ // Parameters that control the generation strategy used
64
+ /**
65
+ * Whether or not to use sampling; use greedy decoding otherwise.
66
+ * @type {boolean}
67
+ * @default false
68
+ */
69
+ do_sample = false;
70
+
71
+ /**
72
+ * Number of beams for beam search. 1 means no beam search.
73
+ * @type {number}
74
+ * @default 1
75
+ */
76
+ num_beams = 1;
77
+
78
+ /**
79
+ * Number of groups to divide `num_beams` into in order to ensure diversity among different groups of beams.
80
+ * See [this paper](https://arxiv.org/pdf/1610.02424.pdf) for more details.
81
+ * @type {number}
82
+ * @default 1
83
+ */
84
+ num_beam_groups = 1;
85
+
86
+ /**
87
+ * The values balance the model confidence and the degeneration penalty in contrastive search decoding.
88
+ * @type {number}
89
+ * @default null
90
+ */
91
+ penalty_alpha = null;
92
+
93
+ /**
94
+ * Whether or not the model should use the past last key/values attentions (if applicable to the model) to speed up decoding.
95
+ * @type {boolean}
96
+ * @default true
97
+ */
98
+ use_cache = true;
99
+
100
+ // Parameters for manipulation of the model output logits
101
+ /**
102
+ * The value used to modulate the next token probabilities.
103
+ * @type {number}
104
+ * @default 1.0
105
+ */
106
+ temperature = 1.0;
107
+
108
+ /**
109
+ * The number of highest probability vocabulary tokens to keep for top-k-filtering.
110
+ * @type {number}
111
+ * @default 50
112
+ */
113
+ top_k = 50;
114
+
115
+ /**
116
+ * 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.
117
+ * @type {number}
118
+ * @default 1.0
119
+ */
120
+ top_p = 1.0;
121
+
122
+ /**
123
+ * 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.
124
+ * 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.
125
+ * See [this paper](https://arxiv.org/pdf/2202.00666.pdf) for more details.
126
+ * @type {number}
127
+ * @default 1.0
128
+ */
129
+ typical_p = 1.0;
130
+
131
+ /**
132
+ * If set to float strictly between 0 and 1, only tokens with a conditional probability greater than `epsilon_cutoff` will be sampled.
133
+ * In the paper, suggested values range from 3e-4 to 9e-4, depending on the size of the model.
134
+ * See [Truncation Sampling as Language Model Desmoothing](https://arxiv.org/abs/2210.15191) for more details.
135
+ * @type {number}
136
+ * @default 0.0
137
+ */
138
+ epsilon_cutoff = 0.0;
139
+
140
+ /**
141
+ * Eta sampling is a hybrid of locally typical sampling and epsilon sampling.
142
+ * 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)))`.
143
+ * 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.
144
+ * See [Truncation Sampling as Language Model Desmoothing](https://arxiv.org/abs/2210.15191) for more details.
145
+ * @type {number}
146
+ * @default 0.0
147
+ */
148
+ eta_cutoff = 0.0;
149
+
150
+ /**
151
+ * 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.
152
+ * Note that `diversity_penalty` is only effective if `group beam search` is enabled.
153
+ * @type {number}
154
+ * @default 0.0
155
+ */
156
+ diversity_penalty = 0.0;
157
+
158
+ /**
159
+ * The parameter for repetition penalty. 1.0 means no penalty.
160
+ * See [this paper](https://arxiv.org/pdf/1909.05858.pdf) for more details.
161
+ * @type {number}
162
+ * @default 1.0
163
+ */
164
+ repetition_penalty = 1.0;
165
+
166
+ /**
167
+ * The paramater for encoder_repetition_penalty.
168
+ * An exponential penalty on sequences that are not in the original input.
169
+ * 1.0 means no penalty.
170
+ * @type {number}
171
+ * @default 1.0
172
+ */
173
+ encoder_repetition_penalty = 1.0;
174
+
175
+ /**
176
+ * Exponential penalty to the length that is used with beam-based generation.
177
+ * It is applied as an exponent to the sequence length, which in turn is used to divide the score of the sequence.
178
+ * 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.
179
+ * @type {number}
180
+ * @default 1.0
181
+ */
182
+ length_penalty = 1.0;
183
+
184
+ /**
185
+ * If set to int > 0, all ngrams of that size can only occur once.
186
+ * @type {number}
187
+ * @default 0
188
+ */
189
+ no_repeat_ngram_size = 0;
190
+
191
+ /**
192
+ * List of token ids that are not allowed to be generated.
193
+ * In order to get the token ids of the words that should not appear in the generated text, use
194
+ * `tokenizer(bad_words, { add_prefix_space: true, add_special_tokens: false }).input_ids`.
195
+ * @type {number[][]}
196
+ * @default null
197
+ */
198
+ bad_words_ids = null;
199
+
200
+ /**
201
+ * List of token ids that must be generated.
202
+ * If given a `number[][]`, this is treated as a simple list of words that must be included, the opposite to `bad_words_ids`.
203
+ * If given `number[][][]`, this triggers a [disjunctive constraint](https://github.com/huggingface/transformers/issues/14081), where one can allow different forms of each word.
204
+ * @type {number[][]|number[][][]}
205
+ * @default null
206
+ */
207
+ force_words_ids = null;
208
+
209
+ /**
210
+ * Whether to renormalize the logits after applying all the logits processors or warpers (including the custom ones).
211
+ * 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.
212
+ * @type {boolean}
213
+ * @default false
214
+ */
215
+ renormalize_logits = false;
216
+
217
+ /**
218
+ * 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.
219
+ * @type {Object[]}
220
+ * @default null
221
+ */
222
+ constraints = null;
223
+
224
+ /**
225
+ * The id of the token to force as the first generated token after the `decoder_start_token_id`.
226
+ * Useful for multilingual models like mBART where the first generated token needs to be the target language token.
227
+ * @type {number}
228
+ * @default null
229
+ */
230
+ forced_bos_token_id = null;
231
+
232
+ /**
233
+ * The id of the token to force as the last generated token when `max_length` is reached.
234
+ * Optionally, use a list to set multiple *end-of-sequence* tokens.
235
+ * @type {number|number[]}
236
+ * @default null
237
+ */
238
+ forced_eos_token_id = null;
239
+
240
+ /**
241
+ * 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.
242
+ * @type {boolean}
243
+ */
244
+ remove_invalid_values = false;
245
+
246
+ /**
247
+ * This Tuple adds an exponentially increasing length penalty, after a certain amount of tokens have been generated.
248
+ * 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.
249
+ * @type {[number, number]}
250
+ * @default null
251
+ */
252
+ exponential_decay_length_penalty = null;
253
+
254
+ /**
255
+ * A list of tokens that will be suppressed at generation.
256
+ * The `SuppressTokens` logit processor will set their log probs to `-inf` so that they are not sampled.
257
+ * @type {number[]}
258
+ * @default null
259
+ */
260
+ suppress_tokens = null;
261
+
262
+ /**
263
+ * A list of tokens that will be suppressed at the beginning of the generation.
264
+ * The `SuppressBeginTokens` logit processor will set their log probs to `-inf` so that they are not sampled.
265
+ * @type {number[]}
266
+ * @default null
267
+ */
268
+ begin_suppress_tokens = null;
269
+
270
+ /**
271
+ * A list of pairs of integers which indicates a mapping from generation indices to token indices that will be forced before sampling.
272
+ * For example, `[[1, 123]]` means the second generated token will always be a token of index 123.
273
+ * @type {[number, number][]}
274
+ * @default null
275
+ */
276
+ forced_decoder_ids = null;
277
+
278
+ /**
279
+ * The guidance scale for classifier free guidance (CFG). CFG is enabled by setting `guidance_scale > 1`.
280
+ * Higher guidance scale encourages the model to generate samples that are more closely linked to the input
281
+ * prompt, usually at the expense of poorer quality.
282
+ * @type {number}
283
+ * @default null
284
+ */
285
+ guidance_scale = null;
286
+
287
+ // Parameters that define the output variables of `generate`
288
+ /**
289
+ * The number of independently computed returned sequences for each element in the batch.
290
+ * @type {number}
291
+ * @default 1
292
+ */
293
+ num_return_sequences = 1;
294
+
295
+ /**
296
+ * Whether or not to return the attentions tensors of all attention layers.
297
+ * See `attentions` under returned tensors for more details.
298
+ * @type {boolean}
299
+ * @default false
300
+ */
301
+ output_attentions = false;
302
+
303
+ /**
304
+ * Whether or not to return the hidden states of all layers.
305
+ * See `hidden_states` under returned tensors for more details.
306
+ * @type {boolean}
307
+ * @default false
308
+ */
309
+ output_hidden_states = false;
310
+
311
+ /**
312
+ * Whether or not to return the prediction scores.
313
+ * See `scores` under returned tensors for more details.
314
+ * @type {boolean}
315
+ * @default false
316
+ */
317
+ output_scores = false;
318
+
319
+ /**
320
+ * Whether or not to return a `ModelOutput` instead of a plain tuple.
321
+ * @type {boolean}
322
+ * @default false
323
+ */
324
+ return_dict_in_generate = false;
325
+
326
+ // Special tokens that can be used at generation time
327
+ /**
328
+ * The id of the *padding* token.
329
+ * @type {number}
330
+ * @default null
331
+ */
332
+ pad_token_id = null;
333
+
334
+ /**
335
+ * The id of the *beginning-of-sequence* token.
336
+ * @type {number}
337
+ * @default null
338
+ */
339
+ bos_token_id = null;
340
+
341
+ /**
342
+ * The id of the *end-of-sequence* token.
343
+ * Optionally, use a list to set multiple *end-of-sequence* tokens.
344
+ * @type {number|number[]}
345
+ * @default null
346
+ */
347
+ eos_token_id = null;
348
+
349
+ // Generation parameters exclusive to encoder-decoder models
350
+ /**
351
+ * If set to int > 0, all ngrams of that size that occur in the `encoder_input_ids` cannot occur in the `decoder_input_ids`.
352
+ * @type {number}
353
+ * @default 0
354
+ */
355
+ encoder_no_repeat_ngram_size = 0;
356
+
357
+ /**
358
+ * If an encoder-decoder model starts decoding with a different token than *bos*, the id of that token.
359
+ * @type {number}
360
+ * @default null
361
+ */
362
+ decoder_start_token_id = null;
363
+
364
+ // Wild card
365
+ /**
366
+ * Additional generation kwargs will be forwarded to the `generate` function of the model.
367
+ * Kwargs that are not present in `generate`'s signature will be used in the model forward pass.
368
+ * @type {Object}
369
+ * @default {}
370
+ */
371
+ generation_kwargs = {};
372
+
373
+ /**
374
+ *
375
+ * @param {GenerationConfig|import('../configs.js').PretrainedConfig} config
376
+ */
377
+ constructor(config) {
378
+ Object.assign(this, pick(config, Object.getOwnPropertyNames(this)));
379
+ }
380
+ }
381
+