การฝัง: แบบฝึกหัดแบบอินเทอร์แอกทีฟ
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
วิดเจ็ตต่อไปนี้ ซึ่งใช้ Embedding Projector ของ TensorFlow ทำให้เวกเตอร์แบบคงที่ของ word2vec
10,000 อันแบนราบลงในพื้นที่ 3 มิติ การยุบมิติแบบนี้อาจทำให้เข้าใจผิดเพราะจุดที่อยู่ใกล้กันที่สุดในพื้นที่มิติสูงเดิมอาจปรากฏเหมือนอยู่ห่างกันในการฉายภาพแบบ 3 มิติ จุดที่อยู่ใกล้กันที่สุดจำนวน n จุดไฮไลต์ด้วยสีม่วง โดยที่ผู้ใช้เลือก n ไว้ใน Isolate __ points แถบด้านขวาจะแสดงจุดข้อมูลข้างเคียงที่อยู่ใกล้กันที่สุดดังกล่าว
ในการทดลองเหล่านี้ คุณจะได้ลองเล่นกับการฝังของ word2vec
ในวิดเจ็ตด้านบน
งาน 1
ลองหาจุดข้อมูลข้างเคียงที่อยู่ใกล้ที่สุด 20 จุดของคำต่อไปนี้ และดูว่ากลุ่มจุดต่างๆ อยู่ตรงไหนในรูปเมฆจุดข้อมูล
iii
, third
และ three
tao
และ way
orange
, yellow
และ juice
คุณสังเกตเห็นอะไรเกี่ยวกับผลลัพธ์เหล่านี้
คลิกที่นี่เพื่อดูคำตอบของเรา
ถึงแม้ว่า iii
, third
และ three
จะมีความคล้ายกันทางความหมาย แต่ก็ปรากฏในบริบทที่แตกต่างกันในข้อความ และดูเหมือนว่าจะไม่ได้อยู่ใกล้กันในพื้นที่การฝังนี้ ใน word2vec
นั้น iii
อยู่ใกล้กับ iv
มากกว่าอยู่ใกล้กับ third
ในทำนองเดียวกัน แม้ว่า way
จะเป็นการแปลตรงตัวของ tao
แต่คำเหล่านี้มักจะปรากฏร่วมกับกลุ่มคำที่แตกต่างกันโดยสิ้นเชิงในชุดข้อมูลที่ใช้ และด้วยเหตุนี้เวกเตอร์ทั้งสองจึงอยู่ห่างกันมาก
จุดข้อมูลข้างเคียงที่อยู่ใกล้ที่สุด 4-5 จุดแรกของ orange
คือสีต่างๆ แต่ juice
และ peel
ซึ่งเกี่ยวข้องกับความหมายของ orange
ในฐานะผลไม้ ปรากฏเป็นจุดข้อมูลข้างเคียงที่ใกล้ที่สุดลำดับที่ 14 และ 18 ในขณะเดียวกัน prince
เช่นในกรณีของ "Prince of Orange" อยู่ในลำดับที่ 17 ในการฉายภาพ คำที่อยู่ใกล้ orange
ที่สุดคือ yellow
และสีอื่นๆ ในขณะที่คำที่อยู่ใกล้ juice
ที่สุดไม่มี orange
งาน 2
ลองพยายามหาลักษณะเฉพาะบางอย่างของข้อมูลฝึกฝน ตัวอย่างเช่น ลองหาจุดข้อมูลข้างเคียงที่อยู่ใกล้ที่สุด 100 จุดของคำต่อไปนี้ และดูว่ากลุ่มจุดต่างๆ อยู่ตรงไหนในรูปเมฆจุดข้อมูล
boston
, paris
, tokyo
, delhi
, moscow
และ seoul
(นี่คือคำถามทดสอบไหวพริบ)
jane
, sarah
, john
, peter
, rosa
และ juan
คลิกที่นี่เพื่อดูคำตอบของเรา
จุดข้อมูลข้างเคียงที่อยู่ใกล้ boston
ที่สุดจำนวนมากเป็นเมืองอื่นๆ ในสหรัฐอเมริกา จุดข้อมูลข้างเคียงที่อยู่ใกล้ paris
ที่สุดจำนวนมากเป็นเมืองอื่นๆ ในยุโรป tokyo
และ delhi
ดูเหมือนจะไม่ได้ให้ผลลัพธ์ที่คล้ายกัน เนื่องจากคำหนึ่งเกี่ยวข้องกับเมืองต่างๆ ทั่วโลกที่เป็นศูนย์กลางการเดินทาง ขณะที่อีกคำเกี่ยวข้องกับ india
และคำอื่นๆ ที่เกี่ยวข้องกัน seoul
ไม่ปรากฏอยู่ในชุดเวกเตอร์คำที่มีการตัดลดนี้เลย
ดูเหมือนว่าชุดข้อมูลนี้จะมีเอกสารจำนวนมากที่เกี่ยวข้องกับภูมิศาสตร์ระดับประเทศของสหรัฐฯ บางเอกสารเกี่ยวข้องกับภูมิศาสตร์ระดับภูมิภาคของยุโรป และไม่มีการครอบคลุมรายละเอียดของประเทศหรือภูมิภาคอื่นมากนัก
ในทำนองเดียวกัน ชุดข้อมูลนี้ดูเหมือนจะมีชื่อภาษาอังกฤษของผู้ชายจำนวนมาก ชื่อภาษาอังกฤษของผู้หญิงบางส่วน และมีชื่อจากภาษาอื่นๆ น้อยมาก โปรดทราบว่า Don Rosa เป็นผู้เขียนและวาดภาพการ์ตูน Scrooge McDuck ให้กับ Disney ซึ่งน่าจะเป็นเหตุผลของการที่คำว่า scrooge และ mcduck อยู่ในกลุ่มจุดข้อมูลข้างเคียงที่ใกล้คำว่า "rosa" ที่สุด
เวกเตอร์คำที่ได้รับการฝึกล่วงหน้าซึ่ง word2vec
นำเสนอนั้น แท้ที่จริงได้รับการฝึกจากบทความข่าวของ Google News จนถึงปี 2013
งาน 3
การฝังไม่ได้จำกัดอยู่แค่คำเท่านั้น แต่รูปภาพ เสียง และข้อมูลอื่นๆ ก็ฝังได้เช่นกัน สำหรับงานนี้ให้ทำดังนี้
- เปิด Embedding Projector ของ TensorFlow
- ในแถบด้านซ้ายที่มีชื่อว่าข้อมูล ให้เลือก Mnist พร้อมรูปภาพ การดำเนินการนี้จะแสดงการฉายภาพการฝังของฐานข้อมูล MNIST ซึ่งประกอบด้วยภาพตัวเลขที่เขียนด้วยลายมือ
- คลิกเพื่อหยุดการหมุนและเลือกรูปภาพเดียว ซูมเข้าและซูมออกตามต้องการ
- มองหาจุดข้อมูลที่อยู่ใกล้ที่สุดในแถบด้านขวา มีสิ่งที่ทำให้คุณประหลาดใจไหม
- ทำไมเลข
7
บางตัวมีเลข 1
เป็นจุดข้อมูลที่อยู่ใกล้ที่สุด ทำไมเลข 8
บางตัวมีเลข 9
เป็นจุดข้อมูลที่อยู่ใกล้ที่สุด
- มีอะไรในรูปภาพที่อยู่บริเวณขอบของพื้นที่ฉายภาพที่ดูแตกต่างจากรูปภาพที่อยู่กึ่งกลางของพื้นที่ฉายภาพไหม
โปรดทราบว่าโมเดลที่สร้างการฝังเหล่านี้จะรับข้อมูลรูปรูปภาพ ซึ่งก็คือพิกเซล และเลือกการแทนรูปภาพแต่ละภาพด้วยเวกเตอร์เชิงตัวเลข โมเดลดังกล่าวไม่ได้สร้างความเชื่อมโยงทางความคิดโดยอัตโนมัติระหว่างรูปภาพตัวเลขที่เขียนด้วยลายมือกับตัวเลขนั้นเอง
คลิกที่นี่เพื่อดูคำตอบของเรา
เนื่องจากรูปร่างมีความคล้ายคลึงกัน เวกเตอร์ที่แทนเลข 7
ที่บางและแคบบางตัวจึงวางอยู่ใกล้กับเวกเตอร์ของเลข 1
ที่เขียนด้วยลายมือ ซึ่งกรณีนี้เกิดขึ้นกับเลข 8
และเลข 9
บางตัว และแม้กระทั่งเลข 5
กับเลข 3
บางตัวด้วย
ตัวเลขที่เขียนด้วยลายมือซึ่งอยู่ด้านนอกของพื้นที่ฉายภาพดูเหมือนจะระบุได้ชัดเจนว่าเป็นตัวเลขหนึ่งใน 9 ตัวเลข และแตกต่างอย่างชัดเจนกับตัวเลขอื่นที่อาจมีลักษณะใกล้เคียง
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-05-22 UTC
[null,null,["อัปเดตล่าสุด 2025-05-22 UTC"],[],[],null,["# Embeddings: Interactive exercises\n\nThe following widget, based on TensorFlow's\n[Embedding Projector](https://projector.tensorflow.org/), flattens 10,000\n`word2vec` static vectors into a 3D space. This collapse of dimensions can be\nmisleading, because the points closest to each other in the original\nhigh-dimensional space may appear farther apart in the 3D projection. The\nclosest *n* points are highlighted in purple, with *n* chosen by the user in\n**Isolate __ points**. The sidebar on the right identifies those nearest\nneighbors. \n\nIn these experiments, you'll play with the `word2vec` embeddings in the widget\nabove.\n\nTask 1\n------\n\nTry to find the 20 nearest neighbors for the following, and see where the\ngroups fall in the cloud.\n\n- `iii`, `third`, and `three`\n- `tao` and `way`\n- `orange`, `yellow`, and `juice`\n\nWhat do you notice about these results? \n**Click here for our answer**\n\nEven though `iii`, `third`, and `three`\nare semantically similar, they appear in different contexts in text and\ndon't appear to be close together in this embedding space. In\n`word2vec`, `iii` is closer to `iv` than to\n`third`.\n\nSimilarly, while `way` is a direct translation of `tao`,\nthese words most frequently occur with completely different groups of words\nin the dataset used, and so the two vectors are very far apart.\n\nThe first several nearest neighbors of `orange` are colors, but\n`juice` and `peel`, related to the meaning of\n`orange` as fruit, show up as the 14th\nand 18th nearest neighbors. `prince`, meanwhile, as in the\nPrince of Orange, is 17th. In the projection, the words closest to\n`orange` are `yellow` and other\ncolors, while the closest words to `juice` don't include\n`orange`.\n\nTask 2\n------\n\nTry to figure out some characteristics of the training data. For example, try\nto find the 100 nearest neighbors for the following, and see where the groups\nare in the cloud:\n\n- `boston`, `paris`, `tokyo`, `delhi`, `moscow`, and `seoul` (this is a trick question)\n- `jane`, `sarah`, `john`, `peter`, `rosa`, and `juan`\n\n**Click here for our answer**\n\nMany of the nearest neighbors to `boston` are other cities in\nthe US. Many of the nearest neighbors to `paris` are other cities\nin Europe. `tokyo` and `delhi` don't seem to have\nsimilar results: one is associated with cities around the world that are\ntravel hubs, while the other is associated with `india` and related\nwords. `seoul` doesn't appear in this trimmed-down set of\nword vectors at all.\n\nIt seems that this dataset contains many documents related to US national\ngeography, some documents relate to European regional geography, and not\nmuch fine-grained coverage of other countries or regions.\n\nSimilarly, this dataset seems to contain many male English names, some female\nEnglish names, and far fewer names from other languages. Note that Don Rosa\nwrote and illustrated Scrooge McDuck comics for Disney, which is the likely\nreason that \\`scrooge\\` and \\`mcduck\\` are among the nearest neighbors for \\`rosa\\`.\n\nThe pre-trained word vectors offered by `word2vec` were in fact\ntrained on\n[Google News articles up to 2013](https://code.google.com/archive/p/word2vec/).\n\nTask 3\n------\n\nEmbeddings aren't limited to words. Images, audio, and other data can also be\nembedded. For this task:\n\n1. Open TensorFlow's [Embedding Projector](https://projector.tensorflow.org/).\n2. In the left sidebar titled **Data** , choose **Mnist with images** . This brings up a projection of the embeddings of the [MNIST](https://developers.google.com/machine-learning/glossary#mnist) database of handwritten digits.\n3. Click to stop the rotation and choose a single image. Zoom in and out as needed.\n4. Look in the right sidebar for nearest neighbors. Are there any surprises?\n\n- Why do some `7`s have `1`s as their nearest neighbor? Why do some `8`s have `9` as their nearest neighbor?\n- Is there anything about the images on the edges of the projection space that seem different from the images in the center of the projection space?\n\nKeep in mind that the model that created these embeddings is receiving image\ndata, which is to say, pixels, and choosing a numerical vector representation\nfor each image. The model doesn't make an automatic mental association\nbetween the image of the handwritten digit and the numerical digit itself. \n**Click here for our answer**\n\nDue to similarities in shape, the vector representations of some of the\nskinnier, narrower `7`s are placed closer to the vectors for\nhandwritten `1`s. The same thing happens for some `8`s\nand `9`s, and even some of the `5`s and `3`s.\n\nThe handwritten digits on the outside of the projection space appear\nmore strongly definable as one of the nine digits and strongly differentiated\nfrom other possible digits.\n| **Key terms:**\n|\n| - [Embedding vector](/machine-learning/glossary#embedding-vector)\n- [Embedding space](/machine-learning/glossary#embedding-space) \n[Help Center](https://support.google.com/machinelearningeducation)"]]