@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
@@ -0,0 +1,354 @@
1
+ declare const LogitsProcessor_base: new () => {
2
+ (...args: any[]): any;
3
+ _call(...args: any[]): any;
4
+ };
5
+ /**
6
+ * Abstract base class for all logit processors that can be applied during generation.
7
+ */
8
+ export class LogitsProcessor extends LogitsProcessor_base {
9
+ /**
10
+ * Apply the processor to the input logits.
11
+ *
12
+ * @abstract
13
+ * @param {bigint[][]} input_ids The input ids.
14
+ * @param {Tensor} logits The logits to process.
15
+ * @throws {Error} Throws an error if `_call` is not implemented in the subclass.
16
+ */
17
+ _call(input_ids: bigint[][], logits: Tensor): void;
18
+ }
19
+ declare const LogitsWarper_base: new () => {
20
+ (...args: any[]): any;
21
+ _call(...args: any[]): any;
22
+ };
23
+ /**
24
+ * Abstract base class for all logit warpers that can be applied during generation with multinomial sampling.
25
+ */
26
+ export class LogitsWarper extends LogitsWarper_base {
27
+ /**
28
+ * Apply the processor to the input logits.
29
+ *
30
+ * @abstract
31
+ * @param {bigint[][]} input_ids The input ids.
32
+ * @param {Tensor} logits The logits to process.
33
+ * @throws {Error} Throws an error if `_call` is not implemented in the subclass.
34
+ */
35
+ _call(input_ids: bigint[][], logits: Tensor): void;
36
+ }
37
+ declare const LogitsProcessorList_base: new () => {
38
+ (...args: any[]): any;
39
+ _call(...args: any[]): any;
40
+ };
41
+ /**
42
+ * A class representing a list of logits processors. A logits processor is a function that modifies the logits
43
+ * output of a language model. This class provides methods for adding new processors and applying all processors to a
44
+ * batch of logits.
45
+ */
46
+ export class LogitsProcessorList extends LogitsProcessorList_base {
47
+ processors: any[];
48
+ /**
49
+ * Adds a new logits processor to the list.
50
+ *
51
+ * @param {LogitsProcessor} item The logits processor function to add.
52
+ */
53
+ push(item: LogitsProcessor): void;
54
+ /**
55
+ * Adds multiple logits processors to the list.
56
+ *
57
+ * @param {LogitsProcessor[]} items The logits processor functions to add.
58
+ */
59
+ extend(items: LogitsProcessor[]): void;
60
+ /**
61
+ * Applies all logits processors in the list to a batch of logits, modifying them in-place.
62
+ *
63
+ * @param {bigint[][]} input_ids The input IDs for the language model.
64
+ * @param {Tensor} logits
65
+ */
66
+ _call(input_ids: bigint[][], logits: Tensor): Tensor;
67
+ [Symbol.iterator](): IterableIterator<any>;
68
+ }
69
+ /**
70
+ * A LogitsProcessor that forces a BOS token at the beginning of the generated sequence.
71
+ */
72
+ export class ForcedBOSTokenLogitsProcessor extends LogitsProcessor {
73
+ /**
74
+ * Create a ForcedBOSTokenLogitsProcessor.
75
+ * @param {number} bos_token_id The ID of the beginning-of-sequence token to be forced.
76
+ */
77
+ constructor(bos_token_id: number);
78
+ bos_token_id: number;
79
+ /**
80
+ * Apply the BOS token forcing to the logits.
81
+ * @param {bigint[][]} input_ids The input IDs.
82
+ * @param {Tensor} logits The logits.
83
+ * @returns {Object} The logits with BOS token forcing.
84
+ */
85
+ _call(input_ids: bigint[][], logits: Tensor): any;
86
+ }
87
+ /**
88
+ * A logits processor that enforces the specified token as the last generated token when `max_length` is reached.
89
+ */
90
+ export class ForcedEOSTokenLogitsProcessor extends LogitsProcessor {
91
+ /**
92
+ * Create a ForcedEOSTokenLogitsProcessor.
93
+ * @param {number} max_length The maximum length of the sequence to be generated.
94
+ * @param {number|number[]} eos_token_id The id(s) of the *end-of-sequence* token.
95
+ */
96
+ constructor(max_length: number, eos_token_id: number | number[]);
97
+ max_length: number;
98
+ eos_token_id: number[];
99
+ /**
100
+ * Apply the processor to input_ids and logits.
101
+ *
102
+ * @param {bigint[][]} input_ids The input ids.
103
+ * @param {Tensor} logits The logits tensor.
104
+ */
105
+ _call(input_ids: bigint[][], logits: Tensor): Tensor;
106
+ }
107
+ /**
108
+ * A LogitsProcessor that suppresses a list of tokens as soon as the `generate` function starts
109
+ * generating using `begin_index` tokens. This should ensure that the tokens defined by
110
+ * `begin_suppress_tokens` at not sampled at the begining of the generation.
111
+ */
112
+ export class SuppressTokensAtBeginLogitsProcessor extends LogitsProcessor {
113
+ /**
114
+ * Create a SuppressTokensAtBeginLogitsProcessor.
115
+ * @param {number[]} begin_suppress_tokens The IDs of the tokens to suppress.
116
+ * @param {number} begin_index The number of tokens to generate before suppressing tokens.
117
+ */
118
+ constructor(begin_suppress_tokens: number[], begin_index: number);
119
+ begin_suppress_tokens: number[];
120
+ begin_index: number;
121
+ /**
122
+ * Apply the BOS token forcing to the logits.
123
+ * @param {bigint[][]} input_ids The input IDs.
124
+ * @param {Tensor} logits The logits.
125
+ * @returns {Object} The logits with BOS token forcing.
126
+ */
127
+ _call(input_ids: bigint[][], logits: Tensor): any;
128
+ }
129
+ /**
130
+ * A LogitsProcessor that handles adding timestamps to generated text.
131
+ */
132
+ export class WhisperTimeStampLogitsProcessor extends LogitsProcessor {
133
+ /**
134
+ * Constructs a new WhisperTimeStampLogitsProcessor.
135
+ * @param {import('../models/whisper/generation_whisper.js').WhisperGenerationConfig} generate_config The config object passed to the `generate()` method of a transformer model.
136
+ * @param {number[]} init_tokens The initial tokens of the input sequence.
137
+ */
138
+ constructor(generate_config: import('../models/whisper/generation_whisper.js').WhisperGenerationConfig, init_tokens: number[]);
139
+ eos_token_id: number;
140
+ no_timestamps_token_id: number;
141
+ timestamp_begin: number;
142
+ begin_index: number;
143
+ max_initial_timestamp_index: number;
144
+ /**
145
+ * Modify the logits to handle timestamp tokens.
146
+ * @param {bigint[][]} input_ids The input sequence of tokens.
147
+ * @param {Tensor} logits The logits output by the model.
148
+ * @returns {Tensor} The modified logits.
149
+ */
150
+ _call(input_ids: bigint[][], logits: Tensor): Tensor;
151
+ }
152
+ /**
153
+ * A logits processor that disallows ngrams of a certain size to be repeated.
154
+ */
155
+ export class NoRepeatNGramLogitsProcessor extends LogitsProcessor {
156
+ /**
157
+ * Create a NoRepeatNGramLogitsProcessor.
158
+ * @param {number} no_repeat_ngram_size The no-repeat-ngram size. All ngrams of this size can only occur once.
159
+ */
160
+ constructor(no_repeat_ngram_size: number);
161
+ no_repeat_ngram_size: number;
162
+ /**
163
+ * Generate n-grams from a sequence of token ids.
164
+ * @param {bigint[]} prevInputIds List of previous input ids
165
+ * @returns {Map<string, number[]>} Map of generated n-grams
166
+ */
167
+ getNgrams(prevInputIds: bigint[]): Map<string, number[]>;
168
+ /**
169
+ * Generate n-grams from a sequence of token ids.
170
+ * @param {Map<string, number[]>} bannedNgrams Map of banned n-grams
171
+ * @param {bigint[]} prevInputIds List of previous input ids
172
+ * @returns {number[]} Map of generated n-grams
173
+ */
174
+ getGeneratedNgrams(bannedNgrams: Map<string, number[]>, prevInputIds: bigint[]): number[];
175
+ /**
176
+ * Calculate banned n-gram tokens
177
+ * @param {bigint[]} prevInputIds List of previous input ids
178
+ * @returns {number[]} Map of generated n-grams
179
+ */
180
+ calcBannedNgramTokens(prevInputIds: bigint[]): number[];
181
+ /**
182
+ * Apply the no-repeat-ngram processor to the logits.
183
+ * @param {bigint[][]} input_ids The input IDs.
184
+ * @param {Tensor} logits The logits.
185
+ * @returns {Object} The logits with no-repeat-ngram processing.
186
+ */
187
+ _call(input_ids: bigint[][], logits: Tensor): any;
188
+ }
189
+ /**
190
+ * A logits processor that penalises repeated output tokens.
191
+ */
192
+ export class RepetitionPenaltyLogitsProcessor extends LogitsProcessor {
193
+ /**
194
+ * Create a RepetitionPenaltyLogitsProcessor.
195
+ * @param {number} penalty The penalty to apply for repeated tokens.
196
+ */
197
+ constructor(penalty: number);
198
+ penalty: number;
199
+ /**
200
+ * Apply the repetition penalty to the logits.
201
+ * @param {bigint[][]} input_ids The input IDs.
202
+ * @param {Tensor} logits The logits.
203
+ * @returns {Object} The logits with repetition penalty processing.
204
+ */
205
+ _call(input_ids: bigint[][], logits: Tensor): any;
206
+ }
207
+ /**
208
+ * A logits processor that enforces a minimum number of tokens.
209
+ */
210
+ export class MinLengthLogitsProcessor extends LogitsProcessor {
211
+ /**
212
+ * Create a MinLengthLogitsProcessor.
213
+ * @param {number} min_length The minimum length below which the score of `eos_token_id` is set to negative infinity.
214
+ * @param {number|number[]} eos_token_id The ID/IDs of the end-of-sequence token.
215
+ */
216
+ constructor(min_length: number, eos_token_id: number | number[]);
217
+ min_length: number;
218
+ eos_token_id: number[];
219
+ /**
220
+ * Apply logit processor.
221
+ * @param {bigint[][]} input_ids The input IDs.
222
+ * @param {Tensor} logits The logits.
223
+ * @returns {Object} The processed logits.
224
+ */
225
+ _call(input_ids: bigint[][], logits: Tensor): any;
226
+ }
227
+ /**
228
+ * A logits processor that enforces a minimum number of new tokens.
229
+ */
230
+ export class MinNewTokensLengthLogitsProcessor extends LogitsProcessor {
231
+ /**
232
+ * Create a MinNewTokensLengthLogitsProcessor.
233
+ * @param {number} prompt_length_to_skip The input tokens length.
234
+ * @param {number} min_new_tokens The minimum *new* tokens length below which the score of `eos_token_id` is set to negative infinity.
235
+ * @param {number|number[]} eos_token_id The ID/IDs of the end-of-sequence token.
236
+ */
237
+ constructor(prompt_length_to_skip: number, min_new_tokens: number, eos_token_id: number | number[]);
238
+ prompt_length_to_skip: number;
239
+ min_new_tokens: number;
240
+ eos_token_id: number[];
241
+ /**
242
+ * Apply logit processor.
243
+ * @param {bigint[][]} input_ids The input IDs.
244
+ * @param {Tensor} logits The logits.
245
+ * @returns {Object} The processed logits.
246
+ */
247
+ _call(input_ids: bigint[][], logits: Tensor): any;
248
+ }
249
+ export class NoBadWordsLogitsProcessor extends LogitsProcessor {
250
+ /**
251
+ * Create a `NoBadWordsLogitsProcessor`.
252
+ * @param {number[][]} bad_words_ids List of list of token ids that are not allowed to be generated.
253
+ * @param {number|number[]} eos_token_id The id of the *end-of-sequence* token. Optionally, use a list to set multiple *end-of-sequence* tokens.
254
+ */
255
+ constructor(bad_words_ids: number[][], eos_token_id: number | number[]);
256
+ bad_words_ids: number[][];
257
+ eos_token_id: number[];
258
+ /**
259
+ * Apply logit processor.
260
+ * @param {bigint[][]} input_ids The input IDs.
261
+ * @param {Tensor} logits The logits.
262
+ * @returns {Object} The processed logits.
263
+ */
264
+ _call(input_ids: bigint[][], logits: Tensor): any;
265
+ }
266
+ /**
267
+ * [`LogitsProcessor`] for classifier free guidance (CFG). The scores are split over the batch dimension,
268
+ * where the first half correspond to the conditional logits (predicted from the input prompt) and the second half
269
+ * correspond to the unconditional logits (predicted from an empty or 'null' prompt). The processor computes a
270
+ * weighted average across the conditional and unconditional logits, parameterised by the `guidance_scale`.
271
+ *
272
+ * See [the paper](https://arxiv.org/abs/2306.05284) for more information.
273
+ */
274
+ export class ClassifierFreeGuidanceLogitsProcessor extends LogitsProcessor {
275
+ /**
276
+ * Create a `ClassifierFreeGuidanceLogitsProcessor`.
277
+ * @param {number} guidance_scale The guidance scale for classifier free guidance (CFG). CFG is enabled by setting `guidance_scale > 1`.
278
+ * Higher guidance scale encourages the model to generate samples that are more closely linked to the input
279
+ * prompt, usually at the expense of poorer quality.
280
+ */
281
+ constructor(guidance_scale: number);
282
+ guidance_scale: number;
283
+ /**
284
+ * Apply logit processor.
285
+ * @param {bigint[][]} input_ids The input IDs.
286
+ * @param {Tensor} logits The logits.
287
+ * @returns {Object} The processed logits.
288
+ */
289
+ _call(input_ids: bigint[][], logits: Tensor): any;
290
+ }
291
+ /**
292
+ * [`LogitsWarper`] for temperature (exponential scaling output probability distribution), which effectively means
293
+ * that it can control the randomness of the predicted tokens. Often used together with [`TopPLogitsWarper`] and [`TopKLogitsWarper`].
294
+ */
295
+ export class TemperatureLogitsWarper extends LogitsWarper {
296
+ /**
297
+ * Create a `TemperatureLogitsWarper`.
298
+ * @param {number} temperature Strictly positive float value used to modulate the logits distribution.
299
+ * A value smaller than `1` decreases randomness (and vice versa), with `0` being equivalent to shifting
300
+ * all probability mass to the most likely token.
301
+ */
302
+ constructor(temperature: number);
303
+ temperature: number;
304
+ /**
305
+ * Apply logit warper.
306
+ * @param {bigint[][]} input_ids The input IDs.
307
+ * @param {Tensor} logits The logits.
308
+ * @returns {Object} The processed logits.
309
+ */
310
+ _call(input_ids: bigint[][], logits: Tensor): any;
311
+ }
312
+ /**
313
+ * [`LogitsWarper`] that performs top-p, i.e. restricting to top tokens summing to prob_cut_off <= prob_cut_off.
314
+ * Often used together with [`TemperatureLogitsWarper`] and [`TopKLogitsWarper`].
315
+ */
316
+ export class TopPLogitsWarper extends LogitsWarper {
317
+ /**
318
+ * Create a `TopPLogitsWarper`.
319
+ * @param {number} top_p If set to < 1, only the smallest set of most probable tokens with
320
+ * probabilities that add up to `top_p` or higher are kept for generation.
321
+ * @param {Object} options Additional options for the top-p sampling.
322
+ * @param {number} [options.filter_value=-Infinity] All filtered values will be set to this float value.
323
+ * @param {number} [options.min_tokens_to_keep=1] Minimum number of tokens that cannot be filtered.
324
+ */
325
+ constructor(top_p: number, { filter_value, min_tokens_to_keep, }?: {
326
+ filter_value?: number;
327
+ min_tokens_to_keep?: number;
328
+ });
329
+ top_p: number;
330
+ filter_value: number;
331
+ min_tokens_to_keep: number;
332
+ }
333
+ /**
334
+ * [`LogitsWarper`] that performs top-k, i.e. restricting to the k highest probability elements.
335
+ * Often used together with [`TemperatureLogitsWarper`] and [`TopPLogitsWarper`].
336
+ */
337
+ export class TopKLogitsWarper extends LogitsWarper {
338
+ /**
339
+ * Create a `TopKLogitsWarper`.
340
+ * @param {number} top_k If set to > 0, only the top `top_k` tokens are kept for generation.
341
+ * @param {Object} options Additional options for the top-k sampling.
342
+ * @param {number} [options.filter_value=-Infinity] All filtered values will be set to this float value.
343
+ * @param {number} [options.min_tokens_to_keep=1] Minimum number of tokens that cannot be filtered.
344
+ */
345
+ constructor(top_k: number, { filter_value, min_tokens_to_keep, }?: {
346
+ filter_value?: number;
347
+ min_tokens_to_keep?: number;
348
+ });
349
+ top_k: number;
350
+ filter_value: number;
351
+ }
352
+ import { Tensor } from "../utils/tensor.js";
353
+ export {};
354
+ //# sourceMappingURL=logits_process.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logits_process.d.ts","sourceRoot":"","sources":["../../src/generation/logits_process.js"],"names":[],"mappings":"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"}
@@ -0,0 +1,51 @@
1
+ declare const LogitsSampler_base: new () => {
2
+ (...args: any[]): any;
3
+ _call(...args: any[]): any;
4
+ };
5
+ /**
6
+ * Sampler is a base class for all sampling methods used for text generation.
7
+ */
8
+ export class LogitsSampler extends LogitsSampler_base {
9
+ /**
10
+ * Returns a Sampler object based on the specified options.
11
+ * @param {GenerationConfig} generation_config An object containing options for the sampler.
12
+ * @returns {LogitsSampler} A Sampler object.
13
+ */
14
+ static getSampler(generation_config: GenerationConfig): LogitsSampler;
15
+ /**
16
+ * Creates a new Sampler object with the specified generation config.
17
+ * @param {GenerationConfig} generation_config The generation config.
18
+ */
19
+ constructor(generation_config: GenerationConfig);
20
+ generation_config: GenerationConfig;
21
+ /**
22
+ * Executes the sampler, using the specified logits.
23
+ * @param {Tensor} logits
24
+ * @returns {Promise<[bigint, number][]>}
25
+ */
26
+ _call(logits: Tensor): Promise<[bigint, number][]>;
27
+ /**
28
+ * Abstract method for sampling the logits.
29
+ * @param {Tensor} logits
30
+ * @throws {Error} If not implemented in subclass.
31
+ * @returns {Promise<[bigint, number][]>}
32
+ */
33
+ sample(logits: Tensor): Promise<[bigint, number][]>;
34
+ /**
35
+ * Returns the specified logits as an array, with temperature applied.
36
+ * @param {Tensor} logits
37
+ * @param {number} index
38
+ * @returns {Float32Array}
39
+ */
40
+ getLogits(logits: Tensor, index: number): Float32Array;
41
+ /**
42
+ * Selects an item randomly based on the specified probabilities.
43
+ * @param {import("../transformers.js").DataArray} probabilities An array of probabilities to use for selection.
44
+ * @returns {number} The index of the selected item.
45
+ */
46
+ randomSelect(probabilities: import("../transformers.js").DataArray): number;
47
+ }
48
+ import { GenerationConfig } from '../generation/configuration_utils.js';
49
+ import { Tensor } from "../utils/tensor.js";
50
+ export {};
51
+ //# sourceMappingURL=logits_sampler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logits_sampler.d.ts","sourceRoot":"","sources":["../../src/generation/logits_sampler.js"],"names":[],"mappings":";;;;AAcA;;GAEG;AACH;IAyEI;;;;OAIG;IACH,qCAHW,gBAAgB,GACd,aAAa,CAwBzB;IAnGD;;;OAGG;IACH,+BAFW,gBAAgB,EAK1B;IADG,oCAA0C;IAG9C;;;;OAIG;IACH,cAHW,MAAM,GACJ,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC,CAMvC;IAED;;;;;OAKG;IACH,eAJW,MAAM,GAEJ,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC,CAIvC;IAED;;;;;OAKG;IACH,kBAJW,MAAM,SACN,MAAM,GACJ,YAAY,CAcxB;IAED;;;;OAIG;IACH,4BAHW,OAAO,oBAAoB,EAAE,SAAS,GACpC,MAAM,CAiBlB;CA8BJ;iCA1GgC,sCAAsC;uBAN1C,oBAAoB"}
@@ -0,0 +1,47 @@
1
+ type GenerationFunctionParameters = {
2
+ /**
3
+ * (`Tensor` of varying shape depending on the modality, *optional*):
4
+ * The sequence used as a prompt for the generation or as model inputs to the encoder. If `null` the
5
+ * method initializes it with `bos_token_id` and a batch size of 1. For decoder-only models `inputs`
6
+ * should be in the format of `input_ids`. For encoder-decoder models *inputs* can represent any of
7
+ * `input_ids`, `input_values`, `input_features`, or `pixel_values`.
8
+ */
9
+ inputs?: import('../utils/tensor.js').Tensor;
10
+ /**
11
+ * (`GenerationConfig`, *optional*):
12
+ * The generation configuration to be used as base parametrization for the generation call.
13
+ * `**kwargs` passed to generate matching the attributes of `generation_config` will override them.
14
+ * If `generation_config` is not provided, the default will be used, which has the following loading
15
+ * priority:
16
+ * - (1) from the `generation_config.json` model file, if it exists;
17
+ * - (2) from the model configuration. Please note that unspecified parameters will inherit [`GenerationConfig`]'s
18
+ * default values, whose documentation should be checked to parameterize generation.
19
+ */
20
+ generation_config?: import('./configuration_utils.js').GenerationConfig;
21
+ /**
22
+ * (`LogitsProcessorList`, *optional*):
23
+ * Custom logits processors that complement the default logits processors built from arguments and
24
+ * generation config. If a logit processor is passed that is already created with the arguments or a
25
+ * generation config an error is thrown. This feature is intended for advanced users.
26
+ */
27
+ logits_processor?: import('./logits_process.js').LogitsProcessorList;
28
+ /**
29
+ * (`StoppingCriteriaList`, *optional*):
30
+ * Custom stopping criteria that complements the default stopping criteria built from arguments and a
31
+ * generation config. If a stopping criteria is passed that is already created with the arguments or a
32
+ * generation config an error is thrown. This feature is intended for advanced users.
33
+ */
34
+ stopping_criteria?: import('./stopping_criteria.js').StoppingCriteriaList;
35
+ /**
36
+ * (`BaseStreamer`, *optional*):
37
+ * Streamer object that will be used to stream the generated sequences. Generated tokens are passed
38
+ * through `streamer.put(token_ids)` and the streamer is responsible for any further processing.
39
+ */
40
+ streamer?: import('./streamers.js').BaseStreamer;
41
+ /**
42
+ * (`number[]`, *optional*):
43
+ * If the model is an encoder-decoder model, this argument is used to pass the `decoder_input_ids`.
44
+ */
45
+ decoder_input_ids?: number[];
46
+ };
47
+ //# sourceMappingURL=parameters.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parameters.d.ts","sourceRoot":"","sources":["../../src/generation/parameters.js"],"names":[],"mappings":";;;;;;;;aAOc,OAAO,oBAAoB,EAAE,MAAM;;;;;;;;;;;wBAKnC,OAAO,0BAA0B,EAAE,gBAAgB;;;;;;;uBAQnD,OAAO,qBAAqB,EAAE,mBAAmB;;;;;;;wBAIjD,OAAO,wBAAwB,EAAE,oBAAoB;;;;;;eAIrD,OAAO,gBAAgB,EAAE,YAAY;;;;;wBAGrC,MAAM,EAAE"}
@@ -0,0 +1,81 @@
1
+ declare const StoppingCriteria_base: new () => {
2
+ (...args: any[]): any;
3
+ _call(...args: any[]): any;
4
+ };
5
+ /**
6
+ * Abstract base class for all stopping criteria that can be applied during generation.
7
+ */
8
+ export class StoppingCriteria extends StoppingCriteria_base {
9
+ /**
10
+ *
11
+ * @param {number[][]} input_ids (`number[][]` of shape `(batch_size, sequence_length)`):
12
+ * Indices of input sequence tokens in the vocabulary.
13
+ * @param {number[][]} scores scores (`number[][]` of shape `(batch_size, config.vocab_size)`):
14
+ * Prediction scores of a language modeling head. These can be scores for each vocabulary token before SoftMax
15
+ * or scores for each vocabulary token after SoftMax.
16
+ * @returns {boolean[]} A list of booleans indicating whether each sequence should be stopped.
17
+ */
18
+ _call(input_ids: number[][], scores: number[][]): boolean[];
19
+ }
20
+ declare const StoppingCriteriaList_base: new () => {
21
+ (...args: any[]): any;
22
+ _call(...args: any[]): any;
23
+ };
24
+ /**
25
+ */
26
+ export class StoppingCriteriaList extends StoppingCriteriaList_base {
27
+ criteria: any[];
28
+ /**
29
+ * Adds a new stopping criterion to the list.
30
+ *
31
+ * @param {StoppingCriteria} item The stopping criterion to add.
32
+ */
33
+ push(item: StoppingCriteria): void;
34
+ /**
35
+ * Adds multiple stopping criteria to the list.
36
+ *
37
+ * @param {StoppingCriteria|StoppingCriteriaList|StoppingCriteria[]} items The stopping criteria to add.
38
+ */
39
+ extend(items: StoppingCriteria | StoppingCriteriaList | StoppingCriteria[]): void;
40
+ _call(input_ids: any, scores: any): any[];
41
+ [Symbol.iterator](): IterableIterator<any>;
42
+ }
43
+ /**
44
+ * This class can be used to stop generation whenever the full generated number of tokens exceeds `max_length`.
45
+ * Keep in mind for decoder-only type of transformers, this will include the initial prompted tokens.
46
+ */
47
+ export class MaxLengthCriteria extends StoppingCriteria {
48
+ /**
49
+ *
50
+ * @param {number} max_length The maximum length that the output sequence can have in number of tokens.
51
+ * @param {number} [max_position_embeddings=null] The maximum model length, as defined by the model's `config.max_position_embeddings` attribute.
52
+ */
53
+ constructor(max_length: number, max_position_embeddings?: number);
54
+ max_length: number;
55
+ max_position_embeddings: number;
56
+ _call(input_ids: any): any;
57
+ }
58
+ /**
59
+ * This class can be used to stop generation whenever the "end-of-sequence" token is generated.
60
+ * By default, it uses the `model.generation_config.eos_token_id`.
61
+ */
62
+ export class EosTokenCriteria extends StoppingCriteria {
63
+ /**
64
+ *
65
+ * @param {number|number[]} eos_token_id The id of the *end-of-sequence* token.
66
+ * Optionally, use a list to set multiple *end-of-sequence* tokens.
67
+ */
68
+ constructor(eos_token_id: number | number[]);
69
+ eos_token_id: number[];
70
+ }
71
+ /**
72
+ * This class can be used to stop generation whenever the user interrupts the process.
73
+ */
74
+ export class InterruptableStoppingCriteria extends StoppingCriteria {
75
+ interrupted: boolean;
76
+ interrupt(): void;
77
+ reset(): void;
78
+ _call(input_ids: any, scores: any): any[];
79
+ }
80
+ export {};
81
+ //# sourceMappingURL=stopping_criteria.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stopping_criteria.d.ts","sourceRoot":"","sources":["../../src/generation/stopping_criteria.js"],"names":[],"mappings":";;;;AAUA;;GAEG;AACH;IACI;;;;;;;;OAQG;IACH,iBAPW,MAAM,EAAE,EAAE,UAEV,MAAM,EAAE,EAAE,GAGR,OAAO,EAAE,CAIrB;CACJ;;;;;AACD;GACG;AACH;IAMQ,gBAAkB;IAGtB;;;;OAIG;IACH,WAFW,gBAAgB,QAI1B;IAED;;;;OAIG;IACH,cAFW,gBAAgB,GAAC,oBAAoB,GAAC,gBAAgB,EAAE,QASlE;IAED,0CASC;IAED,2CAEC;CACJ;AAED;;;GAGG;AACH;IAEI;;;;OAIG;IACH,wBAHW,MAAM,4BACN,MAAM,EAMhB;IAFG,mBAA4B;IAC5B,gCAAsD;IAG1D,2BAEC;CACJ;AAID;;;GAGG;AACH;IAEI;;;;OAIG;IACH,0BAHW,MAAM,GAAC,MAAM,EAAE,EASzB;IADG,uBAAgC;CAgBvC;AAED;;GAEG;AACH;IAGQ,qBAAwB;IAG5B,kBAEC;IAED,cAEC;IAED,0CAEC;CACJ"}
@@ -0,0 +1,81 @@
1
+ export class BaseStreamer {
2
+ /**
3
+ * Function that is called by `.generate()` to push new tokens
4
+ * @param {bigint[][]} value
5
+ */
6
+ put(value: bigint[][]): void;
7
+ /**
8
+ * Function that is called by `.generate()` to signal the end of generation
9
+ */
10
+ end(): void;
11
+ }
12
+ /**
13
+ * Simple text streamer that prints the token(s) to stdout as soon as entire words are formed.
14
+ */
15
+ export class TextStreamer extends BaseStreamer {
16
+ /**
17
+ *
18
+ * @param {import('../tokenizers.js').PreTrainedTokenizer} tokenizer
19
+ */
20
+ constructor(tokenizer: import('../tokenizers.js').PreTrainedTokenizer, { skip_prompt, callback_function, token_callback_function, decode_kwargs, ...kwargs }?: {
21
+ skip_prompt?: boolean;
22
+ callback_function?: any;
23
+ token_callback_function?: any;
24
+ decode_kwargs?: {};
25
+ });
26
+ tokenizer: import("../tokenizers.js").PreTrainedTokenizer;
27
+ skip_prompt: boolean;
28
+ callback_function: any;
29
+ token_callback_function: any;
30
+ decode_kwargs: {};
31
+ token_cache: any[];
32
+ print_len: number;
33
+ next_tokens_are_prompt: boolean;
34
+ /**
35
+ * Prints the new text to stdout. If the stream is ending, also prints a newline.
36
+ * @param {string} text
37
+ * @param {boolean} stream_end
38
+ */
39
+ on_finalized_text(text: string, stream_end: boolean): void;
40
+ }
41
+ /**
42
+ * Utility class to handle streaming of tokens generated by whisper speech-to-text models.
43
+ * Callback functions are invoked when each of the following events occur:
44
+ * - A new chunk starts (on_chunk_start)
45
+ * - A new token is generated (callback_function)
46
+ * - A chunk ends (on_chunk_end)
47
+ * - The stream is finalized (on_finalize)
48
+ */
49
+ export class WhisperTextStreamer extends TextStreamer {
50
+ /**
51
+ * @param {import('../tokenizers.js').WhisperTokenizer} tokenizer
52
+ * @param {Object} options
53
+ * @param {boolean} [options.skip_prompt=false] Whether to skip the prompt tokens
54
+ * @param {function(string): void} [options.callback_function=null] Function to call when a piece of text is ready to display
55
+ * @param {function(string): void} [options.token_callback_function=null] Function to call when a new token is generated
56
+ * @param {function(number): void} [options.on_chunk_start=null] Function to call when a new chunk starts
57
+ * @param {function(number): void} [options.on_chunk_end=null] Function to call when a chunk ends
58
+ * @param {function(): void} [options.on_finalize=null] Function to call when the stream is finalized
59
+ * @param {number} [options.time_precision=0.02] Precision of the timestamps
60
+ * @param {boolean} [options.skip_special_tokens=true] Whether to skip special tokens when decoding
61
+ * @param {Object} [options.decode_kwargs={}] Additional keyword arguments to pass to the tokenizer's decode method
62
+ */
63
+ constructor(tokenizer: import('../tokenizers.js').WhisperTokenizer, { skip_prompt, callback_function, token_callback_function, on_chunk_start, on_chunk_end, on_finalize, time_precision, skip_special_tokens, decode_kwargs, }?: {
64
+ skip_prompt?: boolean;
65
+ callback_function?: (arg0: string) => void;
66
+ token_callback_function?: (arg0: string) => void;
67
+ on_chunk_start?: (arg0: number) => void;
68
+ on_chunk_end?: (arg0: number) => void;
69
+ on_finalize?: () => void;
70
+ time_precision?: number;
71
+ skip_special_tokens?: boolean;
72
+ decode_kwargs?: any;
73
+ });
74
+ timestamp_begin: number;
75
+ on_chunk_start: (arg0: number) => void;
76
+ on_chunk_end: (arg0: number) => void;
77
+ on_finalize: () => void;
78
+ time_precision: number;
79
+ waiting_for_timestamp: boolean;
80
+ }
81
+ //# sourceMappingURL=streamers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"streamers.d.ts","sourceRoot":"","sources":["../../src/generation/streamers.js"],"names":[],"mappings":"AASA;IACI;;;OAGG;IACH,WAFW,MAAM,EAAE,EAAE,QAIpB;IAED;;OAEG;IACH,YAEC;CACJ;AAMD;;GAEG;AACH;IACI;;;OAGG;IACH,uBAFW,OAAO,kBAAkB,EAAE,mBAAmB;;;;;OAoBxD;IAVG,0DAA0B;IAC1B,qBAA8B;IAC9B,uBAA0D;IAC1D,6BAAsD;IACtD,kBAAoD;IAGpD,mBAAqB;IACrB,kBAAkB;IAClB,gCAAkC;IA6DtC;;;;OAIG;IACH,wBAHW,MAAM,cACN,OAAO,QASjB;CACJ;AAED;;;;;;;GAOG;AACH;IACI;;;;;;;;;;;;OAYG;IACH,uBAZW,OAAO,kBAAkB,EAAE,gBAAgB;QAEzB,WAAW,GAA7B,OAAO;QAC0B,iBAAiB,UAAzC,MAAM,KAAG,IAAI;QACW,uBAAuB,UAA/C,MAAM,KAAG,IAAI;QACW,cAAc,UAAtC,MAAM,KAAG,IAAI;QACW,YAAY,UAApC,MAAM,KAAG,IAAI;QACK,WAAW,SAA1B,IAAI;QACC,cAAc,GAA/B,MAAM;QACY,mBAAmB,GAArC,OAAO;QACU,aAAa;OA4BxC;IATG,wBAAgD;IAEhD,uBA1BgB,MAAM,KAAG,IAAI,CA0BO;IACpC,qBA1BgB,MAAM,KAAG,IAAI,CA0BG;IAChC,mBA1BmB,IAAI,CA0BO;IAE9B,uBAAoC;IAEpC,+BAAkC;CAiCzC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @param {string} language The language name or code
3
+ * @returns {string} The language code
4
+ */
5
+ export function whisper_language_to_code(language: string): string;
6
+ export const WHISPER_LANGUAGE_MAPPING: Map<any, any>;
7
+ export const WHISPER_TO_LANGUAGE_CODE_MAPPING: Map<any, any>;
8
+ //# sourceMappingURL=common_whisper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common_whisper.d.ts","sourceRoot":"","sources":["../../../src/models/whisper/common_whisper.js"],"names":[],"mappings":"AA4HA;;;GAGG;AACH,mDAHW,MAAM,GACJ,MAAM,CAwBlB;AA7CD,qDAAmE;AAEnE,6DAeG"}