جاسازیها: تمرینهای تعاملی
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
ابزاره زیر، براساس فراتاب جاسازی TensorFlow، ۱۰٬۰۰۰ بردار ایستا word2vec
را در فضایی سهبعدی مسطح میکند. این پایین رفتن ابعاد میتواند گمراهکننده باشد زیرا نقاطی که در فضای بُعدبالای اصلی به یکدیگر نزدیکتر هستند، ممکن است در تصویر سهبعدی دورتر از هم بهنظر برسند. نزدیکترین نقطههای n با رنگ بنفش برجسته شدهاند و n توسط کاربر در Isolate __ points انتخاب شده است. نوار کناری سمت چپ نزدیکترین موارد همجوار را مشخص میکند.
در این آزمایشها، جاسازیهای word2vec
را در ابزاره بالا امتحان میکنید.
تکلیف ۱
سعی کنید ۲۰ نمونه از نزدیکترین موارد همجوار را برای موارد زیر پیدا کنید و ببینید این گروهها در فضای ابری کجا قرار میگیرند.
-
iii
، third
، و three
-
tao
و way
-
orange
، yellow
، و juice
درباره این نتایج متوجه چه چیزی شدید؟
برای دیدن پاسخ ما، اینجا کلیک کنید
اگرچه iii
، third
، و three
از نظر معنایی مشابه هستند، در متن در بافتهای متفاوتی ظاهر میشوند و بهنظر نمیرسد در این فضای جاسازی به هم نزدیک باشند. در word2vec
، iii
به iv
نزدیکتر است تا به third
.
بههمینترتیب، اگرچه way
ترجمه مستقیمی از tao
است، در مجموعه داده مورداستفاده این کلمات اغلب با گروههای کاملاً متفاوتی از کلمات ظاهر میشوند و بنابراین دو بردار بسیار از هم فاصله دارند.
نزدیکترین موارد همجوار ابتدایی orange
رنگها هستند، بهجز juice
و peel
که به معنی orange
بهعنوان میوه مربوط میشوند و بهعنوان چهاردهمین و هجدهمین مورد همجوار نزدیک ظاهر میشوند. درعینحال، prince
در Prince of Orange هفدهمین مورد است. در طرح سهبعدی کلماتی که به orange
نزدیکترند yellow
و رنگهای دیگر هستند، درحالیکه orange
جزو نزدیکترین کلمات به juice
نیست.
تکلیف ۲
سعی کنید برخیاز ویژگیهای دادههای آموزشی را پیدا کنید. مثلاً سعی کنید نزدیکترین ۱۰۰ مورد همجوار را برای موارد زیر پیدا کنید و ببینید این گروهها در کجای فضای ابری قرار دارند:
-
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 تا سال ۲۰۱۳ آموزش دیده بودند.
تکلیف ۳
جاسازیها محدود به کلمات نیستند. تصاویر، صداها، و دادههای دیگر هم میتوانند جاسازی شوند. برای این تکلیف:
- فراتاب جاسازی TensorFlow را باز کنید.
- در نوار کناری سمت راست با عنوان دادهها، Mnist با تصاویر را انتخاب کنید. با این کار طرح سهبعدی جاسازیهای پایگاه داده MNIST از اعداد دستنویس نمایش داده میشود.
- کلیک کنید تا چرخش متوقف شود و یک تصویر را انتخاب کنید. درصورت نیاز زومپیش و زومپس کنید.
- در نوار کناری سمت چپ بهدنبال نزدیکترین موارد همجوار بگردید. مورد غیرمنتظرهای میبینید؟
- چرا برخیاز
7
ها 1
ها را بهعنوان نزدیکترین مورد همجوار دارند؟ چرا برخیاز 8
ها 9
ها را بهعنوان نزدیکترین مورد همجوار دارند؟
- آیا تصاویری که در لبههای فضای طرح سهبعدی قرار دارند از هیچ لحاظی با تصاویری که در مرکز فضای طرح سهبعدی قرار دارند تفاوت دارند؟
بهخاطر داشته باشید مُدلی که این جاسازیها را ایجاد کرده است دادههای تصویر، یعنی پیکسلها، را دریافت میکند و برداری عددی را برای نمایش دادن هر تصویر انتخاب میکند. این مدل بهطور خودکار بین تصویر عدد دستنویس و خود عدد ارتباط ذهنی برقرار نمیکند.
برای دیدن پاسخ ما، اینجا کلیک کنید
بهدلیل شباهتهای شکلی، نمایشهای برداری برخیاز 7
های باریکتر و نازکتر به بردارهای دستنویس 1
ها نزدیکتر قرار داده شدهاند. همین اتفاق برای بعضیاز 8
ها و 9
ها و حتی بعضیاز 5
ها و 3
ها میافتد.
اعداد دستنویس در بیرون فضای طرح سهبعدی بهطرز قابل تعریفتری بهعنوان یکی از نُه رقم و کاملاً متمایز از سایر ارقامِ احتمالی نشان داده میشوند.
جز در مواردی که غیر از این ذکر شده باشد،محتوای این صفحه تحت مجوز Creative Commons Attribution 4.0 License است. نمونه کدها نیز دارای مجوز Apache 2.0 License است. برای اطلاع از جزئیات، به خطمشیهای سایت Google Developers مراجعه کنید. جاوا علامت تجاری ثبتشده Oracle و/یا شرکتهای وابسته به آن است.
تاریخ آخرین بهروزرسانی 2025-05-16 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2025-05-16 بهوقت ساعت هماهنگ جهانی."],[],[],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)"]]