@ohos-ports/sillytavern-transformers 2.17.2-beta.1

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 (59) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +361 -0
  3. package/dist/ort-wasm-simd-threaded.wasm +0 -0
  4. package/dist/ort-wasm-simd.wasm +0 -0
  5. package/dist/ort-wasm-threaded.wasm +0 -0
  6. package/dist/ort-wasm.wasm +0 -0
  7. package/dist/transformers.js +26758 -0
  8. package/dist/transformers.js.map +1 -0
  9. package/dist/transformers.min.js +107 -0
  10. package/dist/transformers.min.js.map +1 -0
  11. package/package.json +85 -0
  12. package/src/backends/onnx.js +50 -0
  13. package/src/configs.js +107 -0
  14. package/src/env.js +128 -0
  15. package/src/models.js +6267 -0
  16. package/src/pipelines.js +3287 -0
  17. package/src/processors.js +2248 -0
  18. package/src/tokenizers.js +4479 -0
  19. package/src/transformers.js +24 -0
  20. package/src/utils/audio.js +672 -0
  21. package/src/utils/core.js +175 -0
  22. package/src/utils/data-structures.js +415 -0
  23. package/src/utils/generation.js +873 -0
  24. package/src/utils/hub.js +658 -0
  25. package/src/utils/image.js +731 -0
  26. package/src/utils/maths.js +985 -0
  27. package/src/utils/tensor.js +1250 -0
  28. package/types/backends/onnx.d.ts +5 -0
  29. package/types/backends/onnx.d.ts.map +1 -0
  30. package/types/configs.d.ts +43 -0
  31. package/types/configs.d.ts.map +1 -0
  32. package/types/env.d.ts +28 -0
  33. package/types/env.d.ts.map +1 -0
  34. package/types/models.d.ts +3661 -0
  35. package/types/models.d.ts.map +1 -0
  36. package/types/pipelines.d.ts +2427 -0
  37. package/types/pipelines.d.ts.map +1 -0
  38. package/types/processors.d.ts +769 -0
  39. package/types/processors.d.ts.map +1 -0
  40. package/types/tokenizers.d.ts +932 -0
  41. package/types/tokenizers.d.ts.map +1 -0
  42. package/types/transformers.d.ts +11 -0
  43. package/types/transformers.d.ts.map +1 -0
  44. package/types/utils/audio.d.ts +121 -0
  45. package/types/utils/audio.d.ts.map +1 -0
  46. package/types/utils/core.d.ts +99 -0
  47. package/types/utils/core.d.ts.map +1 -0
  48. package/types/utils/data-structures.d.ts +224 -0
  49. package/types/utils/data-structures.d.ts.map +1 -0
  50. package/types/utils/generation.d.ts +593 -0
  51. package/types/utils/generation.d.ts.map +1 -0
  52. package/types/utils/hub.d.ts +154 -0
  53. package/types/utils/hub.d.ts.map +1 -0
  54. package/types/utils/image.d.ts +113 -0
  55. package/types/utils/image.d.ts.map +1 -0
  56. package/types/utils/maths.d.ts +280 -0
  57. package/types/utils/maths.d.ts.map +1 -0
  58. package/types/utils/tensor.d.ts +318 -0
  59. package/types/utils/tensor.d.ts.map +1 -0
