Detyra MediaPipe Text Embedder ju lejon të krijoni një paraqitje numerike të të dhënave të tekstit për të kapur kuptimin e tij semantik. Ky funksionalitet përdoret shpesh për të krahasuar ngjashmërinë semantike të dy pjesëve të tekstit duke përdorur teknika krahasimi matematikore si ngjashmëria e kosinusit. Kjo detyrë funksionon në të dhënat e tekstit me një model të mësimit të makinerive (ML) dhe nxjerr një paraqitje numerike të të dhënave të tekstit si një listë e vektorëve të veçorive me dimensione të larta, të njohura edhe si vektorë të ngulitur, në formë me pikë lundruese ose të kuantizuar.
Filloni ta përdorni këtë detyrë duke ndjekur një nga këto udhëzues zbatimi për platformën tuaj të synuar. Këta udhëzues specifikë të platformës ju përcjellin një zbatim bazë të kësaj detyre, duke përfshirë një model të rekomanduar dhe shembull kodi me opsionet e rekomanduara të konfigurimit:
Ky seksion përshkruan aftësitë, hyrjet, daljet dhe opsionet e konfigurimit të kësaj detyre.
Veçoritë
Përpunimi i tekstit të hyrjes - Mbështet tokenizimin jashtë grafikut për modelet pa tokenizimin në grafik.
Përfshirja e llogaritjes së ngjashmërisë - Funksioni i integruar i ndihmës për të llogaritur ngjashmërinë e kosinusit midis dy vektorëve të veçorive.
Kuantizimi - Mbështet kuantizimin skalar për vektorët e veçorive.
Hyrjet e detyrave
Rezultatet e detyrave
Teksti Embedder pranon llojin e mëposhtëm të të dhënave hyrëse:
Vargu
Teksti Embedder nxjerr një listë të përfshirjeve që përbëhet nga:
Embedding: Vektori i veçorive në vetvete, qoftë në formë me pikë lundruese ose të kuantizuar në shkallë.
Indeksi i kokës: indeksi për kokën që ka prodhuar këtë ngulitje.
Emri i kokës (opsionale): emri i kokës që ka prodhuar këtë ngulitje.
Opsionet e konfigurimeve
Kjo detyrë ka opsionet e mëposhtme të konfigurimit:
Emri i opsionit
Përshkrimi
Gama e vlerave
Vlera e paracaktuar
l2_normalize
Nëse do të normalizohet vektori i tipareve të kthyera me normën L2. Përdoreni këtë opsion vetëm nëse modeli nuk përmban tashmë një L2_NORMALIZATION TFLite Op. Në shumicën e rasteve, ky është tashmë rasti dhe normalizimi i L2 arrihet në këtë mënyrë përmes përfundimit të TFLite pa pasur nevojë për këtë opsion.
Boolean
False
quantize
Nëse futja e kthyer duhet të kuantizohet në bajt nëpërmjet kuantizimit skalar. Përfshirjet supozohen në mënyrë implicite si njësi-normë dhe për këtë arsye çdo dimension është i garantuar të ketë një vlerë në [-1.0, 1.0]. Përdorni opsionin l2_normalize nëse nuk është kështu.
Boolean
False
Modelet
Ne ofrojmë një model të paracaktuar, të rekomanduar kur filloni të zhvilloni këtë detyrë.
Modeli i koduesit universal të fjalive (rekomandohet)
("Ky restorant ka një mashtrim të madh", "Duhet të kontrollojmë dy herë detajet e planit tonë")
Përfshirjet e tekstit në dy çiftet e para do të kenë një ngjashmëri më të lartë kosinusi sesa futjet në çiftin e tretë, sepse dy palët e para të fjalive ndajnë një temë të përbashkët përkatësisht "ndjenja e udhëtimit" dhe "mendimi i telefonit", ndërsa çifti i tretë i fjalive po nuk ndajnë një temë të përbashkët.
Vini re se megjithëse dy fjalitë në çiftin e dytë kanë ndjenja të kundërta, ato kanë një rezultat të lartë ngjashmërie sepse ndajnë një temë të përbashkët.
Këtu janë standardet e detyrave për të gjithë tubacionin bazuar në modelet e mësipërme të para-trajnuara. Rezultati i vonesës është vonesa mesatare në Pixel 6 duke përdorur CPU / GPU.
[[["E lehtë për t'u kuptuar","easyToUnderstand","thumb-up"],["E zgjidhi problemin tim","solvedMyProblem","thumb-up"],["Tjetër","otherUp","thumb-up"]],[["Mungojnë informacionet që më nevojiten","missingTheInformationINeed","thumb-down"],["Shumë e ndërlikuar/shumë hapa","tooComplicatedTooManySteps","thumb-down"],["E papërditësuar","outOfDate","thumb-down"],["Problem përkthimi","translationIssue","thumb-down"],["Problem me kampionët/kodin","samplesCodeIssue","thumb-down"],["Tjetër","otherDown","thumb-down"]],["Përditësimi i fundit: 2025-01-13 UTC."],[],[],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 | - |"]]