การวัดความคล้ายคลึงจากการฝัง
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
ตอนนี้คุณมีข้อมูลเชิงลึกสําหรับคู่ตัวอย่างแล้ว มาตรการความคล้ายคลึงแบบควบคุมจะนําข้อมูลเชิงลึกเหล่านี้ไปแสดงผลเป็นตัวเลขที่วัดความคล้ายคลึง
โปรดทราบว่าการฝังเป็นเวกเตอร์ของตัวเลข หากต้องการหาความคล้ายคลึงระหว่างเวกเตอร์ 2 รายการ \(A = [a_1,a_2,...,a_n]\) และ \(B = [b_1,b_2,...,b_n]\)ให้เลือกการวัดความคล้ายคลึง 1 ใน 3 รายการต่อไปนี้
วัดผล | ความหมาย | สูตร |
เมื่อความคล้ายคลึงเพิ่มขึ้น การวัดนี้... |
ระยะทางแบบยุคลิด | ระยะห่างระหว่างปลายเวกเตอร์ |
\(\sqrt{(a_1-b_1)^2+(a_2-b_2)^2+...+(a_N-b_N)^2}\) |
ลดลง |
โคไซน์ | โคไซน์ของมุม \(\theta\) ระหว่างเวกเตอร์ |
\(\frac{a^T b}{|a| \cdot |b|}\) |
เพิ่มขึ้น |
ผลคูณจุด | โคไซน์คูณด้วยความยาวของทั้ง 2 เวกเตอร์ |
\(a_1b_1+a_2b_2+...+a_nb_n\) \(=|a||b|cos(\theta)\) |
เพิ่มขึ้น และเพิ่มขึ้นตามความยาวของเวกเตอร์ |
การเลือกการวัดความคล้ายคลึง
ซึ่งแตกต่างจากโคไซน์ตรงที่ผลคูณจุดจะแปรผันตามความยาวเวกเตอร์
ขั้นตอนนี้สำคัญเนื่องจากตัวอย่างที่ปรากฏบ่อยมากในชุดการฝึก (เช่น วิดีโอ YouTube ที่ได้รับความนิยม) มีแนวโน้มที่จะเวกเตอร์การฝังที่มีความยาวมาก
หากต้องการจับความนิยม ให้เลือกผลิตภัณฑ์จุด อย่างไรก็ตาม ความเสี่ยงคือตัวอย่างยอดนิยมอาจทำให้เมตริกความคล้ายคลึงบิดเบือน หากต้องการปรับสมดุลความเอียงนี้ คุณสามารถยกกำลังความยาวเป็นเลขยกกำลัง \(\alpha\ < 1\) เพื่อคำนวณผลคูณแบบดอท \(|a|^{\alpha}|b|^{\alpha}\cos(\theta)\)
หากต้องการทําความเข้าใจได้ดียิ่งขึ้นว่าความยาวเวกเตอร์ทําให้การวัดความคล้ายคลึงเปลี่ยนแปลงไปอย่างไร ให้นอร์มาไลซ์ความยาวเวกเตอร์เป็น 1 และสังเกตว่าค่าทั้ง 3 รายการจะสัดส่วนกัน
หลังจากทำให้ a และ b เป็นมาตรฐานโดยที่ \(||a||=1\) และ \(||b||=1\)แล้ว
การวัดค่าทั้ง 3 รายการนี้มีความเกี่ยวข้องกันดังนี้
- ระยะทางแบบยุคลิด = \(||a-b|| = \sqrt{||a||^2 + ||b||^2 - 2a^{T}b}
= \sqrt{2-2\cos(\theta_{ab})}\)
- ผลคูณจุด = \( |a||b| \cos(\theta_{ab})
= 1\cdot1\cdot \cos(\theta_{ab}) = cos(\theta_{ab})\)
- โคไซน์ = \(\cos(\theta_{ab})\)
ดังนั้น ดัชนีความคล้ายคลึงทั้ง 3 รายการจึงเทียบเท่ากันเนื่องจากมีสัดส่วนกับ \(cos(\theta_{ab})\)
การตรวจสอบการวัดความคล้ายคลึง
การวัดความคล้ายคลึงจะวัดความคล้ายคลึงระหว่างคู่ตัวอย่างหนึ่งๆ เทียบกับคู่ตัวอย่างอื่นๆ ด้านล่างนี้คือข้อมูลเปรียบเทียบระหว่างการตรวจสอบด้วยตนเองและการตรวจสอบที่มีการควบคุม
ประเภท | วิธีสร้าง | เหมาะสำหรับ | ผลกระทบ |
กำหนดเอง | รวมข้อมูลฟีเจอร์ด้วยตนเอง |
ชุดข้อมูลขนาดเล็กที่มีฟีเจอร์ที่รวมเข้าด้วยกันได้ง่าย |
ให้ข้อมูลเชิงลึกเกี่ยวกับผลลัพธ์ของการคำนวณความคล้ายคลึง หากข้อมูลฟีเจอร์มีการเปลี่ยนแปลง คุณต้องอัปเดตการวัดความคล้ายคลึงด้วยตนเอง |
มีการควบคุมดูแล | วัดระยะห่างระหว่างการฝังที่สร้างขึ้นโดย DNN ที่มีการควบคุม |
ชุดข้อมูลขนาดใหญ่ที่มีฟีเจอร์ที่รวมเข้าด้วยกันได้ยาก |
ไม่ได้ให้ข้อมูลเชิงลึกเกี่ยวกับผลลัพธ์ อย่างไรก็ตาม DNN สามารถปรับตัวให้เข้ากับข้อมูลฟีเจอร์ที่เปลี่ยนแปลงไปได้โดยอัตโนมัติ |
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-02-25 UTC
[null,null,["อัปเดตล่าสุด 2025-02-25 UTC"],[[["\u003cp\u003eSupervised similarity measures leverage embeddings to quantify the similarity between data examples using Euclidean distance, cosine, or dot product.\u003c/p\u003e\n"],["\u003cp\u003eDot product incorporates vector length, reflecting popularity, while cosine similarity focuses solely on the angle between vectors, ignoring popularity.\u003c/p\u003e\n"],["\u003cp\u003eNormalizing vector lengths makes Euclidean distance, cosine, and dot product proportional, essentially measuring the same thing.\u003c/p\u003e\n"],["\u003cp\u003eSupervised similarity, using embeddings and a distance metric, is suitable for large, complex datasets, while manual similarity, relying on feature combinations, is better for small, straightforward datasets.\u003c/p\u003e\n"]]],[],null,["# Measuring similarity from embeddings\n\nYou now have embeddings for any pair of examples. A supervised similarity\nmeasure takes these embeddings and returns a number measuring their similarity.\nRemember that embeddings are vectors of numbers. To find the similarity between\ntwo vectors \\\\(A = \\[a_1,a_2,...,a_n\\]\\\\) and \\\\(B = \\[b_1,b_2,...,b_n\\]\\\\),\nchoose one of these three similarity measures:\n\n| Measure | Meaning | Formula | As similarity increases, this measure... |\n|--------------------|-----------------------------------------------|--------------------------------------------------------------|---------------------------------------------------|\n| Euclidean distance | Distance between ends of vectors | \\\\(\\\\sqrt{(a_1-b_1)\\^2+(a_2-b_2)\\^2+...+(a_N-b_N)\\^2}\\\\) | Decreases |\n| Cosine | Cosine of angle \\\\(\\\\theta\\\\) between vectors | \\\\(\\\\frac{a\\^T b}{\\|a\\| \\\\cdot \\|b\\|}\\\\) | Increases |\n| Dot product | Cosine multiplied by lengths of both vectors | \\\\(a_1b_1+a_2b_2+...+a_nb_n\\\\) \\\\(=\\|a\\|\\|b\\|cos(\\\\theta)\\\\) | Increases. Also increases with length of vectors. |\n\nChoosing a similarity measure\n-----------------------------\n\nIn contrast to the cosine, the dot product is proportional to the vector length.\nThis is important because examples that appear very frequently in the training\nset (for example, popular YouTube videos) tend to have embedding vectors with\nlarge lengths.\n\nIf you\nwant to capture popularity, then choose dot product. However, the risk is that\npopular examples may skew the similarity metric. To balance this skew, you can\nraise the length to an exponent \\\\(\\\\alpha\\\\ \\\u003c 1\\\\) to calculate the dot product\nas \\\\(\\|a\\|\\^{\\\\alpha}\\|b\\|\\^{\\\\alpha}\\\\cos(\\\\theta)\\\\).\n\nTo better understand how vector length changes the similarity measure, normalize\nthe vector lengths to 1 and notice that the three measures become proportional\nto each other. \nProof: Proportionality of Similarity Measures \nAfter normalizing a and b such that \\\\(\\|\\|a\\|\\|=1\\\\) and \\\\(\\|\\|b\\|\\|=1\\\\), these three measures are related as:\n\n- Euclidean distance = \\\\(\\|\\|a-b\\|\\| = \\\\sqrt{\\|\\|a\\|\\|\\^2 + \\|\\|b\\|\\|\\^2 - 2a\\^{T}b} = \\\\sqrt{2-2\\\\cos(\\\\theta_{ab})}\\\\).\n- Dot product = \\\\( \\|a\\|\\|b\\| \\\\cos(\\\\theta_{ab}) = 1\\\\cdot1\\\\cdot \\\\cos(\\\\theta_{ab}) = cos(\\\\theta_{ab})\\\\).\n- Cosine = \\\\(\\\\cos(\\\\theta_{ab})\\\\).\nThus, all three similarity measures are equivalent because they are proportional to \\\\(cos(\\\\theta_{ab})\\\\).\n\nReview of similarity measures\n-----------------------------\n\nA similarity measure quantifies the similarity between a pair of\nexamples, relative to other pairs of examples. The two types, manual and\nsupervised, are compared below:\n\n| Type | How to create | Best for | Implications |\n|------------|--------------------------------------------------------------------|-------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------|\n| Manual | Manually combine feature data. | Small datasets with features that are straightforward to combine. | Gives insight into results of similarity calculations. If feature data changes, you must manually update the similarity measure. |\n| Supervised | Measure distance between embeddings generated by a supervised DNN. | Large datasets with hard-to-combine features. | Gives no insight into results. However, a DNN can automatically adapt to changing feature data. |"]]