@@ -0,0 +1,932 @@
1
+ declare const TokenizerModel_base: new () => {
2
+ (...args: any[]): any;
3
+ _call(...args: any[]): any;
4
+ };
5
+ /**
6
+ * Abstract base class for tokenizer models.
7
+ *
8
+ * @extends Callable
9
+ */
10
+ export class TokenizerModel extends TokenizerModel_base {
11
+ /**
12
+ * Instantiates a new TokenizerModel instance based on the configuration object provided.
13
+ * @param {Object} config The configuration object for the TokenizerModel.
14
+ * @param {...*} args Optional arguments to pass to the specific TokenizerModel constructor.
15
+ * @returns {TokenizerModel} A new instance of a TokenizerModel.
16
+ * @throws Will throw an error if the TokenizerModel type in the config is not recognized.
17
+ */
18
+ static fromConfig(config: any, ...args: any[]): TokenizerModel;
19
+ /**
20
+ * Creates a new instance of TokenizerModel.
21
+ * @param {Object} config The configuration object for the TokenizerModel.
22
+ */
23
+ constructor(config: any);
24
+ config: any;
25
+ /** @type {string[]} */
26
+ vocab: string[];
27
+ /**
28
+ * A mapping of tokens to ids.
29
+ * @type {Map<string, number>}
30
+ */
31
+ tokens_to_ids: Map<string, number>;
32
+ unk_token_id: any;
33
+ unk_token: any;
34
+ end_of_word_suffix: any;
35
+ /** @type {boolean} Whether to fuse unknown tokens when encoding. Defaults to false. */
36
+ fuse_unk: boolean;
37
+ /**
38
+ * Internal function to call the TokenizerModel instance.
39
+ * @param {string[]} tokens The tokens to encode.
40
+ * @returns {string[]} The encoded token IDs.
41
+ */
42
+ _call(tokens: string[]): string[];
43
+ /**
44
+ * Encodes a list of tokens into a list of token IDs.
45
+ * @param {string[]} tokens The tokens to encode.
46
+ * @returns {string[]} The encoded tokens.
47
+ * @throws Will throw an error if not implemented in a subclass.
48
+ */
49
+ encode(tokens: string[]): string[];
50
+ /**
51
+ * Converts a list of tokens into a list of token IDs.
52
+ * @param {string[]} tokens The tokens to convert.
53
+ * @returns {number[]} The converted token IDs.
54
+ */
55
+ convert_tokens_to_ids(tokens: string[]): number[];
56
+ /**
57
+ * Converts a list of token IDs into a list of tokens.
58
+ * @param {number[]} ids The token IDs to convert.
59
+ * @returns {string[]} The converted tokens.
60
+ */
61
+ convert_ids_to_tokens(ids: number[]): string[];
62
+ }
63
+ declare const PreTrainedTokenizer_base: new () => {
64
+ (...args: any[]): any;
65
+ _call(...args: any[]): any;
66
+ };
67
+ /**
68
+ * @typedef {Object} Message
69
+ * @property {string} role The role of the message (e.g., "user" or "assistant" or "system").
70
+ * @property {string} content The content of the message.
71
+ */
72
+ export class PreTrainedTokenizer extends PreTrainedTokenizer_base {
73
+ /**
74
+ * Loads a pre-trained tokenizer from the given `pretrained_model_name_or_path`.
75
+ *
76
+ * @param {string} pretrained_model_name_or_path The path to the pre-trained tokenizer.
77
+ * @param {PretrainedTokenizerOptions} options Additional options for loading the tokenizer.
78
+ *
79
+ * @throws {Error} Throws an error if the tokenizer.json or tokenizer_config.json files are not found in the `pretrained_model_name_or_path`.
80
+ * @returns {Promise<PreTrainedTokenizer>} A new instance of the `PreTrainedTokenizer` class.
81
+ */
82
+ static from_pretrained(pretrained_model_name_or_path: string, { progress_callback, config, cache_dir, local_files_only, revision, legacy, }?: PretrainedTokenizerOptions): Promise<PreTrainedTokenizer>;
83
+ /**
84
+ * Create a new PreTrainedTokenizer instance.
85
+ * @param {Object} tokenizerJSON The JSON of the tokenizer.
86
+ * @param {Object} tokenizerConfig The config of the tokenizer.
87
+ */
88
+ constructor(tokenizerJSON: any, tokenizerConfig: any);
89
+ return_token_type_ids: boolean;
90
+ _default_chat_template: string;
91
+ _tokenizer_config: any;
92
+ normalizer: Normalizer;
93
+ pre_tokenizer: PreTokenizer;
94
+ model: TokenizerModel;
95
+ post_processor: PostProcessor;
96
+ decoder: Decoder;
97
+ special_tokens: any[];
98
+ all_special_ids: number[];
99
+ /** @type {AddedToken[]} */
100
+ added_tokens: AddedToken[];
101
+ additional_special_tokens: any;
102
+ added_tokens_regex: RegExp;
103
+ mask_token: string;
104
+ mask_token_id: number;
105
+ pad_token: string;
106
+ pad_token_id: number;
107
+ sep_token: string;
108
+ sep_token_id: number;
109
+ unk_token: string;
110
+ unk_token_id: number;
111
+ model_max_length: any;
112
+ /** @type {boolean} Whether or not to strip the text when tokenizing (removing excess spaces before and after the string). */
113
+ remove_space: boolean;
114
+ clean_up_tokenization_spaces: any;
115
+ do_lowercase_and_remove_accent: any;
116
+ /** @type {'right'|'left'} */
117
+ padding_side: 'right' | 'left';
118
+ legacy: boolean;
119
+ chat_template: any;
120
+ _compiled_template_cache: Map<any, any>;
121
+ /**
122
+ * Returns the value of the first matching key in the tokenizer config object.
123
+ * @param {...string} keys One or more keys to search for in the tokenizer config object.
124
+ * @returns {string|null} The value associated with the first matching key, or null if no match is found.
125
+ * @throws {Error} If an object is found for a matching key and its __type property is not "AddedToken".
126
+ */
127
+ getToken(...keys: string[]): string | null;
128
+ /**
129
+ * @typedef {number[]|number[][]|Tensor} BatchEncodingItem
130
+ *
131
+ * @typedef {Object} BatchEncoding Holds the output of the tokenizer's call function.
132
+ * @property {BatchEncodingItem} input_ids List of token ids to be fed to a model.
133
+ * @property {BatchEncodingItem} attention_mask List of indices specifying which tokens should be attended to by the model.
134
+ * @property {BatchEncodingItem} [token_type_ids] List of token type ids to be fed to a model.
135
+ */
136
+ /**
137
+ * Encode/tokenize the given text(s).
138
+ * @param {string|string[]} text The text to tokenize.
139
+ * @param {Object} options An optional object containing the following properties:
140
+ * @param {string|string[]} [options.text_pair=null] Optional second sequence to be encoded. If set, must be the same type as text.
141
+ * @param {boolean|'max_length'} [options.padding=false] Whether to pad the input sequences.
142
+ * @param {boolean} [options.add_special_tokens=true] Whether or not to add the special tokens associated with the corresponding model.
143
+ * @param {boolean} [options.truncation=null] Whether to truncate the input sequences.
144
+ * @param {number} [options.max_length=null] Maximum length of the returned list and optionally padding length.
145
+ * @param {boolean} [options.return_tensor=true] Whether to return the results as Tensors or arrays.
146
+ * @param {boolean} [options.return_token_type_ids=null] Whether to return the token type ids.
147
+ * @returns {BatchEncoding} Object to be passed to the model.
148
+ */
149
+ _call(text: string | string[], { text_pair, add_special_tokens, padding, truncation, max_length, return_tensor, return_token_type_ids, }?: {
150
+ text_pair?: string | string[];
151
+ padding?: boolean | 'max_length';
152
+ add_special_tokens?: boolean;
153
+ truncation?: boolean;
154
+ max_length?: number;
155
+ return_tensor?: boolean;
156
+ return_token_type_ids?: boolean;
157
+ }): {
158
+ /**
159
+ * List of token ids to be fed to a model.
160
+ */
161
+ input_ids: number[] | Tensor | number[][];
162
+ /**
163
+ * List of indices specifying which tokens should be attended to by the model.
164
+ */
165
+ attention_mask: number[] | Tensor | number[][];
166
+ /**
167
+ * List of token type ids to be fed to a model.
168
+ */
169
+ token_type_ids?: number[] | Tensor | number[][];
170
+ };
171
+ /**
172
+ * Encodes a single text using the preprocessor pipeline of the tokenizer.
173
+ *
174
+ * @param {string|null} text The text to encode.
175
+ * @returns {string[]|null} The encoded tokens.
176
+ */
177
+ _encode_text(text: string | null): string[] | null;
178
+ /**
179
+ * Encodes a single text or a pair of texts using the model's tokenizer.
180
+ *
181
+ * @param {string} text The text to encode.
182
+ * @param {string|null} text_pair The optional second text to encode.
183
+ * @param {Object} options An optional object containing the following properties:
184
+ * @param {boolean} [options.add_special_tokens=true] Whether or not to add the special tokens associated with the corresponding model.
185
+ * @param {boolean} [options.return_token_type_ids=null] Whether to return token_type_ids.
186
+ * @returns {EncodingSingle} An object containing the encoded text.
187
+ * @private
188
+ */
189
+ private _encode_plus;
190
+ /**
191
+ * Encodes a single text or a pair of texts using the model's tokenizer.
192
+ *
193
+ * @param {string} text The text to encode.
194
+ * @param {string|null} text_pair The optional second text to encode.
195
+ * @param {Object} options An optional object containing the following properties:
196
+ * @param {boolean} [options.add_special_tokens=true] Whether or not to add the special tokens associated with the corresponding model.
197
+ * @param {boolean} [options.return_token_type_ids=null] Whether to return token_type_ids.
198
+ * @returns {number[]} An array of token IDs representing the encoded text(s).
199
+ */
200
+ encode(text: string, text_pair?: string | null, { add_special_tokens, return_token_type_ids, }?: {
201
+ add_special_tokens?: boolean;
202
+ return_token_type_ids?: boolean;
203
+ }): number[];
204
+ /**
205
+ * Decode a batch of tokenized sequences.
206
+ * @param {number[][]|Tensor} batch List/Tensor of tokenized input sequences.
207
+ * @param {Object} decode_args (Optional) Object with decoding arguments.
208
+ * @returns {string[]} List of decoded sequences.
209
+ */
210
+ batch_decode(batch: number[][] | Tensor, decode_args?: any): string[];
211
+ /**
212
+ * Decodes a sequence of token IDs back to a string.
213
+ *
214
+ * @param {number[]|Tensor} token_ids List/Tensor of token IDs to decode.
215
+ * @param {Object} [decode_args={}]
216
+ * @param {boolean} [decode_args.skip_special_tokens=false] If true, special tokens are removed from the output string.
217
+ * @param {boolean} [decode_args.clean_up_tokenization_spaces=true] If true, spaces before punctuations and abbreviated forms are removed.
218
+ *
219
+ * @returns {string} The decoded string.
220
+ * @throws {Error} If `token_ids` is not a non-empty array of integers.
221
+ */
222
+ decode(token_ids: number[] | Tensor, decode_args?: {
223
+ skip_special_tokens?: boolean;
224
+ clean_up_tokenization_spaces?: boolean;
225
+ }): string;
226
+ /**
227
+ * Decode a single list of token ids to a string.
228
+ * @param {number[]} token_ids List of token ids to decode
229
+ * @param {Object} decode_args Optional arguments for decoding
230
+ * @param {boolean} [decode_args.skip_special_tokens=false] Whether to skip special tokens during decoding
231
+ * @param {boolean} [decode_args.clean_up_tokenization_spaces=null] Whether to clean up tokenization spaces during decoding.
232
+ * If null, the value is set to `this.decoder.cleanup` if it exists, falling back to `this.clean_up_tokenization_spaces` if it exists, falling back to `true`.
233
+ * @returns {string} The decoded string
234
+ */
235
+ decode_single(token_ids: number[], { skip_special_tokens, clean_up_tokenization_spaces, }: {
236
+ skip_special_tokens?: boolean;
237
+ clean_up_tokenization_spaces?: boolean;
238
+ }): string;
239
+ get default_chat_template(): string;
240
+ _warned_about_chat_template: boolean;
241
+ /**
242
+ * Converts a list of message objects with `"role"` and `"content"` keys to a list of token
243
+ * ids. This method is intended for use with chat models, and will read the tokenizer's chat_template attribute to
244
+ * determine the format and control tokens to use when converting. When chat_template is None, it will fall back
245
+ * to the default_chat_template specified at the class level.
246
+ *
247
+ * See [here](https://huggingface.co/docs/transformers/chat_templating) for more information.
248
+ *
249
+ * **Example:** Applying a chat template to a conversation.
250
+ *
251
+ * ```javascript
252
+ * import { AutoTokenizer } from "@xenova/transformers";
253
+ *
254
+ * const tokenizer = await AutoTokenizer.from_pretrained("Xenova/mistral-tokenizer-v1");
255
+ *
256
+ * const chat = [
257
+ * { "role": "user", "content": "Hello, how are you?" },
258
+ * { "role": "assistant", "content": "I'm doing great. How can I help you today?" },
259
+ * { "role": "user", "content": "I'd like to show off how chat templating works!" },
260
+ * ]
261
+ *
262
+ * const text = tokenizer.apply_chat_template(chat, { tokenize: false });
263
+ * // "<s>[INST] Hello, how are you? [/INST]I'm doing great. How can I help you today?</s> [INST] I'd like to show off how chat templating works! [/INST]"
264
+ *
265
+ * const input_ids = tokenizer.apply_chat_template(chat, { tokenize: true, return_tensor: false });
266
+ * // [1, 733, 16289, 28793, 22557, 28725, 910, 460, 368, 28804, 733, 28748, 16289, 28793, 28737, 28742, 28719, 2548, 1598, 28723, 1602, 541, 315, 1316, 368, 3154, 28804, 2, 28705, 733, 16289, 28793, 315, 28742, 28715, 737, 298, 1347, 805, 910, 10706, 5752, 1077, 3791, 28808, 733, 28748, 16289, 28793]
267
+ * ```
268
+ *
269
+ * @param {Message[]} conversation A list of message objects with `"role"` and `"content"` keys.
270
+ * @param {Object} options An optional object containing the following properties:
271
+ * @param {string} [options.chat_template=null] A Jinja template to use for this conversion. If
272
+ * this is not passed, the model's default chat template will be used instead.
273
+ * @param {boolean} [options.add_generation_prompt=false] Whether to end the prompt with the token(s) that indicate
274
+ * the start of an assistant message. This is useful when you want to generate a response from the model.
275
+ * Note that this argument will be passed to the chat template, and so it must be supported in the
276
+ * template for this argument to have any effect.
277
+ * @param {boolean} [options.tokenize=true] Whether to tokenize the output. If false, the output will be a string.
278
+ * @param {boolean} [options.padding=false] Whether to pad sequences to the maximum length. Has no effect if tokenize is false.
279
+ * @param {boolean} [options.truncation=false] Whether to truncate sequences to the maximum length. Has no effect if tokenize is false.
280
+ * @param {number} [options.max_length=null] Maximum length (in tokens) to use for padding or truncation. Has no effect if tokenize is false.
281
+ * If not specified, the tokenizer's `max_length` attribute will be used as a default.
282
+ * @param {boolean} [options.return_tensor=true] Whether to return the output as a Tensor or an Array. Has no effect if tokenize is false.
283
+ * @param {Object} [options.tokenizer_kwargs={}] Additional options to pass to the tokenizer.
284
+ * @returns {string | Tensor | number[]| number[][]} The tokenized output.
285
+ */
286
+ apply_chat_template(conversation: Message[], { chat_template, add_generation_prompt, tokenize, padding, truncation, max_length, return_tensor, tokenizer_kwargs, ...kwargs }?: {
287
+ chat_template?: string;
288
+ add_generation_prompt?: boolean;
289
+ tokenize?: boolean;
290
+ padding?: boolean;
291
+ truncation?: boolean;
292
+ max_length?: number;
293
+ return_tensor?: boolean;
294
+ tokenizer_kwargs?: any;
295
+ }): string | Tensor | number[] | number[][];
296
+ }
297
+ /**
298
+ * BertTokenizer is a class used to tokenize text for BERT models.
299
+ * @extends PreTrainedTokenizer
300
+ */
301
+ export class BertTokenizer extends PreTrainedTokenizer {
302
+ }
303
+ /**
304
+ * Albert tokenizer
305
+ * @extends PreTrainedTokenizer
306
+ */
307
+ export class AlbertTokenizer extends PreTrainedTokenizer {
308
+ }
309
+ export class MobileBertTokenizer extends PreTrainedTokenizer {
310
+ }
311
+ export class SqueezeBertTokenizer extends PreTrainedTokenizer {
312
+ }
313
+ export class DebertaTokenizer extends PreTrainedTokenizer {
314
+ }
315
+ export class DebertaV2Tokenizer extends PreTrainedTokenizer {
316
+ }
317
+ export class HerbertTokenizer extends PreTrainedTokenizer {
318
+ }
319
+ export class ConvBertTokenizer extends PreTrainedTokenizer {
320
+ }
321
+ export class RoFormerTokenizer extends PreTrainedTokenizer {
322
+ }
323
+ export class DistilBertTokenizer extends PreTrainedTokenizer {
324
+ }
325
+ export class CamembertTokenizer extends PreTrainedTokenizer {
326
+ }
327
+ export class XLMTokenizer extends PreTrainedTokenizer {
328
+ constructor(tokenizerJSON: any, tokenizerConfig: any);
329
+ }
330
+ export class ElectraTokenizer extends PreTrainedTokenizer {
331
+ }
332
+ export class T5Tokenizer extends PreTrainedTokenizer {
333
+ }
334
+ export class GPT2Tokenizer extends PreTrainedTokenizer {
335
+ }
336
+ export class BartTokenizer extends PreTrainedTokenizer {
337
+ }
338
+ export class MBartTokenizer extends PreTrainedTokenizer {
339
+ constructor(tokenizerJSON: any, tokenizerConfig: any);
340
+ languageRegex: RegExp;
341
+ language_codes: any[];
342
+ lang_to_token: (x: any) => any;
343
+ /**
344
+ * Helper function to build translation inputs for an `MBartTokenizer`.
345
+ * @param {string|string[]} raw_inputs The text to tokenize.
346
+ * @param {Object} tokenizer_options Options to be sent to the tokenizer
347
+ * @param {Object} generate_kwargs Generation options.
348
+ * @returns {Object} Object to be passed to the model.
349
+ */
350
+ _build_translation_inputs(raw_inputs: string | string[], tokenizer_options: any, generate_kwargs: any): any;
351
+ }
352
+ export class MBart50Tokenizer extends MBartTokenizer {
353
+ }
354
+ export class RobertaTokenizer extends PreTrainedTokenizer {
355
+ }
356
+ export class BloomTokenizer extends GPT2Tokenizer {
357
+ constructor(tokenizerJSON: any, tokenizerConfig: any);
358
+ }
359
+ export class LlamaTokenizer extends PreTrainedTokenizer {
360
+ constructor(tokenizerJSON: any, tokenizerConfig: any);
361
+ DEFAULT_SYSTEM_PROMPT: string;
362
+ use_default_system_prompt: any;
363
+ legacy: any;
364
+ get default_chat_template(): any;
365
+ }
366
+ export class CodeLlamaTokenizer extends LlamaTokenizer {
367
+ }
368
+ export class XLMRobertaTokenizer extends PreTrainedTokenizer {
369
+ }
370
+ export class MPNetTokenizer extends PreTrainedTokenizer {
371
+ }
372
+ export class FalconTokenizer extends PreTrainedTokenizer {
373
+ }
374
+ export class GPTNeoXTokenizer extends PreTrainedTokenizer {
375
+ }
376
+ export class EsmTokenizer extends PreTrainedTokenizer {
377
+ }
378
+ export class Qwen2Tokenizer extends PreTrainedTokenizer {
379
+ }
380
+ export class GemmaTokenizer extends PreTrainedTokenizer {
381
+ }
382
+ export class Grok1Tokenizer extends PreTrainedTokenizer {
383
+ }
384
+ /**
385
+ * The NllbTokenizer class is used to tokenize text for NLLB ("No Language Left Behind") models.
386
+ *
387
+ * No Language Left Behind (NLLB) is a first-of-its-kind, AI breakthrough project
388
+ * that open-sources models capable of delivering high-quality translations directly
389
+ * between any pair of 200+ languages — including low-resource languages like Asturian,
390
+ * Luganda, Urdu and more. It aims to help people communicate with anyone, anywhere,
391
+ * regardless of their language preferences. For more information, check out their
392
+ * [paper](https://arxiv.org/abs/2207.04672).
393
+ *
394
+ * For a list of supported languages (along with their language codes),
395
+ * @see {@link https://github.com/facebookresearch/flores/blob/main/flores200/README.md#languages-in-flores-200}
396
+ */
397
+ export class NllbTokenizer extends PreTrainedTokenizer {
398
+ constructor(tokenizerJSON: any, tokenizerConfig: any);
399
+ languageRegex: RegExp;
400
+ language_codes: any[];
401
+ lang_to_token: (x: any) => any;
402
+ /**
403
+ * Helper function to build translation inputs for an `NllbTokenizer`.
404
+ * @param {string|string[]} raw_inputs The text to tokenize.
405
+ * @param {Object} tokenizer_options Options to be sent to the tokenizer
406
+ * @param {Object} generate_kwargs Generation options.
407
+ * @returns {Object} Object to be passed to the model.
408
+ */
409
+ _build_translation_inputs(raw_inputs: string | string[], tokenizer_options: any, generate_kwargs: any): any;
410
+ }
411
+ /**
412
+ * The M2M100Tokenizer class is used to tokenize text for M2M100 ("Many-to-Many") models.
413
+ *
414
+ * M2M100 is a multilingual encoder-decoder (seq-to-seq) model trained for Many-to-Many
415
+ * multilingual translation. It was introduced in this [paper](https://arxiv.org/abs/2010.11125)
416
+ * and first released in [this](https://github.com/pytorch/fairseq/tree/master/examples/m2m_100) repository.
417
+ *
418
+ * For a list of supported languages (along with their language codes),
419
+ * @see {@link https://huggingface.co/facebook/m2m100_418M#languages-covered}
420
+ */
421
+ export class M2M100Tokenizer extends PreTrainedTokenizer {
422
+ constructor(tokenizerJSON: any, tokenizerConfig: any);
423
+ languageRegex: RegExp;
424
+ language_codes: any[];
425
+ lang_to_token: (x: any) => string;
426
+ /**
427
+ * Helper function to build translation inputs for an `M2M100Tokenizer`.
428
+ * @param {string|string[]} raw_inputs The text to tokenize.
429
+ * @param {Object} tokenizer_options Options to be sent to the tokenizer
430
+ * @param {Object} generate_kwargs Generation options.
431
+ * @returns {Object} Object to be passed to the model.
432
+ */
433
+ _build_translation_inputs(raw_inputs: string | string[], tokenizer_options: any, generate_kwargs: any): any;
434
+ }
435
+ /**
436
+ * WhisperTokenizer tokenizer
437
+ * @extends PreTrainedTokenizer
438
+ */
439
+ export class WhisperTokenizer extends PreTrainedTokenizer {
440
+ /**
441
+ * Decodes automatic speech recognition (ASR) sequences.
442
+ * @param {Array<{tokens: number[], token_timestamps?: number[], stride: number[]}>} sequences The sequences to decode.
443
+ * @param {Object} options The options to use for decoding.
444
+ * @returns {Array<string|{chunks?: undefined|Array<{language: string|null, timestamp: Array<number|null>, text: string}>}>} The decoded sequences.
445
+ */
446
+ _decode_asr(sequences: Array<{
447
+ tokens: number[];
448
+ token_timestamps?: number[];
449
+ stride: number[];
450
+ }>, { return_timestamps, return_language, time_precision, force_full_sequences }?: any): (string | {
451
+ chunks?: undefined | Array<{
452
+ language: string | null;
453
+ timestamp: Array<number | null>;
454
+ text: string;
455
+ }>;
456
+ })[];
457
+ /**
458
+ * Finds the longest common sequence among the provided sequences.
459
+ * @param {number[][]} sequences An array of sequences of token ids to compare.
460
+ * @returns {number[][]} The longest common sequence found.
461
+ * @throws {Error} If there is a bug within the function.
462
+ * @private
463
+ */
464
+ private findLongestCommonSequence;
465
+ /** @private */
466
+ private collateWordTimestamps;
467
+ /**
468
+ * Groups tokens by word. Returns a tuple containing a list of strings with the words,
469
+ * and a list of `token_id` sequences with the tokens making up each word.
470
+ * @param {number[]} tokens
471
+ * @param {string} [language]
472
+ * @param {string} prepend_punctionations
473
+ * @param {string} append_punctuations
474
+ *
475
+ * @private
476
+ */
477
+ private combineTokensIntoWords;
478
+ /**
479
+ * @param {number[]} token_ids List of token IDs to decode.
480
+ * @param {Object} decode_args Optional arguments for decoding
481
+ * @private
482
+ */
483
+ private decodeWithTimestamps;
484
+ /**
485
+ * Combine tokens into words by splitting at any position where the tokens are decoded as valid unicode points.
486
+ * @param {number[]} tokens
487
+ * @returns {*}
488
+ * @private
489
+ */
490
+ private splitTokensOnUnicode;
491
+ /**
492
+ * Combine tokens into words by splitting at whitespace and punctuation tokens.
493
+ * @param {number[]} tokens
494
+ * @private
495
+ */
496
+ private splitTokensOnSpaces;
497
+ /**
498
+ * Merges punctuation tokens with neighboring words.
499
+ * @param {string[]} words
500
+ * @param {number[][]} tokens
501
+ * @param {number[][]} indices
502
+ * @param {string} prepended
503
+ * @param {string} appended
504
+ * @private
505
+ */
506
+ private mergePunctuations;
507
+ /**
508
+ * Helper function to build translation inputs for a `WhisperTokenizer`,
509
+ * depending on the language, task, and whether to predict timestamp tokens.
510
+ *
511
+ * Used to override the prefix tokens appended to the start of the label sequence.
512
+ *
513
+ * **Example: Get ids for a language**
514
+ * ```javascript
515
+ * // instantiate the tokenizer and set the prefix token to Spanish
516
+ * const tokenizer = await WhisperTokenizer.from_pretrained('Xenova/whisper-tiny');
517
+ * const forced_decoder_ids = tokenizer.get_decoder_prompt_ids({ language: 'spanish' });
518
+ * // [(1, 50262), (2, 50363)]
519
+ * ```
520
+ *
521
+ * @param {Object} options Options to generate the decoder prompt.
522
+ * @param {string} [options.language] The language of the transcription text.
523
+ * The corresponding language id token is appended to the start of the sequence for multilingual
524
+ * speech recognition and speech translation tasks, e.g. for "Spanish" the token "<|es|>" is appended
525
+ * to the start of sequence.
526
+ * @param {string} [options.task] Task identifier to append at the start of sequence (if any).
527
+ * This should be used for mulitlingual fine-tuning, with "transcribe" for speech recognition and
528
+ * "translate" for speech translation.
529
+ * @param {boolean} [options.no_timestamps] Whether to add the <|notimestamps|> token at the start of the sequence.
530
+ * @returns {number[][]} The decoder prompt ids.
531
+ */
532
+ get_decoder_prompt_ids({ language, task, no_timestamps, }?: {
533
+ language?: string;
534
+ task?: string;
535
+ no_timestamps?: boolean;
536
+ }): number[][];
537
+ }
538
+ export class CodeGenTokenizer extends PreTrainedTokenizer {
539
+ }
540
+ export class CLIPTokenizer extends PreTrainedTokenizer {
541
+ }
542
+ export class SiglipTokenizer extends PreTrainedTokenizer {
543
+ }
544
+ /**
545
+ * @todo This model is not yet supported by Hugging Face's "fast" tokenizers library (https://github.com/huggingface/tokenizers).
546
+ * Therefore, this implementation (which is based on fast tokenizers) may produce slightly inaccurate results.
547
+ */
548
+ export class MarianTokenizer extends PreTrainedTokenizer {
549
+ languageRegex: RegExp;
550
+ supported_language_codes: string[];
551
+ /**
552
+ * Encodes a single text. Overriding this method is necessary since the language codes
553
+ * must be removed before encoding with sentencepiece model.
554
+ * @see https://github.com/huggingface/transformers/blob/12d51db243a00726a548a43cc333390ebae731e3/src/transformers/models/marian/tokenization_marian.py#L204-L213
555
+ *
556
+ * @param {string|null} text The text to encode.
557
+ * @returns {Array} The encoded tokens.
558
+ */
559
+ _encode_text(text: string | null): any[];
560
+ }
561
+ export class Wav2Vec2CTCTokenizer extends PreTrainedTokenizer {
562
+ }
563
+ export class BlenderbotTokenizer extends PreTrainedTokenizer {
564
+ }
565
+ export class BlenderbotSmallTokenizer extends BlenderbotTokenizer {
566
+ }
567
+ export class SpeechT5Tokenizer extends PreTrainedTokenizer {
568
+ }
569
+ export class NougatTokenizer extends PreTrainedTokenizer {
570
+ }
571
+ export class VitsTokenizer extends PreTrainedTokenizer {
572
+ constructor(tokenizerJSON: any, tokenizerConfig: any);
573
+ }
574
+ export class CohereTokenizer extends PreTrainedTokenizer {
575
+ }
576
+ /**
577
+ * Helper class which is used to instantiate pretrained tokenizers with the `from_pretrained` function.
578
+ * The chosen tokenizer class is determined by the type specified in the tokenizer config.
579
+ *
580
+ * @example
581
+ * const tokenizer = await AutoTokenizer.from_pretrained('Xenova/bert-base-uncased');
582
+ */
583
+ export class AutoTokenizer {
584
+ static TOKENIZER_CLASS_MAPPING: {
585
+ T5Tokenizer: typeof T5Tokenizer;
586
+ DistilBertTokenizer: typeof DistilBertTokenizer;
587
+ CamembertTokenizer: typeof CamembertTokenizer;
588
+ DebertaTokenizer: typeof DebertaTokenizer;
589
+ DebertaV2Tokenizer: typeof DebertaV2Tokenizer;
590
+ BertTokenizer: typeof BertTokenizer;
591
+ HerbertTokenizer: typeof HerbertTokenizer;
592
+ ConvBertTokenizer: typeof ConvBertTokenizer;
593
+ RoFormerTokenizer: typeof RoFormerTokenizer;
594
+ XLMTokenizer: typeof XLMTokenizer;
595
+ ElectraTokenizer: typeof ElectraTokenizer;
596
+ MobileBertTokenizer: typeof MobileBertTokenizer;
597
+ SqueezeBertTokenizer: typeof SqueezeBertTokenizer;
598
+ AlbertTokenizer: typeof AlbertTokenizer;
599
+ GPT2Tokenizer: typeof GPT2Tokenizer;
600
+ BartTokenizer: typeof BartTokenizer;
601
+ MBartTokenizer: typeof MBartTokenizer;
602
+ MBart50Tokenizer: typeof MBart50Tokenizer;
603
+ RobertaTokenizer: typeof RobertaTokenizer;
604
+ WhisperTokenizer: typeof WhisperTokenizer;
605
+ CodeGenTokenizer: typeof CodeGenTokenizer;
606
+ CLIPTokenizer: typeof CLIPTokenizer;
607
+ SiglipTokenizer: typeof SiglipTokenizer;
608
+ MarianTokenizer: typeof MarianTokenizer;
609
+ BloomTokenizer: typeof BloomTokenizer;
610
+ NllbTokenizer: typeof NllbTokenizer;
611
+ M2M100Tokenizer: typeof M2M100Tokenizer;
612
+ LlamaTokenizer: typeof LlamaTokenizer;
613
+ CodeLlamaTokenizer: typeof CodeLlamaTokenizer;
614
+ XLMRobertaTokenizer: typeof XLMRobertaTokenizer;
615
+ MPNetTokenizer: typeof MPNetTokenizer;
616
+ FalconTokenizer: typeof FalconTokenizer;
617
+ GPTNeoXTokenizer: typeof GPTNeoXTokenizer;
618
+ EsmTokenizer: typeof EsmTokenizer;
619
+ Wav2Vec2CTCTokenizer: typeof Wav2Vec2CTCTokenizer;
620
+ BlenderbotTokenizer: typeof BlenderbotTokenizer;
621
+ BlenderbotSmallTokenizer: typeof BlenderbotSmallTokenizer;
622
+ SpeechT5Tokenizer: typeof SpeechT5Tokenizer;
623
+ NougatTokenizer: typeof NougatTokenizer;
624
+ VitsTokenizer: typeof VitsTokenizer;
625
+ Qwen2Tokenizer: typeof Qwen2Tokenizer;
626
+ GemmaTokenizer: typeof GemmaTokenizer;
627
+ Grok1Tokenizer: typeof Grok1Tokenizer;
628
+ CohereTokenizer: typeof CohereTokenizer;
629
+ PreTrainedTokenizer: typeof PreTrainedTokenizer;
630
+ };
631
+ /**
632
+ * Instantiate one of the tokenizer classes of the library from a pretrained model.
633
+ *
634
+ * The tokenizer class to instantiate is selected based on the `tokenizer_class` property of the config object
635
+ * (either passed as an argument or loaded from `pretrained_model_name_or_path` if possible)
636
+ *
637
+ * @param {string} pretrained_model_name_or_path The name or path of the pretrained model. Can be either:
638
+ * - A string, the *model id* of a pretrained tokenizer hosted inside a model repo on huggingface.co.
639
+ * Valid model ids can be located at the root-level, like `bert-base-uncased`, or namespaced under a
640
+ * user or organization name, like `dbmdz/bert-base-german-cased`.
641
+ * - A path to a *directory* containing tokenizer files, e.g., `./my_model_directory/`.
642
+ * @param {PretrainedTokenizerOptions} options Additional options for loading the tokenizer.
643
+ *
644
+ * @returns {Promise<PreTrainedTokenizer>} A new instance of the PreTrainedTokenizer class.
645
+ */
646
+ static from_pretrained(pretrained_model_name_or_path: string, { quantized, progress_callback, config, cache_dir, local_files_only, revision, legacy, }?: PretrainedTokenizerOptions): Promise<PreTrainedTokenizer>;
647
+ }
648
+ /**
649
+ * Additional tokenizer-specific properties.
650
+ */
651
+ export type TokenizerProperties = {
652
+ /**
653
+ * Whether or not the `legacy` behavior of the tokenizer should be used.
654
+ */
655
+ legacy?: boolean;
656
+ };
657
+ export type PretrainedTokenizerOptions = import('./utils/hub.js').PretrainedOptions & TokenizerProperties;
658
+ export type BPENode = {
659
+ /**
660
+ * The token associated with the node
661
+ */
662
+ token: string;
663
+ /**
664
+ * A positional bias for the node.
665
+ */
666
+ bias: number;
667
+ /**
668
+ * The score of the node.
669
+ */
670
+ score?: number;
671
+ /**
672
+ * The previous node in the linked list.
673
+ */
674
+ prev?: BPENode;
675
+ /**
676
+ * The next node in the linked list.
677
+ */
678
+ next?: BPENode;
679
+ };
680
+ export type SplitDelimiterBehavior = 'removed' | 'isolated' | 'mergedWithPrevious' | 'mergedWithNext' | 'contiguous';
681
+ export type PostProcessedOutput = {
682
+ /**
683
+ * List of token produced by the post-processor.
684
+ */
685
+ tokens: string[];
686
+ /**
687
+ * List of token type ids produced by the post-processor.
688
+ */
689
+ token_type_ids?: number[];
690
+ };
691
+ export type EncodingSingle = {
692
+ /**
693
+ * List of token ids to be fed to a model.
694
+ */
695
+ input_ids: number[];
696
+ /**
697
+ * List of token type ids to be fed to a model
698
+ */
699
+ attention_mask: number[];
700
+ /**
701
+ * List of indices specifying which tokens should be attended to by the model
702
+ */
703
+ token_type_ids?: number[];
704
+ };
705
+ export type Message = {
706
+ /**
707
+ * The role of the message (e.g., "user" or "assistant" or "system").
708
+ */
709
+ role: string;
710
+ /**
711
+ * The content of the message.
712
+ */
713
+ content: string;
714
+ };
715
+ declare const Normalizer_base: new () => {
716
+ (...args: any[]): any;
717
+ _call(...args: any[]): any;
718
+ };
719
+ /**
720
+ * A base class for text normalization.
721
+ * @abstract
722
+ */
723
+ declare class Normalizer extends Normalizer_base {
724
+ /**
725
+ * Factory method for creating normalizers from config objects.
726
+ * @static
727
+ * @param {Object} config The configuration object for the normalizer.
728
+ * @returns {Normalizer} A Normalizer object.
729
+ * @throws {Error} If an unknown Normalizer type is specified in the config.
730
+ */
731
+ static fromConfig(config: any): Normalizer;
732
+ /**
733
+ * @param {Object} config The configuration object for the normalizer.
734
+ */
735
+ constructor(config: any);
736
+ config: any;
737
+ /**
738
+ * Normalize the input text.
739
+ * @abstract
740
+ * @param {string} text The text to normalize.
741
+ * @returns {string} The normalized text.
742
+ * @throws {Error} If this method is not implemented in a subclass.
743
+ */
744
+ normalize(text: string): string;
745
+ /**
746
+ * Alias for {@link Normalizer#normalize}.
747
+ * @param {string} text The text to normalize.
748
+ * @returns {string} The normalized text.
749
+ */
750
+ _call(text: string): string;
751
+ }
752
+ declare const PreTokenizer_base: new () => {
753
+ (...args: any[]): any;
754
+ _call(...args: any[]): any;
755
+ };
756
+ /**
757
+ * A callable class representing a pre-tokenizer used in tokenization. Subclasses
758
+ * should implement the `pre_tokenize_text` method to define the specific pre-tokenization logic.
759
+ * @extends Callable
760
+ */
761
+ declare class PreTokenizer extends PreTokenizer_base {
762
+ /**
763
+ * Factory method that returns an instance of a subclass of `PreTokenizer` based on the provided configuration.
764
+ *
765
+ * @static
766
+ * @param {Object} config A configuration object for the pre-tokenizer.
767
+ * @returns {PreTokenizer} An instance of a subclass of `PreTokenizer`.
768
+ * @throws {Error} If the provided configuration object does not correspond to any known pre-tokenizer.
769
+ */
770
+ static fromConfig(config: any): PreTokenizer;
771
+ /**
772
+ * Method that should be implemented by subclasses to define the specific pre-tokenization logic.
773
+ *
774
+ * @abstract
775
+ * @param {string} text The text to pre-tokenize.
776
+ * @param {Object} [options] Additional options for the pre-tokenization logic.
777
+ * @returns {string[]} The pre-tokenized text.
778
+ * @throws {Error} If the method is not implemented in the subclass.
779
+ */
780
+ pre_tokenize_text(text: string, options?: any): string[];
781
+ /**
782
+ * Tokenizes the given text into pre-tokens.
783
+ * @param {string|string[]} text The text or array of texts to pre-tokenize.
784
+ * @param {Object} [options] Additional options for the pre-tokenization logic.
785
+ * @returns {string[]} An array of pre-tokens.
786
+ */
787
+ pre_tokenize(text: string | string[], options?: any): string[];
788
+ /**
789
+ * Alias for {@link PreTokenizer#pre_tokenize}.
790
+ * @param {string|string[]} text The text or array of texts to pre-tokenize.
791
+ * @param {Object} [options] Additional options for the pre-tokenization logic.
792
+ * @returns {string[]} An array of pre-tokens.
793
+ */
794
+ _call(text: string | string[], options?: any): string[];
795
+ }
796
+ declare const PostProcessor_base: new () => {
797
+ (...args: any[]): any;
798
+ _call(...args: any[]): any;
799
+ };
800
+ /**
801
+ * @typedef {Object} PostProcessedOutput
802
+ * @property {string[]} tokens List of token produced by the post-processor.
803
+ * @property {number[]} [token_type_ids] List of token type ids produced by the post-processor.
804
+ */
805
+ /**
806
+ * @typedef {Object} EncodingSingle
807
+ * @property {number[]} input_ids List of token ids to be fed to a model.
808
+ * @property {number[]} attention_mask List of token type ids to be fed to a model
809
+ * @property {number[]} [token_type_ids] List of indices specifying which tokens should be attended to by the model
810
+ */
811
+ /**
812
+ * @extends Callable
813
+ */
814
+ declare class PostProcessor extends PostProcessor_base {
815
+ /**
816
+ * Factory method to create a PostProcessor object from a configuration object.
817
+ *
818
+ * @param {Object} config Configuration object representing a PostProcessor.
819
+ * @returns {PostProcessor} A PostProcessor object created from the given configuration.
820
+ * @throws {Error} If an unknown PostProcessor type is encountered.
821
+ */
822
+ static fromConfig(config: any): PostProcessor;
823
+ /**
824
+ * @param {Object} config The configuration for the post-processor.
825
+ */
826
+ constructor(config: any);
827
+ config: any;
828
+ /**
829
+ * Method to be implemented in subclass to apply post-processing on the given tokens.
830
+ *
831
+ * @param {Array} tokens The input tokens to be post-processed.
832
+ * @param {...*} args Additional arguments required by the post-processing logic.
833
+ * @returns {PostProcessedOutput} The post-processed tokens.
834
+ * @throws {Error} If the method is not implemented in subclass.
835
+ */
836
+ post_process(tokens: any[], ...args: any[]): PostProcessedOutput;
837
+ /**
838
+ * Alias for {@link PostProcessor#post_process}.
839
+ * @param {Array} tokens The text or array of texts to post-process.
840
+ * @param {...*} args Additional arguments required by the post-processing logic.
841
+ * @returns {PostProcessedOutput} The post-processed tokens.
842
+ */
843
+ _call(tokens: any[], ...args: any[]): PostProcessedOutput;
844
+ }
845
+ declare const Decoder_base: new () => {
846
+ (...args: any[]): any;
847
+ _call(...args: any[]): any;
848
+ };
849
+ /**
850
+ * The base class for token decoders.
851
+ * @extends Callable
852
+ */
853
+ declare class Decoder extends Decoder_base {
854
+ /**
855
+ * Creates a decoder instance based on the provided configuration.
856
+ *
857
+ * @param {Object} config The configuration object.
858
+ * @returns {Decoder} A decoder instance.
859
+ * @throws {Error} If an unknown decoder type is provided.
860
+ */
861
+ static fromConfig(config: any): Decoder;
862
+ /**
863
+ * Creates an instance of `Decoder`.
864
+ *
865
+ * @param {Object} config The configuration object.
866
+ */
867
+ constructor(config: any);
868
+ config: any;
869
+ /** @type {AddedToken[]} */
870
+ added_tokens: AddedToken[];
871
+ end_of_word_suffix: any;
872
+ trim_offsets: any;
873
+ /**
874
+ * Calls the `decode` method.
875
+ *
876
+ * @param {string[]} tokens The list of tokens.
877
+ * @returns {string} The decoded string.
878
+ */
879
+ _call(tokens: string[]): string;
880
+ /**
881
+ * Decodes a list of tokens.
882
+ * @param {string[]} tokens The list of tokens.
883
+ * @returns {string} The decoded string.
884
+ */
885
+ decode(tokens: string[]): string;
886
+ /**
887
+ * Apply the decoder to a list of tokens.
888
+ *
889
+ * @param {string[]} tokens The list of tokens.
890
+ * @returns {string[]} The decoded list of tokens.
891
+ * @throws {Error} If the `decode_chain` method is not implemented in the subclass.
892
+ */
893
+ decode_chain(tokens: string[]): string[];
894
+ }
895
+ /**
896
+ * Represent a token added by the user on top of the existing Model vocabulary.
897
+ * AddedToken can be configured to specify the behavior they should have in various situations like:
898
+ * - Whether they should only match single words
899
+ * - Whether to include any whitespace on its left or right
900
+ */
901
+ declare class AddedToken {
902
+ /**
903
+ * Creates a new instance of AddedToken.
904
+ * @param {Object} config Added token configuration object.
905
+ * @param {string} config.content The content of the added token.
906
+ * @param {number} config.id The id of the added token.
907
+ * @param {boolean} [config.single_word=false] Whether this token must be a single word or can break words.
908
+ * @param {boolean} [config.lstrip=false] Whether this token should strip whitespaces on its left.
909
+ * @param {boolean} [config.rstrip=false] Whether this token should strip whitespaces on its right.
910
+ * @param {boolean} [config.normalized=false] Whether this token should be normalized.
911
+ * @param {boolean} [config.special=false] Whether this token is special.
912
+ */
913
+ constructor(config: {
914
+ content: string;
915
+ id: number;
916
+ single_word?: boolean;
917
+ lstrip?: boolean;
918
+ rstrip?: boolean;
919
+ normalized?: boolean;
920
+ special?: boolean;
921
+ });
922
+ content: string;
923
+ id: number;
924
+ single_word: boolean;
925
+ lstrip: boolean;
926
+ rstrip: boolean;
927
+ special: boolean;
928
+ normalized: boolean;
929
+ }
930
+ import { Tensor } from './utils/tensor.js';
931
+ export {};
932
+ //# sourceMappingURL=tokenizers.d.ts.map