@mediapipe/tasks-text 0.1.0-alpha-7 → 0.1.0-alpha-9
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/README.md
CHANGED
|
@@ -2,9 +2,23 @@
|
|
|
2
2
|
|
|
3
3
|
This package contains the text tasks for MediaPipe.
|
|
4
4
|
|
|
5
|
+
## Language Detection
|
|
6
|
+
|
|
7
|
+
The MediaPipe Language Detector task predicts the language of an input text.
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
const text = await FilesetResolver.forTextTasks(
|
|
11
|
+
"https://cdn.jsdelivr.net/npm/@mediapipe/tasks-text@latest/wasm"
|
|
12
|
+
);
|
|
13
|
+
const languageDetector = await LanguageDetector.createFromModelPath(text,
|
|
14
|
+
"model.tflite"
|
|
15
|
+
);
|
|
16
|
+
const result = languageDetector.detect(textData);
|
|
17
|
+
```
|
|
18
|
+
|
|
5
19
|
## Text Classification
|
|
6
20
|
|
|
7
|
-
MediaPipe Text Classifier task lets you classify text into a set of defined
|
|
21
|
+
The MediaPipe Text Classifier task lets you classify text into a set of defined
|
|
8
22
|
categories, such as positive or negative sentiment.
|
|
9
23
|
|
|
10
24
|
```
|
package/package.json
CHANGED
package/text.d.ts
CHANGED
|
@@ -256,6 +256,90 @@ export declare class FilesetResolver {
|
|
|
256
256
|
static forVisionTasks(basePath?: string): Promise<WasmFileset>;
|
|
257
257
|
}
|
|
258
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
|
+
|
|
259
343
|
/** Base class for all MediaPipe Tasks. */
|
|
260
344
|
declare abstract class TaskRunner {
|
|
261
345
|
protected constructor();
|