وظیفه MediaPipe Text Embedder به شما امکان می دهد یک نمایش عددی از داده های متنی ایجاد کنید تا معنای معنایی آن را دریافت کنید. این قابلیت اغلب برای مقایسه شباهت معنایی دو قطعه متن با استفاده از تکنیک های مقایسه ریاضی مانند شباهت کسینوس استفاده می شود. این وظیفه بر روی دادههای متنی با مدل یادگیری ماشین (ML) عمل میکند و نمایش عددی دادههای متنی را بهعنوان فهرستی از بردارهای ویژگی با ابعاد بالا، که بهعنوان بردارهای جاسازی نیز شناخته میشوند، به صورت ممیز شناور یا کوانتیزه شده، خروجی میدهد.
استفاده از این کار را با دنبال کردن یکی از این راهنماهای پیاده سازی برای پلتفرم هدف خود شروع کنید. این راهنماهای مخصوص پلتفرم شما را از طریق اجرای اساسی این کار، از جمله یک مدل توصیه شده، و نمونه کد با گزینه های پیکربندی توصیه شده، راهنمایی می کنند:
این بخش قابلیت ها، ورودی ها، خروجی ها و گزینه های پیکربندی این کار را شرح می دهد.
ویژگی ها
پردازش متن ورودی - از توکنسازی خارج از نمودار برای مدلهای بدون نشانهسازی درون گراف پشتیبانی میکند.
تعبیه محاسبات شباهت - تابع ابزار داخلی برای محاسبه شباهت کسینوس بین دو بردار ویژگی.
Quantization - از کوانتیزهسازی اسکالر برای بردارهای ویژگی پشتیبانی میکند.
ورودی های وظیفه
خروجی های وظیفه
Text Embedder نوع داده ورودی زیر را می پذیرد:
رشته
Text Embedder لیستی از جاسازیها شامل موارد زیر را خروجی میدهد:
جاسازی: خود بردار ویژگی، چه به صورت ممیز شناور و چه به صورت اسکالر کوانتیزه شده است.
نمایه سر: نمایه سر که این تعبیه را ایجاد کرده است.
نام سر (اختیاری): نام سر که این تعبیه را ایجاد کرده است.
گزینه های پیکربندی
این کار دارای گزینه های پیکربندی زیر است:
نام گزینه
توضیحات
محدوده ارزش
مقدار پیش فرض
l2_normalize
آیا باید بردار ویژگی بازگشتی را با نرمال L2 عادی سازی کرد. فقط در صورتی از این گزینه استفاده کنید که مدل از قبل دارای یک L2_NORMALIZATION TFLite Op بومی نباشد. در بیشتر موارد، این قبلاً وجود دارد و بنابراین عادی سازی L2 از طریق استنتاج TFLite بدون نیاز به این گزینه حاصل می شود.
Boolean
False
quantize
اینکه آیا تعبیه برگشتی باید از طریق کوانتیزه کردن اسکالر به بایت تبدیل شود یا خیر. تعبیهها به طور ضمنی واحد هنجار فرض میشوند و بنابراین هر بعد تضمین میشود که مقداری در [-1.0، 1.0] داشته باشد. اگر اینطور نیست از گزینه l2_normalize استفاده کنید.
Boolean
False
مدل ها
هنگامی که شما شروع به توسعه با این کار می کنید، یک مدل پیش فرض و توصیه شده را ارائه می دهیم.
مدل رمزگذار جمله جهانی (توصیه می شود)
این مدل از معماری رمزگذار دوگانه استفاده می کند و بر روی مجموعه داده های مختلف پرسش و پاسخ آموزش داده شده است.
جفت جمله زیر را در نظر بگیرید:
("این یک سفر جذاب و اغلب تاثیرگذار است"، "چه سفر عالی و خارق العاده ای")
("من تلفنم را دوست دارم"، "از تلفنم متنفرم")
("این رستوران یک ترفند عالی دارد"، "ما باید جزئیات برنامه خود را دوباره بررسی کنیم")
جاسازیهای متن در دو جفت اول شباهت کسینوس بالاتری نسبت به جاسازیهای جفت سوم دارند، زیرا دو جفت جملات اول به ترتیب موضوع مشترک «احساس سفر» و «نظر تلفن» دارند در حالی که جفت جملات سوم دارای یک موضوع مشترک هستند. یک موضوع مشترک را به اشتراک نگذارید
توجه داشته باشید که اگرچه دو جمله در جفت دوم دارای احساسات متضاد هستند، اما به دلیل اشتراک در موضوع مشترک دارای امتیاز شباهت بالایی هستند.
تاریخ آخرین بهروزرسانی 2025-01-13 بهوقت ساعت هماهنگ جهانی.
[[["درک آسان","easyToUnderstand","thumb-up"],["مشکلم را برطرف کرد","solvedMyProblem","thumb-up"],["غیره","otherUp","thumb-up"]],[["اطلاعاتی که نیاز دارم وجود ندارد","missingTheInformationINeed","thumb-down"],["بیشازحد پیچیده/ مراحل بسیار زیاد","tooComplicatedTooManySteps","thumb-down"],["قدیمی","outOfDate","thumb-down"],["مشکل ترجمه","translationIssue","thumb-down"],["مشکل کد / نمونهها","samplesCodeIssue","thumb-down"],["غیره","otherDown","thumb-down"]],["تاریخ آخرین بهروزرسانی 2025-01-13 بهوقت ساعت هماهنگ جهانی."],[],[],null,["# Text embedding guide\n\nThe MediaPipe Text Embedder task lets you create a numeric representation of text data to\ncapture its semantic meaning. This functionality is frequently used to compare\nthe semantic similarity of two pieces of text using mathematical comparison\ntechniques such as Cosine Similarity. This task operates on text data with a\nmachine learning (ML) model, and outputs a numeric representation of the text\ndata as a list of high-dimensional feature vectors, also known as embedding\nvectors, in either floating-point or quantized form.\n\n[Try it!arrow_forward](https://mediapipe-studio.webapps.google.com/demo/text_embedder)\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\n example](https://github.com/google-ai-edge/mediapipe-samples/tree/main/examples/text_embedder/android) - [Guide](./android)\n- **Python** - [Code\n example](https://colab.sandbox.google.com/github/googlesamples/mediapipe/blob/main/examples/text_embedder/python/text_embedder.ipynb) - [Guide](./python)\n- **Web** - [Code example](https://codepen.io/mediapipe-preview/pen/XWBVZmE) - [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- **Input text processing** - Supports out-of-graph tokenization for models without in-graph tokenization.\n- **Embedding similarity computation** - Built-in utility function to compute the [cosine similarity](https://en.wikipedia.org/wiki/Cosine_similarity) between two feature vectors.\n- **Quantization** - Supports scalar quantization for the feature vectors.\n\n| Task inputs | Task outputs |\n|---------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| Text Embedder accepts the following input data type: - String | Text Embedder outputs a list of embeddings consisting of: - Embedding: the feature vector itself, either in floating-point form or scalar-quantized. \u003c!-- --\u003e - Head index: the index for the head that produced this embedding. \u003c!-- --\u003e - Head name (optional): the name of the head that produced this embedding. |\n\n### Configurations options\n\nThis task has the following configuration options:\n\n| Option Name | Description | Value Range | Default Value |\n|----------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------|---------------|\n| `l2_normalize` | Whether to normalize the returned feature vector with L2 norm. Use this option only if the model does not already contain a native L2_NORMALIZATION TFLite Op. In most cases, this is already the case and L2 normalization is thus achieved through TFLite inference with no need for this option. | `Boolean` | `False` |\n| `quantize` | Whether the returned embedding should be quantized to bytes via scalar quantization. Embeddings are implicitly assumed to be unit-norm and therefore any dimension is guaranteed to have a value in \\[-1.0, 1.0\\]. Use the l2_normalize option if this is not the case. | `Boolean` | `False` |\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### Universal Sentence Encoder model (recommended)\n\nThis model uses a [dual encoder architecture](https://aclanthology.org/2022.emnlp-main.640.pdf)\nand was trained on various question-answer datasets.\n\nConsider the following pairs of sentences:\n\n- (\"it's a charming and often affecting journey\", \"what a great and fantastic trip\")\n- (\"I like my phone\", \"I hate my phone\")\n- (\"This restaurant has a great gimmick\", \"We need to double-check the details of our plan\")\n\nThe text embeddings in the first two pairs will have a higher cosine similarity\nthan the embeddings in the third pair because the first two pairs of sentences\nshare a common topic of \"trip sentiment\" and \"phone opinion\" respectively while\nthe third pair of sentences do not share a common topic.\n\nNote that although the two sentences in the second pair have opposing sentiments,\nthey have a high similarity score because they share a common topic.\n\n| Model name | Input shape | Quantization type | Versions |\n|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------|-------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------|\n| [Universal Sentence Encoder](https://storage.googleapis.com/mediapipe-models/text_embedder/universal_sentence_encoder/float32/latest/universal_sentence_encoder.tflite) | string, string, string | None (float32) | [Latest](https://storage.googleapis.com/mediapipe-models/text_embedder/universal_sentence_encoder/float32/latest/universal_sentence_encoder.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| Universal Sentence Encoder | 18.21ms | - |"]]