MediaPipe metin yerleştirme görevi, metin verilerinin anlamsal anlamını yakalamak için sayısal bir temsili oluşturmanıza olanak tanır. Bu işlev, kosinüs benzerliği gibi matematiksel karşılaştırma tekniklerini kullanarak iki metnin semantik benzerliğini karşılaştırmak için sıklıkla kullanılır. Bu görev, makine öğrenimi (ML) modeli ile metin verileri üzerinde çalışır ve metin verilerinin sayısal bir temsilini, kayan nokta veya kesirli biçimde, yerleştirme vektörleri olarak da bilinen yüksek boyutlu özellik vektörlerinin listesi olarak döndürür.
Hedef platformunuzla ilgili bu uygulama kılavuzlarından birini uygulayarak bu görevi kullanmaya başlayın. Platforma özel bu kılavuzlar, önerilen bir model ve önerilen yapılandırma seçenekleriyle birlikte kod örneği de dahil olmak üzere bu görevin temel uygulama sürecinde size yol gösterir:
Bu bölümde, bu görevin özellikleri, girişleri, çıkışları ve yapılandırma seçenekleri açıklanmaktadır.
Özellikler
Giriş metni işleme: Grafik içi jeton oluşturma özelliği olmayan modeller için grafik dışı jeton oluşturmayı destekler.
Embedding benzerlik hesaplaması: İki özellik vektori arasındaki kosinüs benzerliğini hesaplamak için yerleşik yardımcı program işlevi.
Nicemleme: Özellik vektörleri için skaler nicelemeyi destekler.
Görev girişleri
Görev çıkışları
Metin Yerleştirici, aşağıdaki giriş veri türünü kabul eder:
Dize
Metin Gömücü, aşağıdakilerden oluşan bir gömülü metin listesi döndürür:
Yerleştirme: Özellik vektörünün kendisi, kayan noktalı biçimde veya skaler olarak kesikli.
Baş dizini: Bu yerleştirmeyi oluşturan başlığın dizini.
Başlık adı (isteğe bağlı): Bu yerleştirmeyi oluşturan başlığın adı.
Yapılandırma seçenekleri
Bu görev için aşağıdaki yapılandırma seçenekleri vardır:
Seçenek Adı
Açıklama
Değer Aralığı
Varsayılan değer
l2_normalize
Döndürülen özellik vektörünün L2 normuyla normalleştirilip normalleştirilmeyeceği.
Bu seçeneği yalnızca modelde halihazırda doğal bir L2_NORMALIZATION TFLite Op içermiyorsa kullanın. Çoğu durumda bu durum geçerlidir ve L2 normalleştirmesi, bu seçeneğe gerek kalmadan TFLite çıkarımıyla elde edilir.
Boolean
False
quantize
Döndürülen yerleştirmenin skaler kesme işlemiyle baytlara bölünüp bölünmeyeceği. Yerleşimlerin birim normal olduğu varsayılır ve bu nedenle tüm boyutların [-1,0; 1,0] aralığında bir değere sahip olduğu garanti edilir. Aksi takdirde l2_normalize seçeneğini kullanın.
Boolean
False
Modeller
Bu görevle geliştirmeye başladığınızda varsayılan olarak önerilen bir model sunarız.
Evrensel Cümle Kodlayıcı modeli (önerilen)
Bu model, çift kodlayıcı mimarisi kullanır ve çeşitli soru-cevap veri kümeleriyle eğitilmiştir.
Aşağıdaki cümle çiftlerini inceleyin:
("büyüleyici ve genellikle etkileyici bir yolculuk", "ne kadar harika ve fantastik bir gezi")
("Telefonumu seviyorum", "Telefonumu sevmiyorum")
("Bu restoranın ilgi çekici bir özelliği var", "Planımızın ayrıntılarını tekrar kontrol etmemiz gerekiyor")
İlk iki cümle çiftinde sırasıyla "seyahat duygusu" ve "telefon görüşü" ortak bir konu olduğu için ilk iki çiftteki metin yerleştirmelerinin kosinüs benzerliği, üçüncü çiftteki yerleştirmelerden daha yüksektir. Üçüncü cümle çiftinde ise ortak bir konu yoktur.
İkinci çiftteki iki cümlenin zıt duygulara sahip olmasına rağmen ortak bir konuyu paylaştıkları için benzerlik puanlarının yüksek olduğunu unutmayın.
Yukarıdaki önceden eğitilmiş modellere dayalı olarak tüm ardışık düzenin görev karşılaştırmalarını aşağıda bulabilirsiniz. Gecikme sonucu, CPU / GPU kullanan Pixel 6'taki ortalama gecikmedir.
[[["Anlaması kolay","easyToUnderstand","thumb-up"],["Sorunumu çözdü","solvedMyProblem","thumb-up"],["Diğer","otherUp","thumb-up"]],[["İhtiyacım olan bilgiler yok","missingTheInformationINeed","thumb-down"],["Çok karmaşık / çok fazla adım var","tooComplicatedTooManySteps","thumb-down"],["Güncel değil","outOfDate","thumb-down"],["Çeviri sorunu","translationIssue","thumb-down"],["Örnek veya kod sorunu","samplesCodeIssue","thumb-down"],["Diğer","otherDown","thumb-down"]],["Son güncelleme tarihi: 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 | - |"]]