تتيح لك مهمة "إدراج النص" في MediaPipe إنشاء تمثيل رقمي لبيانات النص بهدف
التقاط معناها الدلالي. تُستخدَم هذه الوظيفة كثيرًا لمقارنة
التشابه الدلالي بين قطعتَي نص باستخدام أساليب مقارنة
رياضية، مثل التشابه القائم على دالة الجيبّ cosine. تعمل هذه المهمة على بيانات النص باستخدام نموذج تعلُّم الآلة، وتُخرج تمثيلًا رقميًا لبيانات النص على شكل قائمة بمتجهات السمات العالية الأبعاد، والتي تُعرف أيضًا باسم متجهات التضمين، سواء بتنسيق النقطة العائمة أو بتنسيق الكمّي.
ابدأ استخدام هذه المهمة باتّباع أحد أدلة التنفيذ هذه ل منصّتك المستهدفة. ترشدك هذه الأدلة الخاصة بالنظام الأساسي إلى تنفيذ أساسي
لهذه المهمة، بما في ذلك نموذج مقترَح ومثال على الرمز المبرمَج
مع خيارات الإعداد المقترَحة:
يصف هذا القسم ميزات هذه المهمة ومدخلاتها ومخرجاتها وخيارات الضبط.
الميزات
معالجة نص الإدخال: تتيح هذه الميزة تقسيم النصوص إلى وحدات خارج الرسم البياني للنماذج
بدون تقسيم النصوص إلى وحدات داخل الرسم البياني.
حساب التشابه في الدمج: دالة مساعدة مضمّنة لاحتساب تشابه جيب التمام بين متجهَين للميزات
التكمية: تتيح هذه الطريقة استخدام الكمّات على مستوى العنصر الواحد في متجهات السمات.
مدخلات المهام
نتائج المهام
يقبل "مُضمِّن النصوص" نوع بيانات الإدخال التالي:
سلسلة
تُخرج أداة "إدراج النصوص" قائمة بإدراجات تتألف من:
التضمين: مصفوفة السمات نفسها، إما بتنسيق النقطة العائمة أو
بترميز متّجه
فهرس العنوان: فهرس العنوان الذي أنتج هذا التضمين.
اسم العنوان (اختياري): اسم العنوان الذي أنشأ هذا التضمين.
خيارات الإعدادات
تتضمّن هذه المهمة خيارات الضبط التالية:
اسم الخيار
الوصف
نطاق القيمة
القيمة التلقائية
l2_normalize
ما إذا كان يجب تطبيع متجه السمات المعروض باستخدام معيار L2
لا تستخدِم هذا الخيار إلا إذا كان النموذج لا يحتوي على خطوة معالجة برمجية أساسية
L2_NORMALIZATION من TFLite. وفي معظم الحالات، يكون هذا هو الحال، وبالتالي يتم تحقيق
تسويّة L2 من خلال الاستنتاج باستخدام TFLite بدون الحاجة
إلى هذا الخيار.
Boolean
False
quantize
ما إذا كان يجب تجزئة البيانات المضمّنة التي تم إرجاعها إلى وحدات بايت من خلال
التجزئة على مستوى مقياس واحد يُفترض ضمنيًا أنّ القيم المضمّنة هي قيم عادية و
بالتالي، يُضمن أن تكون قيمة أيّ سمة ضمن النطاق [-1.0, 1.0]. استخدِم
الخيار l2_normalize إذا لم يكن الأمر كذلك.
Boolean
False
النماذج
نقدّم نموذجًا تلقائيًا مقترَحًا عند بدء التطوير باستخدام هذه المهمة.
نموذج Universal Sentence Encoder (مُقترَح)
يستخدم هذا النموذج بنية برنامج ترميز مزدوج
وقد تم تدريبه على مجموعات بيانات مختلفة من الأسئلة والأجوبة.
راجِع أزواج الجمل التالية:
("إنّها رحلة ساحرة ومؤثرة في كثير من الأحيان"، "ما أروع هذه الرحلة الرائعة")
("أحب هاتفي"، "أكره هاتفي")
("يقدّم هذا المطعم عروضًا رائعة"، "علينا التحقّق من تفاصيل خطّتنا مرة أخرى")
سيكون لتضمين النصوص في أول زوجَين من الجمل تشابهًا أكبر في دالة الجيب الزائد مقارنةً بالتضمين في الزوج الثالث من الجمل، لأنّ أول زوجَين من الجمل يتشاركان موضوعًا شائعًا هو "الشعور بالرحلة" و "رأي حول الهاتف" على التوالي، في حين أنّه
لا يتشارك الزوج الثالث من الجمل موضوعًا شائعًا.
تجدر الإشارة إلى أنّه على الرغم من أنّ الجملتَين في الزوج الثاني تتضمّنان مشاعر متعارضة،
تحصلان على نتيجة تشابه عالية لأنّهما تتشاركان موضوعًا مشتركًا.
في ما يلي مقاييس أداء المهام لعملية المعالجة بأكملها استنادًا إلى نماذج pretrained
المدرَّبة مسبقًا أعلاه. نتيجة وقت الاستجابة هي متوسط وقت الاستجابة على هاتف Pixel 6 باستخدام
وحدة المعالجة المركزية / وحدة معالجة الرسومات.
تاريخ التعديل الأخير: 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 | - |"]]