@mediapipe/tasks-text 0.1.0-alpha-12 → 0.1.0-alpha-14

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.
Binary file
package/text.d.ts DELETED
@@ -1,531 +0,0 @@
1
- /**
2
- * Copyright 2022 The MediaPipe Authors. All Rights Reserved.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
- /** Options to configure MediaPipe model loading and processing. */
17
- declare interface BaseOptions_2 {
18
- /**
19
- * The model path to the model asset file. Only one of `modelAssetPath` or
20
- * `modelAssetBuffer` can be set.
21
- */
22
- modelAssetPath?: string | undefined;
23
- /**
24
- * A buffer containing the model aaset. Only one of `modelAssetPath` or
25
- * `modelAssetBuffer` can be set.
26
- */
27
- modelAssetBuffer?: Uint8Array | undefined;
28
- /** Overrides the default backend to use for the provided model. */
29
- delegate?: "CPU" | "GPU" | undefined;
30
- }
31
-
32
- /**
33
- * Copyright 2022 The MediaPipe Authors. All Rights Reserved.
34
- *
35
- * Licensed under the Apache License, Version 2.0 (the "License");
36
- * you may not use this file except in compliance with the License.
37
- * You may obtain a copy of the License at
38
- *
39
- * http://www.apache.org/licenses/LICENSE-2.0
40
- *
41
- * Unless required by applicable law or agreed to in writing, software
42
- * distributed under the License is distributed on an "AS IS" BASIS,
43
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
44
- * See the License for the specific language governing permissions and
45
- * limitations under the License.
46
- */
47
- /** A classification category. */
48
- export declare interface Category {
49
- /** The probability score of this label category. */
50
- score: number;
51
- /** The index of the category in the corresponding label file. */
52
- index: number;
53
- /**
54
- * The label of this category object. Defaults to an empty string if there is
55
- * no category.
56
- */
57
- categoryName: string;
58
- /**
59
- * The display name of the label, which may be translated for different
60
- * locales. For example, a label, "apple", may be translated into Spanish for
61
- * display purpose, so that the `display_name` is "manzana". Defaults to an
62
- * empty string if there is no display name.
63
- */
64
- displayName: string;
65
- }
66
-
67
- /** Classification results for a given classifier head. */
68
- export declare interface Classifications {
69
- /**
70
- * The array of predicted categories, usually sorted by descending scores,
71
- * e.g., from high to low probability.
72
- */
73
- categories: Category[];
74
- /**
75
- * The index of the classifier head these categories refer to. This is
76
- * useful for multi-head models.
77
- */
78
- headIndex: number;
79
- /**
80
- * The name of the classifier head, which is the corresponding tensor
81
- * metadata name. Defaults to an empty string if there is no such metadata.
82
- */
83
- headName: string;
84
- }
85
-
86
- /**
87
- * Copyright 2022 The MediaPipe Authors. All Rights Reserved.
88
- *
89
- * Licensed under the Apache License, Version 2.0 (the "License");
90
- * you may not use this file except in compliance with the License.
91
- * You may obtain a copy of the License at
92
- *
93
- * http://www.apache.org/licenses/LICENSE-2.0
94
- *
95
- * Unless required by applicable law or agreed to in writing, software
96
- * distributed under the License is distributed on an "AS IS" BASIS,
97
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
98
- * See the License for the specific language governing permissions and
99
- * limitations under the License.
100
- */
101
- /** Options to configure a MediaPipe Classifier Task. */
102
- declare interface ClassifierOptions {
103
- /**
104
- * The locale to use for display names specified through the TFLite Model
105
- * Metadata, if any. Defaults to English.
106
- */
107
- displayNamesLocale?: string | undefined;
108
- /** The maximum number of top-scored detection results to return. */
109
- maxResults?: number | undefined;
110
- /**
111
- * Overrides the value provided in the model metadata. Results below this
112
- * value are rejected.
113
- */
114
- scoreThreshold?: number | undefined;
115
- /**
116
- * Allowlist of category names. If non-empty, detection results whose category
117
- * name is not in this set will be filtered out. Duplicate or unknown category
118
- * names are ignored. Mutually exclusive with `categoryDenylist`.
119
- */
120
- categoryAllowlist?: string[] | undefined;
121
- /**
122
- * Denylist of category names. If non-empty, detection results whose category
123
- * name is in this set will be filtered out. Duplicate or unknown category
124
- * names are ignored. Mutually exclusive with `categoryAllowlist`.
125
- */
126
- categoryDenylist?: string[] | undefined;
127
- }
128
-
129
- /**
130
- * Copyright 2022 The MediaPipe Authors. All Rights Reserved.
131
- *
132
- * Licensed under the Apache License, Version 2.0 (the "License");
133
- * you may not use this file except in compliance with the License.
134
- * You may obtain a copy of the License at
135
- *
136
- * http://www.apache.org/licenses/LICENSE-2.0
137
- *
138
- * Unless required by applicable law or agreed to in writing, software
139
- * distributed under the License is distributed on an "AS IS" BASIS,
140
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
141
- * See the License for the specific language governing permissions and
142
- * limitations under the License.
143
- */
144
- /** Options to configure a MediaPipe Embedder Task */
145
- declare interface EmbedderOptions {
146
- /**
147
- * Whether to normalize the returned feature vector with L2 norm. Use this
148
- * option only if the model does not already contain a native L2_NORMALIZATION
149
- * TF Lite Op. In most cases, this is already the case and L2 norm is thus
150
- * achieved through TF Lite inference.
151
- */
152
- l2Normalize?: boolean | undefined;
153
- /**
154
- * Whether the returned embedding should be quantized to bytes via scalar
155
- * quantization. Embeddings are implicitly assumed to be unit-norm and
156
- * therefore any dimension is guaranteed to have a value in [-1.0, 1.0]. Use
157
- * the l2_normalize option if this is not the case.
158
- */
159
- quantize?: boolean | undefined;
160
- }
161
-
162
- /**
163
- * Copyright 2022 The MediaPipe Authors. All Rights Reserved.
164
- *
165
- * Licensed under the Apache License, Version 2.0 (the "License");
166
- * you may not use this file except in compliance with the License.
167
- * You may obtain a copy of the License at
168
- *
169
- * http://www.apache.org/licenses/LICENSE-2.0
170
- *
171
- * Unless required by applicable law or agreed to in writing, software
172
- * distributed under the License is distributed on an "AS IS" BASIS,
173
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
174
- * See the License for the specific language governing permissions and
175
- * limitations under the License.
176
- */
177
- /**
178
- * List of embeddings with an optional timestamp.
179
- *
180
- * One and only one of the two 'floatEmbedding' and 'quantizedEmbedding' will
181
- * contain data, based on whether or not the embedder was configured to perform
182
- * scalar quantization.
183
- */
184
- export declare interface Embedding {
185
- /**
186
- * Floating-point embedding. Empty if the embedder was configured to perform
187
- * scalar-quantization.
188
- */
189
- floatEmbedding?: number[];
190
- /**
191
- * Scalar-quantized embedding. Empty if the embedder was not configured to
192
- * perform scalar quantization.
193
- */
194
- quantizedEmbedding?: Uint8Array;
195
- /**
196
- * The index of the classifier head these categories refer to. This is
197
- * useful for multi-head models.
198
- */
199
- headIndex: number;
200
- /**
201
- * The name of the classifier head, which is the corresponding tensor
202
- * metadata name.
203
- */
204
- headName: string;
205
- }
206
-
207
- /**
208
- * Resolves the files required for the MediaPipe Task APIs.
209
- *
210
- * This class verifies whether SIMD is supported in the current environment and
211
- * loads the SIMD files only if support is detected. The returned filesets
212
- * require that the Wasm files are published without renaming. If this is not
213
- * possible, you can invoke the MediaPipe Tasks APIs using a manually created
214
- * `WasmFileset`.
215
- */
216
- export declare class FilesetResolver {
217
- /**
218
- * Returns whether SIMD is supported in the current environment.
219
- *
220
- * If your environment requires custom locations for the MediaPipe Wasm files,
221
- * you can use `isSimdSupported()` to decide whether to load the SIMD-based
222
- * assets.
223
- *
224
- * @return Whether SIMD support was detected in the current environment.
225
- */
226
- static isSimdSupported(): Promise<boolean>;
227
- /**
228
- * Creates a fileset for the MediaPipe Audio tasks.
229
- *
230
- * @param basePath An optional base path to specify the directory the Wasm
231
- * files should be loaded from. If not specified, the Wasm files are
232
- * loaded from the host's root directory.
233
- * @return A `WasmFileset` that can be used to initialize MediaPipe Audio
234
- * tasks.
235
- */
236
- static forAudioTasks(basePath?: string): Promise<WasmFileset>;
237
- /**
238
- * Creates a fileset for the MediaPipe Text tasks.
239
- *
240
- * @param basePath An optional base path to specify the directory the Wasm
241
- * files should be loaded from. If not specified, the Wasm files are
242
- * loaded from the host's root directory.
243
- * @return A `WasmFileset` that can be used to initialize MediaPipe Text
244
- * tasks.
245
- */
246
- static forTextTasks(basePath?: string): Promise<WasmFileset>;
247
- /**
248
- * Creates a fileset for the MediaPipe Vision tasks.
249
- *
250
- * @param basePath An optional base path to specify the directory the Wasm
251
- * files should be loaded from. If not specified, the Wasm files are
252
- * loaded from the host's root directory.
253
- * @return A `WasmFileset` that can be used to initialize MediaPipe Vision
254
- * tasks.
255
- */
256
- static forVisionTasks(basePath?: string): Promise<WasmFileset>;
257
- }
258
-
259
- /** Predicts the language of an input text. */
260
- export declare class LanguageDetector extends TaskRunner {
261
- /**
262
- * Initializes the Wasm runtime and creates a new language detector from the
263
- * provided options.
264
- * @param wasmFileset A configuration object that provides the location of the
265
- * Wasm binary and its loader.
266
- * @param textClassifierOptions The options for the language detector. Note
267
- * that either a path to the TFLite model or the model itself needs to be
268
- * provided (via `baseOptions`).
269
- */
270
- static createFromOptions(wasmFileset: WasmFileset, textClassifierOptions: LanguageDetectorOptions): Promise<LanguageDetector>;
271
- /**
272
- * Initializes the Wasm runtime and creates a new language detector based on
273
- * the provided model asset buffer.
274
- * @param wasmFileset A configuration object that provides the location of the
275
- * Wasm binary and its loader.
276
- * @param modelAssetBuffer A binary representation of the model.
277
- */
278
- static createFromModelBuffer(wasmFileset: WasmFileset, modelAssetBuffer: Uint8Array): Promise<LanguageDetector>;
279
- /**
280
- * Initializes the Wasm runtime and creates a new language detector based on
281
- * the path to the model asset.
282
- * @param wasmFileset A configuration object that provides the location of the
283
- * Wasm binary and its loader.
284
- * @param modelAssetPath The path to the model asset.
285
- */
286
- static createFromModelPath(wasmFileset: WasmFileset, modelAssetPath: string): Promise<LanguageDetector>;
287
- private constructor();
288
- /**
289
- * Sets new options for the language detector.
290
- *
291
- * Calling `setOptions()` with a subset of options only affects those options.
292
- * You can reset an option back to its default value by explicitly setting it
293
- * to `undefined`.
294
- *
295
- * @param options The options for the language detector.
296
- */
297
- setOptions(options: LanguageDetectorOptions): Promise<void>;
298
- /**
299
- * Predicts the language of the input text.
300
- *
301
- * @param text The text to process.
302
- * @return The languages detected in the input text.
303
- */
304
- detect(text: string): LanguageDetectorResult;
305
- }
306
-
307
- /** Options to configure the MediaPipe Language Detector Task */
308
- export declare interface LanguageDetectorOptions extends ClassifierOptions, TaskRunnerOptions {
309
- }
310
-
311
- /**
312
- * Copyright 2022 The MediaPipe Authors. All Rights Reserved.
313
- *
314
- * Licensed under the Apache License, Version 2.0 (the "License");
315
- * you may not use this file except in compliance with the License.
316
- * You may obtain a copy of the License at
317
- *
318
- * http://www.apache.org/licenses/LICENSE-2.0
319
- *
320
- * Unless required by applicable law or agreed to in writing, software
321
- * distributed under the License is distributed on an "AS IS" BASIS,
322
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
323
- * See the License for the specific language governing permissions and
324
- * limitations under the License.
325
- */
326
- /** A language code and its probability. */
327
- export declare interface LanguageDetectorPrediction {
328
- /**
329
- * An i18n language / locale code, e.g. "en" for English, "uz" for Uzbek,
330
- * "ja"-Latn for Japanese (romaji).
331
- */
332
- languageCode: string;
333
- /** The probability */
334
- probability: number;
335
- }
336
-
337
- /** The result of language detection. */
338
- export declare interface LanguageDetectorResult {
339
- /** A list of language predictions. */
340
- languages: LanguageDetectorPrediction[];
341
- }
342
-
343
- /** Base class for all MediaPipe Tasks. */
344
- declare abstract class TaskRunner {
345
- protected constructor();
346
- /** Configures the task with custom options. */
347
- abstract setOptions(options: TaskRunnerOptions): Promise<void>;
348
- }
349
-
350
- /** Options to configure MediaPipe Tasks in general. */
351
- declare interface TaskRunnerOptions {
352
- /** Options to configure the loading of the model assets. */
353
- baseOptions?: BaseOptions_2;
354
- }
355
-
356
- /** Performs Natural Language classification. */
357
- export declare class TextClassifier extends TaskRunner {
358
- /**
359
- * Initializes the Wasm runtime and creates a new text classifier from the
360
- * provided options.
361
- * @param wasmFileset A configuration object that provides the location of the
362
- * Wasm binary and its loader.
363
- * @param textClassifierOptions The options for the text classifier. Note that
364
- * either a path to the TFLite model or the model itself needs to be
365
- * provided (via `baseOptions`).
366
- */
367
- static createFromOptions(wasmFileset: WasmFileset, textClassifierOptions: TextClassifierOptions): Promise<TextClassifier>;
368
- /**
369
- * Initializes the Wasm runtime and creates a new text classifier based on the
370
- * provided model asset buffer.
371
- * @param wasmFileset A configuration object that provides the location of the
372
- * Wasm binary and its loader.
373
- * @param modelAssetBuffer A binary representation of the model.
374
- */
375
- static createFromModelBuffer(wasmFileset: WasmFileset, modelAssetBuffer: Uint8Array): Promise<TextClassifier>;
376
- /**
377
- * Initializes the Wasm runtime and creates a new text classifier based on the
378
- * path to the model asset.
379
- * @param wasmFileset A configuration object that provides the location of the
380
- * Wasm binary and its loader.
381
- * @param modelAssetPath The path to the model asset.
382
- */
383
- static createFromModelPath(wasmFileset: WasmFileset, modelAssetPath: string): Promise<TextClassifier>;
384
- private constructor();
385
- /**
386
- * Sets new options for the text classifier.
387
- *
388
- * Calling `setOptions()` with a subset of options only affects those options.
389
- * You can reset an option back to its default value by explicitly setting it
390
- * to `undefined`.
391
- *
392
- * @param options The options for the text classifier.
393
- */
394
- setOptions(options: TextClassifierOptions): Promise<void>;
395
- /**
396
- * Performs Natural Language classification on the provided text and waits
397
- * synchronously for the response.
398
- *
399
- * @param text The text to process.
400
- * @return The classification result of the text
401
- */
402
- classify(text: string): TextClassifierResult;
403
- }
404
-
405
- /** Options to configure the MediaPipe Text Classifier Task */
406
- export declare interface TextClassifierOptions extends ClassifierOptions, TaskRunnerOptions {
407
- }
408
-
409
- /** Classification results of a model. */
410
- export declare interface TextClassifierResult {
411
- /** The classification results for each head of the model. */
412
- classifications: Classifications[];
413
- /**
414
- * The optional timestamp (in milliseconds) of the start of the chunk of data
415
- * corresponding to these results.
416
- *
417
- * This is only used for classification on time series (e.g. audio
418
- * classification). In these use cases, the amount of data to process might
419
- * exceed the maximum size that the model can process: to solve this, the
420
- * input data is split into multiple chunks starting at different timestamps.
421
- */
422
- timestampMs?: number;
423
- }
424
-
425
- /**
426
- * Performs embedding extraction on text.
427
- */
428
- export declare class TextEmbedder extends TaskRunner {
429
- /**
430
- * Initializes the Wasm runtime and creates a new text embedder from the
431
- * provided options.
432
- * @param wasmFileset A configuration object that provides the location of the
433
- * Wasm binary and its loader.
434
- * @param textEmbedderOptions The options for the text embedder. Note that
435
- * either a path to the TFLite model or the model itself needs to be
436
- * provided (via `baseOptions`).
437
- */
438
- static createFromOptions(wasmFileset: WasmFileset, textEmbedderOptions: TextEmbedderOptions): Promise<TextEmbedder>;
439
- /**
440
- * Initializes the Wasm runtime and creates a new text embedder based on the
441
- * provided model asset buffer.
442
- * @param wasmFileset A configuration object that provides the location of the
443
- * Wasm binary and its loader.
444
- * @param modelAssetBuffer A binary representation of the TFLite model.
445
- */
446
- static createFromModelBuffer(wasmFileset: WasmFileset, modelAssetBuffer: Uint8Array): Promise<TextEmbedder>;
447
- /**
448
- * Initializes the Wasm runtime and creates a new text embedder based on the
449
- * path to the model asset.
450
- * @param wasmFileset A configuration object that provides the location of the
451
- * Wasm binary and its loader.
452
- * @param modelAssetPath The path to the TFLite model.
453
- */
454
- static createFromModelPath(wasmFileset: WasmFileset, modelAssetPath: string): Promise<TextEmbedder>;
455
- private constructor();
456
- /**
457
- * Sets new options for the text embedder.
458
- *
459
- * Calling `setOptions()` with a subset of options only affects those options.
460
- * You can reset an option back to its default value by explicitly setting it
461
- * to `undefined`.
462
- *
463
- * @param options The options for the text embedder.
464
- */
465
- setOptions(options: TextEmbedderOptions): Promise<void>;
466
- /**
467
- * Performs embeding extraction on the provided text and waits synchronously
468
- * for the response.
469
- *
470
- * @param text The text to process.
471
- * @return The embedding resuls of the text
472
- */
473
- embed(text: string): TextEmbedderResult;
474
- /**
475
- * Utility function to compute cosine similarity[1] between two `Embedding`
476
- * objects.
477
- *
478
- * [1]: https://en.wikipedia.org/wiki/Cosine_similarity
479
- *
480
- * @throws if the embeddings are of different types(float vs. quantized), have
481
- * different sizes, or have an L2-norm of 0.
482
- */
483
- static cosineSimilarity(u: Embedding, v: Embedding): number;
484
- }
485
-
486
- /** Options to configure the MediaPipe Text Embedder Task */
487
- export declare interface TextEmbedderOptions extends EmbedderOptions, TaskRunnerOptions {
488
- }
489
-
490
- /** Embedding results for a given embedder model. */
491
- export declare interface TextEmbedderResult {
492
- /**
493
- * The embedding results for each model head, i.e. one for each output tensor.
494
- */
495
- embeddings: Embedding[];
496
- /**
497
- * The optional timestamp (in milliseconds) of the start of the chunk of
498
- * data corresponding to these results.
499
- *
500
- * This is only used for embedding extraction on time series (e.g. audio
501
- * embedding). In these use cases, the amount of data to process might
502
- * exceed the maximum size that the model can process: to solve this, the
503
- * input data is split into multiple chunks starting at different timestamps.
504
- */
505
- timestampMs?: number;
506
- }
507
-
508
- /**
509
- * Copyright 2022 The MediaPipe Authors. All Rights Reserved.
510
- *
511
- * Licensed under the Apache License, Version 2.0 (the "License");
512
- * you may not use this file except in compliance with the License.
513
- * You may obtain a copy of the License at
514
- *
515
- * http://www.apache.org/licenses/LICENSE-2.0
516
- *
517
- * Unless required by applicable law or agreed to in writing, software
518
- * distributed under the License is distributed on an "AS IS" BASIS,
519
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
520
- * See the License for the specific language governing permissions and
521
- * limitations under the License.
522
- */
523
- /** An object containing the locations of the Wasm assets */
524
- declare interface WasmFileset {
525
- /** The path to the Wasm loader script. */
526
- wasmLoaderPath: string;
527
- /** The path to the Wasm binary. */
528
- wasmBinaryPath: string;
529
- }
530
-
531
- export { }