@mediapipe/tasks-text 0.1.0-alpha-1668420868 → 0.1.0-alpha-1668655831
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.
- package/package.json +2 -11
- package/text.d.ts +297 -16
- package/text_bundle.js +1 -13544
package/package.json
CHANGED
|
@@ -1,20 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mediapipe/tasks-text",
|
|
3
|
-
"version": "0.1.0-alpha-
|
|
3
|
+
"version": "0.1.0-alpha-1668655831",
|
|
4
4
|
"description": "MediaPipe Text Tasks",
|
|
5
5
|
"main": "text_bundle.js",
|
|
6
|
-
"module": "text_bundle.js",
|
|
7
|
-
"exports": {
|
|
8
|
-
".": "./text_bundle.js",
|
|
9
|
-
"./loader": "./wasm/text_wasm_internal.js",
|
|
10
|
-
"./wasm": "./wasm/text_wasm_internal.wasm"
|
|
11
|
-
},
|
|
12
6
|
"author": "mediapipe@google.com",
|
|
13
7
|
"license": "Apache-2.0",
|
|
14
|
-
"dependencies": {
|
|
15
|
-
"google-protobuf": "^3.21.2"
|
|
16
|
-
},
|
|
17
|
-
"homepage": "http://mediapipe.dev",
|
|
18
8
|
"types": "text.d.ts",
|
|
9
|
+
"homepage": "http://mediapipe.dev",
|
|
19
10
|
"keywords": [ "AR", "ML", "Augmented", "MediaPipe", "MediaPipe Tasks" ]
|
|
20
11
|
}
|
package/text.d.ts
CHANGED
|
@@ -1,17 +1,221 @@
|
|
|
1
1
|
/// <reference types="@types/offscreencanvas" />
|
|
2
2
|
|
|
3
|
-
import { Category } from '../../../../tasks/web/components/containers/category';
|
|
4
|
-
import { Classifications } from '../../../../tasks/web/components/containers/classification_result';
|
|
5
|
-
import { ClassifierOptions as TextClassifierOptions } from '../../../../tasks/web/core/classifier_options';
|
|
6
|
-
import { ClassificationResult as TextClassifierResult } from '../../../../tasks/web/components/containers/classification_result';
|
|
7
|
-
import { WasmLoaderOptions } from '../../../../tasks/web/core/wasm_loader_options';
|
|
8
|
-
|
|
9
3
|
/** Listener to be passed in by user for handling output audio data. */
|
|
10
4
|
declare type AudioOutputListener = (output: Float32Array) => void;
|
|
11
5
|
|
|
12
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Copyright 2022 The MediaPipe Authors. All Rights Reserved.
|
|
8
|
+
*
|
|
9
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
10
|
+
* you may not use this file except in compliance with the License.
|
|
11
|
+
* You may obtain a copy of the License at
|
|
12
|
+
*
|
|
13
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
14
|
+
*
|
|
15
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
16
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
17
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
18
|
+
* See the License for the specific language governing permissions and
|
|
19
|
+
* limitations under the License.
|
|
20
|
+
*/
|
|
21
|
+
/** Options to configure MediaPipe Tasks in general. */
|
|
22
|
+
declare interface BaseOptions {
|
|
23
|
+
/**
|
|
24
|
+
* The model path to the model asset file. Only one of `modelAssetPath` or
|
|
25
|
+
* `modelAssetBuffer` can be set.
|
|
26
|
+
*/
|
|
27
|
+
modelAssetPath?: string | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* A buffer containing the model aaset. Only one of `modelAssetPath` or
|
|
30
|
+
* `modelAssetBuffer` can be set.
|
|
31
|
+
*/
|
|
32
|
+
modelAssetBuffer?: Uint8Array | undefined;
|
|
33
|
+
/** Overrides the default backend to use for the provided model. */
|
|
34
|
+
delegate?: 'cpu' | 'gpu' | undefined;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Copyright 2022 The MediaPipe Authors. All Rights Reserved.
|
|
39
|
+
*
|
|
40
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
41
|
+
* you may not use this file except in compliance with the License.
|
|
42
|
+
* You may obtain a copy of the License at
|
|
43
|
+
*
|
|
44
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
45
|
+
*
|
|
46
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
47
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
48
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
49
|
+
* See the License for the specific language governing permissions and
|
|
50
|
+
* limitations under the License.
|
|
51
|
+
*/
|
|
52
|
+
/** A classification category. */
|
|
53
|
+
declare interface Category {
|
|
54
|
+
/** The probability score of this label category. */
|
|
55
|
+
score: number;
|
|
56
|
+
/** The index of the category in the corresponding label file. */
|
|
57
|
+
index: number;
|
|
58
|
+
/**
|
|
59
|
+
* The label of this category object. Defaults to an empty string if there is
|
|
60
|
+
* no category.
|
|
61
|
+
*/
|
|
62
|
+
categoryName: string;
|
|
63
|
+
/**
|
|
64
|
+
* The display name of the label, which may be translated for different
|
|
65
|
+
* locales. For example, a label, "apple", may be translated into Spanish for
|
|
66
|
+
* display purpose, so that the `display_name` is "manzana". Defaults to an
|
|
67
|
+
* empty string if there is no display name.
|
|
68
|
+
*/
|
|
69
|
+
displayName: string;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Classification results of a model. */
|
|
73
|
+
declare interface ClassificationResult {
|
|
74
|
+
/** The classification results for each head of the model. */
|
|
75
|
+
classifications: Classifications[];
|
|
76
|
+
/**
|
|
77
|
+
* The optional timestamp (in milliseconds) of the start of the chunk of data
|
|
78
|
+
* corresponding to these results.
|
|
79
|
+
*
|
|
80
|
+
* This is only used for classification on time series (e.g. audio
|
|
81
|
+
* classification). In these use cases, the amount of data to process might
|
|
82
|
+
* exceed the maximum size that the model can process: to solve this, the
|
|
83
|
+
* input data is split into multiple chunks starting at different timestamps.
|
|
84
|
+
*/
|
|
85
|
+
timestampMs?: number;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** Classification results for a given classifier head. */
|
|
89
|
+
declare interface Classifications {
|
|
90
|
+
/**
|
|
91
|
+
* The array of predicted categories, usually sorted by descending scores,
|
|
92
|
+
* e.g., from high to low probability.
|
|
93
|
+
*/
|
|
94
|
+
categories: Category[];
|
|
95
|
+
/**
|
|
96
|
+
* The index of the classifier head these categories refer to. This is
|
|
97
|
+
* useful for multi-head models.
|
|
98
|
+
*/
|
|
99
|
+
headIndex: number;
|
|
100
|
+
/**
|
|
101
|
+
* The name of the classifier head, which is the corresponding tensor
|
|
102
|
+
* metadata name. Defaults to an empty string if there is no such metadata.
|
|
103
|
+
*/
|
|
104
|
+
headName: string;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** Options to configure the Mediapipe Classifier Task. */
|
|
108
|
+
declare interface ClassifierOptions {
|
|
109
|
+
/** Options to configure the loading of the model assets. */
|
|
110
|
+
baseOptions?: BaseOptions;
|
|
111
|
+
/**
|
|
112
|
+
* The locale to use for display names specified through the TFLite Model
|
|
113
|
+
* Metadata, if any. Defaults to English.
|
|
114
|
+
*/
|
|
115
|
+
displayNamesLocale?: string | undefined;
|
|
116
|
+
/** The maximum number of top-scored detection results to return. */
|
|
117
|
+
maxResults?: number | undefined;
|
|
118
|
+
/**
|
|
119
|
+
* Overrides the value provided in the model metadata. Results below this
|
|
120
|
+
* value are rejected.
|
|
121
|
+
*/
|
|
122
|
+
scoreThreshold?: number | undefined;
|
|
123
|
+
/**
|
|
124
|
+
* Allowlist of category names. If non-empty, detection results whose category
|
|
125
|
+
* name is not in this set will be filtered out. Duplicate or unknown category
|
|
126
|
+
* names are ignored. Mutually exclusive with `categoryDenylist`.
|
|
127
|
+
*/
|
|
128
|
+
categoryAllowlist?: string[] | undefined;
|
|
129
|
+
/**
|
|
130
|
+
* Denylist of category names. If non-empty, detection results whose category
|
|
131
|
+
* name is in this set will be filtered out. Duplicate or unknown category
|
|
132
|
+
* names are ignored. Mutually exclusive with `categoryAllowlist`.
|
|
133
|
+
*/
|
|
134
|
+
categoryDenylist?: string[] | undefined;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** Options to configure the MediaPipe Embedder Task */
|
|
138
|
+
declare interface EmbedderOptions {
|
|
139
|
+
/** Options to configure the loading of the model assets. */
|
|
140
|
+
baseOptions?: BaseOptions;
|
|
141
|
+
/**
|
|
142
|
+
* Whether to normalize the returned feature vector with L2 norm. Use this
|
|
143
|
+
* option only if the model does not already contain a native L2_NORMALIZATION
|
|
144
|
+
* TF Lite Op. In most cases, this is already the case and L2 norm is thus
|
|
145
|
+
* achieved through TF Lite inference.
|
|
146
|
+
*/
|
|
147
|
+
l2Normalize?: boolean | undefined;
|
|
148
|
+
/**
|
|
149
|
+
* Whether the returned embedding should be quantized to bytes via scalar
|
|
150
|
+
* quantization. Embeddings are implicitly assumed to be unit-norm and
|
|
151
|
+
* therefore any dimension is guaranteed to have a value in [-1.0, 1.0]. Use
|
|
152
|
+
* the l2_normalize option if this is not the case.
|
|
153
|
+
*/
|
|
154
|
+
quantize?: boolean | undefined;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Copyright 2022 The MediaPipe Authors. All Rights Reserved.
|
|
159
|
+
*
|
|
160
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
161
|
+
* you may not use this file except in compliance with the License.
|
|
162
|
+
* You may obtain a copy of the License at
|
|
163
|
+
*
|
|
164
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
165
|
+
*
|
|
166
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
167
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
168
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
169
|
+
* See the License for the specific language governing permissions and
|
|
170
|
+
* limitations under the License.
|
|
171
|
+
*/
|
|
172
|
+
/**
|
|
173
|
+
* List of embeddings with an optional timestamp.
|
|
174
|
+
*
|
|
175
|
+
* One and only one of the two 'floatEmbedding' and 'quantizedEmbedding' will
|
|
176
|
+
* contain data, based on whether or not the embedder was configured to perform
|
|
177
|
+
* scalar quantization.
|
|
178
|
+
*/
|
|
179
|
+
declare interface Embedding {
|
|
180
|
+
/**
|
|
181
|
+
* Floating-point embedding. Empty if the embedder was configured to perform
|
|
182
|
+
* scalar-quantization.
|
|
183
|
+
*/
|
|
184
|
+
floatEmbedding?: number[];
|
|
185
|
+
/**
|
|
186
|
+
* Scalar-quantized embedding. Empty if the embedder was not configured to
|
|
187
|
+
* perform scalar quantization.
|
|
188
|
+
*/
|
|
189
|
+
quantizedEmbedding?: Uint8Array;
|
|
190
|
+
/**
|
|
191
|
+
* The index of the classifier head these categories refer to. This is
|
|
192
|
+
* useful for multi-head models.
|
|
193
|
+
*/
|
|
194
|
+
headIndex: number;
|
|
195
|
+
/**
|
|
196
|
+
* The name of the classifier head, which is the corresponding tensor
|
|
197
|
+
* metadata name.
|
|
198
|
+
*/
|
|
199
|
+
headName: string;
|
|
200
|
+
}
|
|
13
201
|
|
|
14
|
-
|
|
202
|
+
/** Embedding results for a given embedder model. */
|
|
203
|
+
declare interface EmbeddingResult {
|
|
204
|
+
/**
|
|
205
|
+
* The embedding results for each model head, i.e. one for each output tensor.
|
|
206
|
+
*/
|
|
207
|
+
embeddings: Embedding[];
|
|
208
|
+
/**
|
|
209
|
+
* The optional timestamp (in milliseconds) of the start of the chunk of
|
|
210
|
+
* data corresponding to these results.
|
|
211
|
+
*
|
|
212
|
+
* This is only used for embedding extraction on time series (e.g. audio
|
|
213
|
+
* embedding). In these use cases, the amount of data to process might
|
|
214
|
+
* exceed the maximum size that the model can process: to solve this, the
|
|
215
|
+
* input data is split into multiple chunks starting at different timestamps.
|
|
216
|
+
*/
|
|
217
|
+
timestampMs?: number;
|
|
218
|
+
}
|
|
15
219
|
|
|
16
220
|
/** A listener that will be invoked with an absl::StatusCode and message. */
|
|
17
221
|
declare type ErrorListener = (code: number, message: string) => void;
|
|
@@ -46,8 +250,10 @@ declare abstract class TaskRunner extends WasmMediaPipeImageLib {
|
|
|
46
250
|
private handleErrors;
|
|
47
251
|
}
|
|
48
252
|
|
|
253
|
+
export declare const TextClassifier: typeof TextClassifier_2;
|
|
254
|
+
|
|
49
255
|
/** Performs Natural Language classification. */
|
|
50
|
-
|
|
256
|
+
declare class TextClassifier_2 extends TaskRunner {
|
|
51
257
|
private classificationResult;
|
|
52
258
|
private readonly options;
|
|
53
259
|
/**
|
|
@@ -59,7 +265,7 @@ export declare class TextClassifier extends TaskRunner {
|
|
|
59
265
|
* either a path to the TFLite model or the model itself needs to be
|
|
60
266
|
* provided (via `baseOptions`).
|
|
61
267
|
*/
|
|
62
|
-
static createFromOptions(wasmLoaderOptions: WasmLoaderOptions, textClassifierOptions:
|
|
268
|
+
static createFromOptions(wasmLoaderOptions: WasmLoaderOptions, textClassifierOptions: ClassifierOptions): Promise<TextClassifier_2>;
|
|
63
269
|
/**
|
|
64
270
|
* Initializes the Wasm runtime and creates a new text classifier based on the
|
|
65
271
|
* provided model asset buffer.
|
|
@@ -67,7 +273,7 @@ export declare class TextClassifier extends TaskRunner {
|
|
|
67
273
|
* of the Wasm binary and its loader.
|
|
68
274
|
* @param modelAssetBuffer A binary representation of the model.
|
|
69
275
|
*/
|
|
70
|
-
static createFromModelBuffer(wasmLoaderOptions: WasmLoaderOptions, modelAssetBuffer: Uint8Array): Promise<
|
|
276
|
+
static createFromModelBuffer(wasmLoaderOptions: WasmLoaderOptions, modelAssetBuffer: Uint8Array): Promise<TextClassifier_2>;
|
|
71
277
|
/**
|
|
72
278
|
* Initializes the Wasm runtime and creates a new text classifier based on the
|
|
73
279
|
* path to the model asset.
|
|
@@ -75,7 +281,7 @@ export declare class TextClassifier extends TaskRunner {
|
|
|
75
281
|
* of the Wasm binary and its loader.
|
|
76
282
|
* @param modelAssetPath The path to the model asset.
|
|
77
283
|
*/
|
|
78
|
-
static createFromModelPath(wasmLoaderOptions: WasmLoaderOptions, modelAssetPath: string): Promise<
|
|
284
|
+
static createFromModelPath(wasmLoaderOptions: WasmLoaderOptions, modelAssetPath: string): Promise<TextClassifier_2>;
|
|
79
285
|
/**
|
|
80
286
|
* Sets new options for the text classifier.
|
|
81
287
|
*
|
|
@@ -85,7 +291,7 @@ export declare class TextClassifier extends TaskRunner {
|
|
|
85
291
|
*
|
|
86
292
|
* @param options The options for the text classifier.
|
|
87
293
|
*/
|
|
88
|
-
setOptions(options:
|
|
294
|
+
setOptions(options: ClassifierOptions): Promise<void>;
|
|
89
295
|
/**
|
|
90
296
|
* Performs Natural Language classification on the provided text and waits
|
|
91
297
|
* synchronously for the response.
|
|
@@ -93,14 +299,89 @@ export declare class TextClassifier extends TaskRunner {
|
|
|
93
299
|
* @param text The text to process.
|
|
94
300
|
* @return The classification result of the text
|
|
95
301
|
*/
|
|
96
|
-
classify(text: string):
|
|
302
|
+
classify(text: string): ClassificationResult;
|
|
97
303
|
/** Updates the MediaPipe graph configuration. */
|
|
98
304
|
private refreshGraph;
|
|
99
305
|
}
|
|
100
306
|
|
|
101
|
-
export
|
|
307
|
+
export declare const TextEmbedder: typeof TextEmbedder_2;
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* Performs embedding extraction on text.
|
|
311
|
+
*/
|
|
312
|
+
declare class TextEmbedder_2 extends TaskRunner {
|
|
313
|
+
private embeddingResult;
|
|
314
|
+
private readonly options;
|
|
315
|
+
/**
|
|
316
|
+
* Initializes the Wasm runtime and creates a new text embedder from the
|
|
317
|
+
* provided options.
|
|
318
|
+
* @param wasmLoaderOptions A configuration object that provides the location
|
|
319
|
+
* of the Wasm binary and its loader.
|
|
320
|
+
* @param textEmbedderOptions The options for the text embedder. Note that
|
|
321
|
+
* either a path to the TFLite model or the model itself needs to be
|
|
322
|
+
* provided (via `baseOptions`).
|
|
323
|
+
*/
|
|
324
|
+
static createFromOptions(wasmLoaderOptions: WasmLoaderOptions, textEmbedderOptions: EmbedderOptions): Promise<TextEmbedder_2>;
|
|
325
|
+
/**
|
|
326
|
+
* Initializes the Wasm runtime and creates a new text embedder based on the
|
|
327
|
+
* provided model asset buffer.
|
|
328
|
+
* @param wasmLoaderOptions A configuration object that provides the location
|
|
329
|
+
* of the Wasm binary and its loader.
|
|
330
|
+
* @param modelAssetBuffer A binary representation of the TFLite model.
|
|
331
|
+
*/
|
|
332
|
+
static createFromModelBuffer(wasmLoaderOptions: WasmLoaderOptions, modelAssetBuffer: Uint8Array): Promise<TextEmbedder_2>;
|
|
333
|
+
/**
|
|
334
|
+
* Initializes the Wasm runtime and creates a new text embedder based on the
|
|
335
|
+
* path to the model asset.
|
|
336
|
+
* @param wasmLoaderOptions A configuration object that provides the location
|
|
337
|
+
* of the Wasm binary and its loader.
|
|
338
|
+
* @param modelAssetPath The path to the TFLite model.
|
|
339
|
+
*/
|
|
340
|
+
static createFromModelPath(wasmLoaderOptions: WasmLoaderOptions, modelAssetPath: string): Promise<TextEmbedder_2>;
|
|
341
|
+
/**
|
|
342
|
+
* Sets new options for the text embedder.
|
|
343
|
+
*
|
|
344
|
+
* Calling `setOptions()` with a subset of options only affects those options.
|
|
345
|
+
* You can reset an option back to its default value by explicitly setting it
|
|
346
|
+
* to `undefined`.
|
|
347
|
+
*
|
|
348
|
+
* @param options The options for the text embedder.
|
|
349
|
+
*/
|
|
350
|
+
setOptions(options: EmbedderOptions): Promise<void>;
|
|
351
|
+
/**
|
|
352
|
+
* Performs embeding extraction on the provided text and waits synchronously
|
|
353
|
+
* for the response.
|
|
354
|
+
*
|
|
355
|
+
* @param text The text to process.
|
|
356
|
+
* @return The embedding resuls of the text
|
|
357
|
+
*/
|
|
358
|
+
embed(text: string): EmbeddingResult;
|
|
359
|
+
/** Updates the MediaPipe graph configuration. */
|
|
360
|
+
private refreshGraph;
|
|
361
|
+
}
|
|
102
362
|
|
|
103
|
-
|
|
363
|
+
/**
|
|
364
|
+
* Copyright 2022 The MediaPipe Authors. All Rights Reserved.
|
|
365
|
+
*
|
|
366
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
367
|
+
* you may not use this file except in compliance with the License.
|
|
368
|
+
* You may obtain a copy of the License at
|
|
369
|
+
*
|
|
370
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
371
|
+
*
|
|
372
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
373
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
374
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
375
|
+
* See the License for the specific language governing permissions and
|
|
376
|
+
* limitations under the License.
|
|
377
|
+
*/
|
|
378
|
+
/** An object containing the locations of all Wasm assets */
|
|
379
|
+
declare interface WasmLoaderOptions {
|
|
380
|
+
/** The path to the Wasm loader script. */
|
|
381
|
+
wasmLoaderPath: string;
|
|
382
|
+
/** The path to the Wasm binary. */
|
|
383
|
+
wasmBinaryPath: string;
|
|
384
|
+
}
|
|
104
385
|
|
|
105
386
|
declare const WasmMediaPipeImageLib: (new (...args: any[]) => {
|
|
106
387
|
registerModelResourcesGraphService(): void;
|