Tác vụ Trình phát hiện ngôn ngữ MediaPipe cho phép bạn xác định ngôn ngữ của một đoạn văn bản. Tác vụ này hoạt động trên dữ liệu văn bản bằng mô hình học máy (ML) và xuất ra danh sách các dự đoán, trong đó mỗi dự đoán bao gồm một mã ngôn ngữ ISO 639-1 và một xác suất.
Bắt đầu sử dụng tác vụ này bằng cách làm theo một trong các hướng dẫn triển khai sau đây cho nền tảng mục tiêu của bạn. Các hướng dẫn dành riêng cho nền tảng này sẽ hướng dẫn bạn cách triển khai cơ bản cho tác vụ này, bao gồm cả mô hình được đề xuất và ví dụ về mã với các tuỳ chọn cấu hình được đề xuất:
Phần này mô tả các tính năng, dữ liệu đầu vào, dữ liệu đầu ra và tuỳ chọn cấu hình của tác vụ này.
Tính năng
Ngưỡng điểm – Lọc kết quả dựa trên điểm dự đoán
Nhãn danh sách cho phép và danh sách từ chối – Chỉ định các danh mục đã phát hiện
Dữ liệu đầu vào của việc cần làm
Kết quả của tác vụ
Trình phát hiện ngôn ngữ chấp nhận loại dữ liệu đầu vào sau:
Chuỗi
Trình phát hiện ngôn ngữ sẽ xuất ra một danh sách các cụm từ dự đoán chứa:
Mã ngôn ngữ: Mã ngôn ngữ/ngôn ngữ theo chuẩn ISO 639-1 (https://en.wikipedia.org/wiki / List_of_ISO_639-1_codes) (ví dụ: "en" cho tiếng Anh, "uz" cho tiếng Uzbek, "ja-Latn" cho tiếng Nhật (romaji)) dưới dạng chuỗi.
Xác suất: điểm tin cậy cho dự đoán này, được biểu thị dưới dạng xác suất từ 0 đến 1 dưới dạng giá trị dấu phẩy động.
Tuỳ chọn cấu hình
Tác vụ này có các tuỳ chọn cấu hình sau:
Tên tuỳ chọn
Mô tả
Phạm vi giá trị
Giá trị mặc định
max_results
Đặt số lượng tối đa (không bắt buộc) của các cụm từ gợi ý ngôn ngữ có điểm số cao nhất để trả về. Nếu giá trị này nhỏ hơn 0, tất cả kết quả có sẵn sẽ được trả về.
Bất kỳ số dương nào
-1
score_threshold
Đặt ngưỡng điểm số dự đoán sẽ ghi đè ngưỡng được cung cấp trong siêu dữ liệu mô hình (nếu có). Kết quả thấp hơn giá trị này sẽ bị từ chối.
Bất kỳ float nào
Chưa đặt
category_allowlist
Đặt danh sách tuỳ chọn gồm các mã ngôn ngữ được phép. Nếu không trống, các dự đoán ngôn ngữ có mã ngôn ngữ không có trong tập hợp này sẽ bị lọc ra. Tuỳ chọn này loại trừ lẫn nhau với category_denylist và việc sử dụng cả hai sẽ dẫn đến lỗi.
Chuỗi bất kỳ
Chưa đặt
category_denylist
Đặt danh sách không bắt buộc gồm các mã ngôn ngữ không được phép. Nếu không trống, các dự đoán ngôn ngữ có mã ngôn ngữ nằm trong tập hợp này sẽ bị lọc ra. Tuỳ chọn này loại trừ lẫn nhau với category_allowlist và việc sử dụng cả hai sẽ dẫn đến lỗi.
Chuỗi bất kỳ
Chưa đặt
Mô hình
Chúng tôi cung cấp một mô hình mặc định, được đề xuất khi bạn bắt đầu phát triển bằng nhiệm vụ này.
Mô hình trình phát hiện ngôn ngữ (nên dùng)
Mô hình này được xây dựng để có kích thước nhỏ (315 KB) và sử dụng kiến trúc phân loại mạng nơron dựa trên tính năng nhúng. Mô hình này xác định ngôn ngữ bằng mã ngôn ngữ ISO 639-1 và có thể xác định 110 ngôn ngữ. Để biết danh sách ngôn ngữ mà mô hình hỗ trợ, hãy xem tệp nhãn. Tệp này liệt kê các ngôn ngữ theo mã ISO 639-1.
Dưới đây là điểm chuẩn tác vụ cho toàn bộ quy trình dựa trên các mô hình được huấn luyện trước ở trên. Kết quả về độ trễ là độ trễ trung bình trên Pixel 6 khi sử dụng CPU / GPU.
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 2025-01-13 UTC."],[],[],null,["# Language detection guide\n\nThe MediaPipe Language Detector task lets you identify the language of a piece of text. This\ntask operates on text data with a machine learning (ML) model and outputs a list\nof predictions, where each prediction consists of an\n[ISO 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) language code\nand a probability.\n\n[Try it!arrow_forward](https://mediapipe-studio.webapps.google.com/demo/language_detector)\n\nGet Started\n-----------\n\nStart using this task by following one of these implementation guides for your\ntarget platform. These platform-specific guides walk you through a basic\nimplementation of this task, including a recommended model, and code example\nwith recommended configuration options:\n\n- **Android** - [Code example](https://github.com/google-ai-edge/mediapipe-samples/tree/main/examples/language_detector/android) - [Guide](./android)\n- **Python** - [Code example](https://colab.research.google.com/github/googlesamples/mediapipe/blob/main/examples/language_detector/python/%5BMediaPipe_Python_Tasks%5D_Language_Detector.ipynb) - [Guide](./python)\n- **Web** - [Code example](https://codepen.io/mediapipe-preview/pen/RweLdpK) - [Guide](./web_js)\n\nTask details\n------------\n\nThis section describes the capabilities, inputs, outputs, and configuration\noptions of this task.\n\n### Features\n\n- **Score threshold** - Filter results based on prediction scores\n- **Label allowlist and denylist** - Specify the categories detected\n\n| Task inputs | Task outputs |\n|-------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| Language Detector accepts the following input data type: - String | Language Detector outputs a list of predictions containing: - Language code: An ISO 639-1 (https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) language / locale code (e.g. \"en\" for English, \"uz\" for Uzbek, \"ja-Latn\" for Japanese (romaji)) as a string. \u003c!-- --\u003e - Probability: the confidence score for this prediction, expressed as a probability between zero and one as floating point value. |\n\n### Configurations options\n\nThis task has the following configuration options:\n\n| Option Name | Description | Value Range | Default Value |\n|----------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------|---------------|\n| `max_results` | Sets the optional maximum number of top-scored language predictions to return. If this value is less than zero, all available results are returned. | Any positive numbers | `-1` |\n| `score_threshold` | Sets the prediction score threshold that overrides the one provided in the model metadata (if any). Results below this value are rejected. | Any float | Not set |\n| `category_allowlist` | Sets the optional list of allowed language codes. If non-empty, language predictions whose language code is not in this set will be filtered out. This option is mutually exclusive with `category_denylist` and using both results in an error. | Any strings | Not set |\n| `category_denylist` | Sets the optional list of language codes that are not allowed. If non-empty, language predictions whose language code is in this set will be filtered out. This option is mutually exclusive with `category_allowlist` and using both results in an error. | Any strings | Not set |\n\nModels\n------\n\nWe offer a default, recommended model when you start developing with this task.\n| **Attention:** This MediaPipe Solutions Preview is an early release. [Learn more](/edge/mediapipe/solutions/about#notice).\n\n### Language detector model (recommended)\n\nThis model is built to be lightweight (315 KB) and uses embedding-based, neural\nnetwork classification architecture. The model identifies language using an\n[ISO 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) language\ncode, and can identify 110 languages. For a list of languages supported by the\nmodel, see the\n[label file](https://storage.googleapis.com/mediapipe-tasks/language_detector/labels.txt),\nwhich lists languages by their ISO 639-1 code.\n\n| Model name | Input shape | Quantization type | Model card | Versions |\n|---------------------------------------------------------------------------------------------------------------------------------------------|--------------|-------------------|---------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------|\n| [Language Detector](https://storage.googleapis.com/mediapipe-models/language_detector/language_detector/float32/1/language_detector.tflite) | string UTF-8 | none (float32) | [info](https://storage.googleapis.com/mediapipe-assets/LanguageDetector%20Model%20Card.pdf) | [Latest](https://storage.googleapis.com/mediapipe-models/language_detector/language_detector/float32/1/language_detector.tflite) |\n\nTask benchmarks\n---------------\n\nHere's the task benchmarks for the whole pipeline based on the above\npre-trained models. The latency result is the average latency on Pixel 6 using\nCPU / GPU.\n\n| Model Name | CPU Latency | GPU Latency |\n|-------------------|-------------|-------------|\n| Language Detector | 0.31ms | - |"]]