{"id":1993,"date":"2020-08-12T19:54:18","date_gmt":"2020-08-12T10:54:18","guid":{"rendered":"https:\/\/developers.agirobots.com\/jp\/?p=1993"},"modified":"2021-09-11T00:06:14","modified_gmt":"2021-09-10T15:06:14","slug":"word2vec-and-embeddinglayer","status":"publish","type":"post","link":"https:\/\/developers.agirobots.com\/jp\/word2vec-and-embeddinglayer\/","title":{"rendered":"Word2Vec\u3068Embedding\u5c64\u306b\u3064\u3044\u3066\u8003\u5bdf\u3057\u3066\u307f\u305f"},"content":{"rendered":"\n<p>Word2Vec\u3084Embedding\u5c64\u306b\u3064\u3044\u3066\u81ea\u8eab\u306e\u7406\u89e3\u304c\u66d6\u6627\u3060\u3063\u305f\u306e\u3067\u3001\u5b66\u7fd2\u304c\u3066\u3089\u81ea\u8eab\u306e\u8003\u5bdf\u3092\u793a\u3057\u306a\u304c\u3089\u307e\u3068\u3081\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u5206\u6563\u8868\u73fe<\/h2>\n\n\n\n<p>\u540d\u524d\u306a\u3069\u7269\u7406\u7684\u306a\u8a08\u6e2c\u304c\u4e0d\u53ef\u80fd\u306a\u8a18\u53f7\u96c6\u5408\u3092\u30d9\u30af\u30c8\u30eb\u306b\u5bfe\u5fdc\u4ed8\u3051\u305f\u3082\u306e\u3092\u5206\u6563\u8868\u73fe\uff08distributed representation\uff09\u3068\u3044\u3044\u307e\u3059\u3002\u3053\u306e\u5909\u63db\u64cd\u4f5c\u306f\u3001\u30c8\u30fc\u30af\u30f3\u3092\u30d9\u30af\u30c8\u30eb\u7a7a\u9593\u306b\u57cb\u3081\u8fbc\u3080\u64cd\u4f5c\u3067\u3042\u308b\u3053\u3068\u304b\u3089\u57cb\u3081\u8fbc\u307f\uff08embedding\uff09\u3068\u3082\u3044\u308f\u308c\u307e\u3059\uff08\u4e00\u822c\u7684\u306b\u81ea\u7136\u8a00\u8a9e\u51e6\u7406\u306e\u5206\u91ce\u3067\u30c8\u30fc\u30af\u30f3\u306f\u5358\u8a9e\u3067\u3042\u308b\u305f\u3081\u3001\u5358\u8a9e\u57cb\u3081\u8fbc\u307f\uff08word embedding\uff09\u3068\u547c\u3076\u3053\u3068\u304c\u591a\u3044\uff09\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Word2Vec<\/h2>\n\n\n\n<p>Word2Vec\u3068\u306f\u3001Word\u3092Vector\u306b\u5909\u63db\u3059\u308b\u3068\u3044\u3046\u610f\u5473\u3067\u5206\u6563\u8868\u73fe\u305d\u306e\u3082\u306e\u3092\u6307\u3059\u3068\u89e3\u91c8\u3067\u304d\u307e\u3059\u304c\u3001\u3088\u308a\u72ed\u7fa9\u3067CBOW\u3084Skip-gram\u306e2\u3064\u306e\u30e2\u30c7\u30eb\u3092\u6307\u3059\u306e\u304c\u4e00\u822c\u7684\u3067\u3059\u3002\u52c9\u5f37\u4f1a\u7b49\u3067\u767b\u58c7\u8005\u306e\u8aac\u660e\u3092\u805e\u3044\u305f\u308a\u81ea\u8eab\u304c\u8aac\u660e\u3057\u305f\u308a\u3059\u308b\u3068\u304d\u306fWord2Vec\u304c\u5206\u6563\u8868\u73fe\u305d\u306e\u3082\u306e\u3092\u6307\u3057\u3066\u3044\u308b\u306e\u304b\u3001CBOW\u3068Skip-gram\u306e\u307f\u3092\u6307\u3057\u3066\u3044\u308b\u306e\u304b\u6ce8\u610f\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<p>CBOW\u3084Skip-gram\u3068\u3044\u3046\u30e2\u30c7\u30eb\u306f\u5b66\u7fd2\u3092\u901a\u3058\u3066\u4ee5\u4e0b\u3067\u8aac\u660e\u3059\u308b\u5206\u6563\u8868\u73fe\u3092\u7fd2\u5f97\u3057\u307e\u3059\u3002\u5177\u4f53\u7684\u306b<\/p>\n\n\n\n<p>\"King\"-\"Man\"=\"Queen\"-\"Woman\"<\/p>\n\n\n\n<p>\u3068\u3044\u3046\u30d9\u30af\u30c8\u30eb\u8a08\u7b97\u304c\u53ef\u80fd\u306a\u5206\u6563\u8868\u73fe\u3067\u3059\u3002\u3053\u308c\u306f\u6570\u767e\u6b21\u5143\u3068\u9ad8\u6b21\u5143\u30d9\u30af\u30c8\u30eb\u306e\u6f14\u7b97\u3067\u3042\u308b\u305f\u3081\u3001King\u3001Man\u3001Queen\u3001Woman\u306e\u95a2\u4fc2\u306b\u6ce8\u76ee\u3057\u3066\u4e3b\u6210\u5206\u5206\u6790\u7b49\u306b\u3088\u308a2\u6b21\u5143\u306b\u6b21\u5143\u524a\u6e1b\u3059\u308b\u3068\u3001\u4ee5\u4e0b\u3088\u3046\u306a\u69cb\u9020\u304c\u5f97\u3089\u308c\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img decoding=\"async\" width=\"559\" height=\"332\" src=\"https:\/\/developers.agirobots.com\/jp\/wp-content\/uploads\/2020\/08\/image-9.png\" alt=\"\" class=\"wp-image-2107\" srcset=\"https:\/\/developers.agirobots.com\/jp\/wp-content\/uploads\/2020\/08\/image-9.png 559w, https:\/\/developers.agirobots.com\/jp\/wp-content\/uploads\/2020\/08\/image-9-300x178.png 300w\" sizes=\"(max-width: 559px) 100vw, 559px\" \/><\/figure><\/div>\n\n\n\n<p>\u3053\u3053\u304b\u3089\u3001\"Woman\"\u304b\u3089\"Queen\"\u3068\u3044\u3046\u5358\u8a9e\u3092\u5f97\u305f\u3051\u308c\u3070\u3001\"Woman\"\u306b\"King\"-\"Man\"\u3067\u8868\u3055\u308c\u308b\u30d9\u30af\u30c8\u30eb\u3092\u8db3\u305b\u3070\u3044\u3044\u3068\u3044\u3046\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Embedding\u5c64<\/h2>\n\n\n\n<p>\u4efb\u610f\u306e\u30c8\u30fc\u30af\u30f3\u306b\u5bfe\u5fdc\u3059\u308b\u6570\u5024\u756a\u53f7\uff08\u3064\u307e\u308a\u3001\u30b9\u30ab\u30e9\u30fc\u91cf\uff09\u3092\u5165\u529b\u3068\u3057\u3066\u53d7\u3051\u3001\u5bc6\u306a\u30d9\u30af\u30c8\u30eb\u7a7a\u9593\u306b\u57cb\u3081\u8fbc\u3080\u64cd\u4f5c\u3092\u5b9f\u73fe\u3059\u308b\u5c64\u3067\u3059\u3002\u5185\u90e8\u306e\u30a2\u30fc\u30ad\u30c6\u30af\u30c1\u30e3\u3068\u3057\u3066\u306f\u5165\u529b\u3055\u308c\u305f\u756a\u53f7\u306e\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u90e8\u5206\u306e\u307f\u304c1\u3067\u3042\u308b\u758e\u306aOneHot\u30d9\u30af\u30c8\u30eb\u3092\u305d\u308c\u3088\u308a\u4f4e\u6b21\u306a\u5bc6\u30d9\u30af\u30c8\u30eb\u306b\u7dda\u5f62\u5199\u50cf\u3057\u3066\u304a\u308a\u3001\u8a08\u7b97\u904e\u7a0b\u3067OneHot\u306a\u30d9\u30af\u30c8\u30eb\u8868\u73fe\u306b\u3059\u308b\u64cd\u4f5c\u3092\u30ef\u30f3\u30af\u30c3\u30b7\u30e7\u30f3\u7f6e\u3044\u3066\u3044\u307e\u3059\u304c\u3001\u5c64\u3092\u30d6\u30e9\u30c3\u30af\u30dc\u30c3\u30af\u30b9\u3068\u3057\u3066\u3001\u5165\u529b\u3068\u51fa\u529b\u306e\u307f\u306b\u6ce8\u76ee\u3059\u308c\u3070\u3001\u5358\u8a9e\u540c\u58eb\u306e\u610f\u5473\u95a2\u4fc2\u3092\u8868\u3055\u306a\u3044\u8a18\u53f7\u7a7a\u9593\uff08\u5165\u529b\uff09\u3092\u30d9\u30af\u30c8\u30eb\u7a7a\u9593\uff08\u51fa\u529b\uff09\u306b\u57cb\u3081\u8fbc\u3093\u3067\u304a\u308a\u3001\u307e\u3055\u306b\u5206\u6563\u8868\u73fe\u306e\u5b9a\u7fa9\u305d\u306e\u3082\u306e\u3092\u8868\u3059\u5c64\u3067\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u305d\u3082\u305d\u3082Embedding\u3068\u306f\u4f55\u304b<\/h3>\n\n\n\n<p>\u5148\u307b\u3069\u5206\u6563\u8868\u73fe\u3068Word2Vec\u306b\u3064\u3044\u3066\u8aac\u660e\u3057\u305f\u8981\u9818\u3067\u5341\u5206\u306a\u90e8\u5206\u3082\u3042\u308a\u307e\u3059\u304c\u3001\u3053\u306e\u624b\u306e\u8aac\u660e\u3067\u306fWord2Vec\u3068\u3057\u3066CBOW\u3084Skip-gram\u308c\u89e6\u308c\u3064\u3064\u3082\u3001\u3044\u304d\u306a\u308aEmbedding\u5c64\u304c\u767b\u5834\u3057\u3066\u304f\u308b\u66f8\u7c4d\u304c\u591a\u3044\u5370\u8c61\u3067\u3001Embedding\u5c64\u306b\u3088\u308b\u5206\u6563\u8868\u73fe\uff1dWord2Vec\u306a\u308b\u5206\u6563\u8868\u73fe\u3068\u81ea\u8eab\u304c\u52d8\u9055\u3044\u3057\u3066\u3044\u305f\u305f\u3081\u3001\u5fc5\u305a\u3057\u3082Embedding\u5c64\u306b\u3088\u308b\u5206\u6563\u8868\u73fe\uff1dWord2Vec\u306a\u308b\u5206\u6563\u8868\u73fe\u3067\u306f\u306a\u3044\u3053\u3068\u3092\u6562\u3048\u3066\u8aac\u660e\u3057\u305f\u304f\u3066\u3053\u306e\u30bb\u30af\u30b7\u30e7\u30f3\u3092\u7528\u610f\u3057\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<p>\u6b21\u306e\u30bb\u30af\u30b7\u30e7\u30f3\u3067\u8aac\u660e\u3059\u308b\u30cb\u30e5\u30fc\u30e9\u30eb\u30cd\u30c3\u30c8\u306b\u7e4b\u3052\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u7aef\u7684\u306a\u8aac\u660e\u3092\u306a\u304b\u306a\u304b\u898b\u3064\u3051\u3089\u308c\u306a\u304b\u3063\u305f\u306e\u3067\u3059\u304c\u3001\u3044\u3044\u611f\u3058\u306a\u89e3\u8aac\u3092\u898b\u3064\u3051\u305f\u306e\u3067\u4e00\u90e8\u3092\u4ee5\u4e0b\u306b\u5f15\u7528\u3057\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>Naturally, every feed-forward neural network that takes words from a vocabulary as input and embeds them as vectors into a lower dimensional space, which it then fine-tunes through back-propagation, necessarily yields word embeddings as the weights of the first layer, which is usually referred to as&nbsp;<em>Embedding Layer<\/em>.<\/p><cite><a href=\"https:\/\/goo.gl\/ojJjiE\">https:\/\/goo.gl\/ojJjiE<\/a><\/cite><\/blockquote>\n\n\n\n<p>\u3053\u308c\u306b\u3088\u308c\u3070\u3001\u5358\u8a9e\u3092\u8868\u3059\u30d9\u30af\u30c8\u30eb\u3092\u305d\u308c\u3088\u308a\u3082\u4f4e\u6b21\u5143\u7a7a\u9593\u306b\u5199\u50cf\u3059\u308b\u9806\u4f1d\u64ad\u578b\u30cb\u30e5\u30fc\u30e9\u30eb\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u306fEmbedding\u5c64\u3060\u3068\u3044\u3046\u306e\u3067\u3059\u3002\u3059\u306a\u308f\u3061\u3001\u3084\u3063\u3066\u308b\u3053\u3068\u306fDense\u5c64\u3068\u5909\u308f\u3089\u306a\u3044\uff08\u3082\u3061\u308d\u3093Embedding\u5c64\u306e\u5165\u529b\u5f62\u5f0f\u306f\u30b9\u30ab\u30e9\u30fc\u3067Dense\u5c64\u306e\u5165\u529b\u5f62\u5f0f\u306f\u30d9\u30af\u30c8\u30eb\u3068\u3044\u3046\u70b9\u306f\u7570\u306a\u308b\uff09\u3068\u8a00\u3063\u3066\u3044\u308b\u308f\u3051\u3067\u3059\u3002\u3088\u308a\u53b3\u5bc6\u306b\u3044\u3046\u3068\u3001Dense\u5c64\u306f\u30d0\u30a4\u30a2\u30b9\u3092\u542b\u3093\u3067\u3044\u308b\u305f\u3081\u3001\u7dda\u5f62\u5199\u50cf\u3068\u3044\u3046\u3088\u308a\u306f\u30a2\u30d5\u30a3\u30f3\u5199\u50cf\u3092\u3057\u3066\u3044\u308b\u3053\u3068\u3082\u7570\u306a\u308a\u307e\u3059\u3002\u3059\u306a\u308f\u3061\u3001Dense\u5c64\u306b\u304a\u3044\u3066\u5168\u3066\u306e\u30d0\u30a4\u30a2\u30b9\u30920\u306b\u3057\u3066\u3001\u304b\u3064\u6d3b\u6027\u5316\u95a2\u6570\u3092\u6052\u7b49\u95a2\u6570\u3059\u308b\u3068\u3044\u3046\u7279\u5225\u306a\u5834\u5408\u304cEmbedding\u5c64\u3068\u3044\u3048\u305d\u3046\u3067\u3059\u3002<\/p>\n\n\n\n<p>\u3067\u306f\u3001\u306a\u305cEmbedding\u5c64\u3092\u4f7f\u3046\u306e\u304b\u3068\u3044\u3046\u7591\u554f\u304c\u751f\u307e\u308c\u307e\u3059\u3002\u81ea\u8eab\u306e\u61b6\u6e2c\u3067\u306f\u3001\u5206\u6563\u8868\u73fe\u306e\u5b9a\u7fa9\u305d\u306e\u3082\u306e\u3092\u8868\u3059\u306e\u304cEmbedding\u5c64\u3067\u3042\u308a\u3001\u660e\u793a\u7684\u306b\u5c64\u306e\u5f79\u5272\u3092\u5b9a\u3081\u308b\u3053\u3068\u3067\u3001\u4f7f\u7528\u6027\u3084\u79fb\u690d\u6027\u30fb\u5229\u4fbf\u6027\u304c\u4e0a\u304c\u308b\u305f\u3081\u3068\u8003\u3048\u307e\u3059\u3002\u307e\u305f\u3001Embedding\u5c64\u306f\u4f7f\u7528\u983b\u5ea6\u7684\u306b\u3082\u591a\u3044\u306e\u3067\u3001\u6bce\u56deDense\u5c64\u3092\u4f7f\u7528\u3057\u3066Embedding\u5c64\u3092\u5b9a\u7fa9\u3057\u306a\u304a\u3057\u3066\u3044\u3066\u306f\u5927\u5909\u3060\u304b\u3089\u3068\u8003\u3048\u3089\u308c\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Embedding\u5c64\u3067\u5f97\u3089\u308c\u308b\u5206\u6563\u8868\u73fe<\/h3>\n\n\n\n<p>\u5185\u5bb9\u7684\u306b\u306f\u524d\u306e\u30bb\u30af\u30b7\u30e7\u30f3\u3067\u8aac\u660e\u3057\u305f\u3053\u3068\u3068\u5c11\u3057\u91cd\u8907\u3057\u307e\u3059\u304c\u91cd\u306d\u3066\u8aac\u660e\u3057\u307e\u3059\u3002\u307e\u305a\u3001Word2Vec\u306f\u5206\u6563\u8868\u73fe\u306e\u4e2d\u3067\u3082CBOW\u3084Skip-gram\u3092\u4f7f\u7528\u3057\u305f\u3068\u304d\u306b\u5f97\u3089\u308c\u308b\u7279\u5225\u306a\u5834\u5408\u3067\u3042\u308a\u3001Embedding\u5c64\u3067\u7372\u5f97\u3067\u304d\u308b\u3067\u3042\u308d\u3046\u5168\u3066\u306e\u5206\u6563\u8868\u73fe\uff1dWord2Vec\u3068\u306f\u9650\u308a\u307e\u305b\u3093\u3002\u305d\u306e\u305f\u3081\u3001Embedding\u5c64\u3092\u4f7f\u3048\u3070\u5fc5\u305aWord2Vec\u8868\u73fe\u304c\u5f97\u3089\u308c\u308b\u3068\u3044\u3046\u7406\u89e3\u306f\u9593\u9055\u3063\u3066\u3044\u307e\u3059\u3002Embedding\u5c64\u304c\u5b66\u7fd2\u5f8c\u306bWord2Vec\u306a\u308b\u5206\u6563\u8868\u73fe\u3092\u8868\u73fe\u3067\u304d\u308b\u306e\u306f\u3001CBOW\u3084Skip-gram\u3092\u69cb\u7bc9\u3057\u3066\u5b66\u7fd2\u3055\u305b\u305f\u3068\u304d\u306e\u307f\u3067\u3059\u3002\u3067\u3082\u3001Embedding\u5c64\u304c\u4f7f\u308f\u308c\u308b\u306e\u306f\u3001\u81ea\u7136\u8a00\u8a9e\u51e6\u7406\u306e\u9762\u3067\u4f7f\u7528\u3057\u3084\u3059\u304f\u3001\u307e\u305f\u3001Skip-gram\u3067\u3059\u3067\u306b\u5b66\u7fd2\u3057\u305f\u91cd\u307f\u884c\u5217\u3092\u79fb\u690d\u3059\u308b\u3053\u3068\u3082\u53ef\u80fd\u3067\u3042\u308b\u304b\u3089\u3068\u3044\u3048\u307e\u3059\u3002\u3067\u306f\u3001Word2Vec\u306e\u3088\u3046\u306bCBOW\u3084Skip-gram\u3067\u5f97\u3089\u308c\u308b\u5206\u6563\u8868\u73fe\u4ee5\u5916\u306e\u8868\u73fe\u306f\u610f\u5473\u3092\u306a\u3055\u306a\u3044\u304b\u3068\u3044\u3048\u3070\u305d\u3046\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u3002\u9006\u306b\u3001\u307e\u3063\u3055\u3089\u306aEmbedding\u5c64\u3092\u6bce\u56de\u4f7f\u7528\u3059\u308b\u3053\u3068\u3067\u3001\u6240\u671b\u306e\u30bf\u30b9\u30af\u306b\u7279\u5316\u3057\u305f\u5206\u6563\u8868\u73fe\u304c\u5f97\u3089\u308c\u308b\u3053\u3068\u3082\u591a\u3044\u3068\u8003\u3048\u3089\u308c\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u57cb\u3081\u8fbc\u307f\u884c\u5217\u3068\u57cb\u3081\u8fbc\u307f\u30d9\u30af\u30c8\u30eb<\/h3>\n\n\n\n<p>\u305d\u308c\u3067\u306f\u3001\u6b21\u3067\u5177\u4f53\u7684\u306aEmbedding\u5c64\u306e\u5b9f\u73fe\u65b9\u6cd5\u3092\u793a\u3057\u3066\u3044\u304d\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<p>Embedding\u5c64\u306e\u5185\u90e8\u30a2\u30fc\u30ad\u30c6\u30af\u30c1\u30e3\u306f\u3001\u5927\u304d\u304f2\u3064\u306b\u5206\u3051\u3089\u308c\u30011\u3064\u76ee\u306f\u5165\u529b\u8a18\u53f7\u3092\u793a\u3059\u6570\u5024\u3092OneHot\u30d9\u30af\u30c8\u30eb\u306b\u5909\u63db\u3059\u308b\u3053\u3068\u30012\u3064\u76ee\u306f\u305d\u306eOneHot\u30d9\u30af\u30c8\u30eb\u3092\u3088\u308a\u4f4e\u6b21\u306e\u30d9\u30af\u30c8\u30eb\u7a7a\u9593\u4e0a\u306b\u7dda\u5f62\u5199\u50cf\u3059\u308b\u3053\u3068\u3067\u3059\u3002\u524d\u8005\u306f\u7279\u306b\u8aac\u660e\u3059\u308b\u307e\u3067\u3082\u306a\u3044\u306e\u3067\u3001\u5f8c\u8005\u306e\u90e8\u5206\u306b\u3064\u3044\u3066\u8aac\u660e\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u7dda\u5f62\u5199\u50cf\u306a\u306e\u3067\u3001\u5909\u63db\u884c\u5217\\(W_{embedding}^T\\)\u3092\u8003\u3048\u307e\u3059\u3002vocabulary_size\uff08\u4ee5\u4e0b:n\uff09\u306f\u5165\u529b\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u30c8\u30fc\u30af\u30f3\u306e\u7a2e\u985e\u3001\u4e00\u822c\u7684\u306b\u306f\u5358\u8a9e\u306e\u7a2e\u985e\u306b\u5bfe\u5fdc\u3057\u3001embedding_size\uff08\u4ee5\u4e0b:m\uff09\u306f\u57cb\u3081\u8fbc\u307f\u6b21\u5143\u306e\u30b5\u30a4\u30ba\u3092\u793a\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img decoding=\"async\" width=\"696\" height=\"298\" src=\"https:\/\/developers.agirobots.com\/jp\/wp-content\/uploads\/2020\/08\/image-5.png\" alt=\"\" class=\"wp-image-2091\" srcset=\"https:\/\/developers.agirobots.com\/jp\/wp-content\/uploads\/2020\/08\/image-5.png 696w, https:\/\/developers.agirobots.com\/jp\/wp-content\/uploads\/2020\/08\/image-5-300x128.png 300w\" sizes=\"(max-width: 696px) 100vw, 696px\" \/><\/figure><\/div>\n\n\n\n<p>\u3053\u306e\u3068\u304d\u3001OneHot\u30d9\u30af\u30c8\u30eb\u304b\u3089\u3001\u57cb\u3081\u8fbc\u307f\u6b21\u5143\u3078\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3057\u3066\u5909\u63db\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter is-resized\"><img decoding=\"async\" src=\"https:\/\/texclip.marutank.net\/render.php\/texclip20200810110428.png?s=%5Cleft%5B%0D%0A%20%20%20%20%5Cbegin%7Barray%7D%7Bc%7D%0D%0A%20%20%20%20%20%20%20%20w_%7Bi1%7D%5C%5C%0D%0A%20%20%20%20%20%20%20%20w_%7Bi2%7D%5C%5C%0D%0A%20%20%20%20%20%20%20%20%5Cvdots%5C%5C%0D%0A%20%20%20%20%20%20%20%20w_%7Bim%7D%0D%0A%20%20%20%20%5Cend%7Barray%7D%0D%0A%5Cright%5D%0D%0A%3D%0D%0A%5Cleft%5B%0D%0A%20%20%20%20%5Cbegin%7Barray%7D%7Bcccc%7D%0D%0A%20%20%20%20%20%20%20%20w_%7B11%7D%26w_%7B12%7D%26%5Ccdots%26w_%7B1m%7D%5C%5C%0D%0A%20%20%20%20%20%20%20%20%5Cvdots%26%5Cvdots%26%26%5Cvdots%5C%5C%0D%0A%20%20%20%20%20%20%20%20w_%7Bi1%7D%26w_%7Bi2%7D%26%5Ccdots%26w_%7Bim%7D%5C%5C%0D%0A%20%20%20%20%20%20%20%20%5Cvdots%26%5Cvdots%26%26%5Cvdots%5C%5C%0D%0A%20%20%20%20%20%20%20%20w_%7Bn1%7D%26w_%7Bn2%7D%26%5Ccdots%26w_%7Bnm%7D%0D%0A%20%20%20%20%5Cend%7Barray%7D%0D%0A%5Cright%5D%5ET%0D%0A%5Cleft%5B%0D%0A%20%20%20%20%5Cbegin%7Barray%7D%7Bc%7D%0D%0A%20%20%20%20%20%20%20%200%5C%5C%0D%0A%20%20%20%20%20%20%20%20%5Cvdots%5C%5C%0D%0A%20%20%20%20%20%20%20%201%5C%5C%0D%0A%20%20%20%20%20%20%20%20%5Cvdots%5C%5C%0D%0A%20%20%20%20%20%20%20%200%0D%0A%20%20%20%20%5Cend%7Barray%7D%0D%0A%5Cright%5D&amp;f=c&amp;r=300&amp;m=p&amp;b=f&amp;k=f\" alt=\"\\left[\n    \\begin{array}{c}\n        w_{i1}\\\\\n        w_{i2}\\\\\n        \\vdots\\\\\n        w_{im}\n    \\end{array}\n\\right]\n=\n\\left[\n    \\begin{array}{cccc}\n        w_{11}&amp;w_{12}&amp;\\cdots&amp;w_{1m}\\\\\n        \\vdots&amp;\\vdots&amp;&amp;\\vdots\\\\\n        w_{i1}&amp;w_{i2}&amp;\\cdots&amp;w_{im}\\\\\n        \\vdots&amp;\\vdots&amp;&amp;\\vdots\\\\\n        w_{n1}&amp;w_{n2}&amp;\\cdots&amp;w_{nm}\n    \\end{array}\n\\right]^T\n\\left[\n    \\begin{array}{c}\n        0\\\\\n        \\vdots\\\\\n        1\\\\\n        \\vdots\\\\\n        0\n    \\end{array}\n\\right]\" width=\"605\" height=\"261\"\/><\/figure><\/div>\n\n\n\n<p>\u3053\u306e\u91cd\u307f\u884c\u5217\u306f\u30cb\u30e5\u30fc\u30e9\u30eb\u30cd\u30c3\u30c8\u3092\u69cb\u6210\u3059\u308b\u30cb\u30e5\u30fc\u30ed\u30f3\u540c\u58eb\u306e\u8fba\u306e\u91cd\u307f\u306b\u5bfe\u5fdc\u3059\u308b\u3053\u3068\u304b\u3089\u3001Embedding\u5c64\u306f\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u56f3\u3067\u8868\u3059\u30a2\u30fc\u30ad\u30c6\u30af\u30c1\u30e3\u3067\u5b9f\u73fe\u3067\u304d\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002\u91cd\u307f\u884c\u5217\u306e\u5b66\u7fd2\u306fBP\uff08\u8aa4\u5dee\u9006\u4f1d\u64ad\uff09\u306b\u3088\u308a\u884c\u308f\u308c\u307e\u3059\u3002\u4f8b\u3048\u3070\u5358\u8a9e\u306eweather\u306b\u5bfe\u5fdc\u3059\u308b\u6570\u5024\u304c256\u3068\u3057\u307e\u3059\u3002\u3053\u306e\u3068\u304d\u3001256\u3092Embedding\u5c64\u306b\u5165\u529b\u3059\u308b\u3068\u3001256\u756a\u76ee\u306e\u307f\u304c1\u306eOneHot\u30d9\u30af\u30c8\u30eb\u304c\u751f\u6210\u3055\u308c\u3001\u5909\u63db\u884c\u5217\u306b\u3088\u308a\u57cb\u3081\u8fbc\u307f\u884c\u5217\u306b\u5199\u50cf\u3055\u308c\u305f\u3082\u306e\u304c\u51fa\u529b\u3055\u308c\u308b\u30b9\u30c6\u30c3\u30d7\u3092\u8868\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img decoding=\"async\" width=\"907\" height=\"462\" src=\"https:\/\/developers.agirobots.com\/jp\/wp-content\/uploads\/2020\/08\/image-2.png\" alt=\"\" class=\"wp-image-2085\" srcset=\"https:\/\/developers.agirobots.com\/jp\/wp-content\/uploads\/2020\/08\/image-2.png 907w, https:\/\/developers.agirobots.com\/jp\/wp-content\/uploads\/2020\/08\/image-2-300x153.png 300w, https:\/\/developers.agirobots.com\/jp\/wp-content\/uploads\/2020\/08\/image-2-768x391.png 768w\" sizes=\"(max-width: 907px) 100vw, 907px\" \/><\/figure><\/div>\n\n\n\n<p>\u305d\u3057\u3066\u3001\u5b66\u7fd2\u3067\u5f97\u3089\u308c\u305f\u884c\u5217\u304b\u3089\u3001\u8a18\u53f7\u306e\u756a\u53f7\u3092\\(num\\)\u3068\u3057\u3066\\(W_{embedding}[num]\\)\u306e\u3088\u3046\u306b\u57cb\u3081\u8fbc\u307f\u30d9\u30af\u30c8\u30eb\u3092\u53d6\u5f97\u3067\u304d\u307e\u3059\u3002\u3053\u306e\u3088\u3046\u306a\u6027\u8cea\u3088\u308aEmbedding\u5c64\u306f\u3001\u30eb\u30c3\u30af\u30a2\u30c3\u30d7\u30c6\u30fc\u30d6\u30eb\u3082\u3057\u304f\u306f\u8f9e\u66f8\u3068\u8aac\u660e\u3055\u308c\u308b\u3053\u3068\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u5404\u30e9\u30a4\u30d6\u30e9\u30ea\u3067Embedding\u5c64\u3092\u4f7f\u7528\u3059\u308b\u65b9\u6cd5<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">TensorFlow\u306eembedding _lookup<\/h3>\n\n\n\n<p>\u203b\u73fe\u5728\u306fplaceholder\u304c\u7121\u52b9\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u304c\u3001\u6709\u52b9\u306a\u5834\u5408\u306e\u8868\u8a18\u3092\u793a\u3057\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>voc_size = 5000\nemb_size = 100\n\n# \u5909\u63db\u884c\u5217W_{embedding}\u3092\u30d1\u30e9\u30e1\u30fc\u30bf\u3067\u5b9a\u7fa9\nparams = tf.Variable(tf.random_uniform([voc_size, emb_size], -1.0, 1.0))\n\n# \u30b9\u30ab\u30e9\u30fc\u306e\u756a\u53f7\u304c\u4efb\u610f\u306e\u30d0\u30c3\u30c1\u30b5\u30a4\u30ba\u3067\u5165\u529b\u3055\u308c\u308b\u72b6\u6cc1\u3092\u4eee\u5b9a\nids = tf.placeholder(tf.int32, shape=[None])\n\ntf.nn.embedding_lookup(\n        params=params,     # \u5909\u63db\u884c\u5217\n        ids=ids    # \u5165\u529b\u5f62\u5f0f\u3092\u5b9a\u7fa9\n)<\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">keras\u306eEmbedding<\/h3>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>voc_size = 5000\nemb_size = 100\n\n# TensorFlow\u3068\u306f\u7570\u306a\u308a\u5916\u90e8\u3067\u5909\u63db\u884c\u5217\u3092\u5b9a\u7fa9\u3059\u308b\u5fc5\u8981\u306f\u306a\u3044\u304c\u3001\n# \u5f15\u6570\u3068\u3057\u3066\u5909\u63db\u884c\u5217\u306e\u5f62\u614b\u3001\u30d1\u30e9\u30e1\u30fc\u30bf\u306e\u521d\u671f\u5316\u65b9\u6cd5\u7b49\u3092\u6307\u5b9a\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\nEmbedding(input_dim=voc_size,     # vocabulary_size\n          output_dim=emb_size,     # embedding_size\n          embeddings_initializer=&#39;uniform&#39;, \n          embeddings_regularizer=None, \n          activity_regularizer=None, \n          embeddings_constraint=None, \n          mask_zero=False, \n          input_length=None)<\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">PyTorch\u306eEmbedding<\/h3>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code># \u3053\u308c\u306f\u5f15\u6570\u60c5\u5831\u3092\u542b\u3093\u3067\u3044\u308b\u306e\u3067\u3001\u3053\u306e\u307e\u307e\u30bf\u30fc\u30df\u30ca\u30eb\u306b\n# \u30b3\u30d4\u30da\u3059\u308c\u3070\u52d5\u304f\u3068\u3044\u3046\u308f\u3051\u3067\u306f\u306a\u3044\u3067\u3059\u304c\u3001Keras\u3068\n# \u57fa\u672c\u7684\u306b\u306f\u5909\u308f\u3089\u306a\u3044\u305f\u3081\u3001\u5f15\u6570\u60c5\u5831\u306e\u307f\u793a\u3057\u307e\u3059\nEmbedding(num_embeddings: int, \n          embedding_dim: int, \n          padding_idx: Optional[int] = None, \n          max_norm: Optional[float] = None, \n          norm_type: float = 2.0, \n          scale_grad_by_freq: bool = False, \n          sparse: bool = False, \n          _weight: Optional[torch.Tensor] = None)<\/code><\/pre><\/div>\n\n\n\n<!-- \u30e1\u30e2\n\\left[\n    \\begin{array}{c}\n        w_{i1}\\\\\n        w_{i2}\\\\\n        \\vdots\\\\\n        w_{im}\n    \\end{array}\n\\right]\n=\n\\left[\n    \\begin{array}{cccc}\n        w_{11}&w_{12}&\\cdots&w_{1m}\\\\\n        \\vdots&\\vdots&&\\vdots\\\\\n        w_{i1}&w_{i2}&\\cdots&w_{im}\\\\\n        \\vdots&\\vdots&&\\vdots\\\\\n        w_{n1}&w_{n2}&\\cdots&w_{nm}\n    \\end{array}\n\\right]^T\n\\left[\n    \\begin{array}{c}\n        0\\\\\n        \\vdots\\\\\n        1\\\\\n        \\vdots\\\\\n        0\n    \\end{array}\n\\right]\n-->\n\n\n\n<h2 class=\"wp-block-heading\">\u307e\u3068\u3081<\/h2>\n\n\n\n<p>Embedding\u5c64\u306f\u3001\u7269\u7406\u7684\u8a08\u6e2c\u306e\u4e0d\u53ef\u80fd\u306a\u8a18\u53f7\u96c6\u5408\u3092\u30d9\u30af\u30c8\u30eb\u7a7a\u9593\u306b\u5199\u50cf\u3059\u308b\u5206\u6563\u8868\u73fe\u305d\u306e\u3082\u306e\u306e\u5b9a\u7fa9\u3092\u5b9f\u73fe\u3059\u308b\u3082\u306e\u3067\u3001COW\u3084Skip-gram\u3092\u4f7f\u3048\u3070\u5358\u8a9e\u540c\u58eb\u306e\u610f\u5473\u306b\u3088\u308b\u30d9\u30af\u30c8\u30eb\u8a08\u7b97\u304c\u53ef\u80fd\u306a\u5206\u6563\u8868\u73fe\u3092\u5f97\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u305d\u308c\u4ee5\u5916\u306e\u5206\u6563\u8868\u73fe\u3082\u5b66\u7fd2\u53ef\u80fd\u3067\u3001\u305d\u308c\u305e\u308c\u306e\u30bf\u30b9\u30af\u306b\u7279\u5316\u3057\u3066\u57cb\u3081\u8fbc\u307f\u3092\u5b66\u7fd2\u3059\u308b\u3053\u3068\u3067\u3001\u8a00\u8a9e\u306e\u3088\u3046\u306a\u7269\u7406\u7684\u8a08\u6e2c\u304c\u4e0d\u53ef\u80fd\u306a\u8a18\u53f7\u96c6\u5408\u3068\u30cb\u30e5\u30fc\u30e9\u30eb\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u306e\u304b\u3051\u6a4b\u3068\u3057\u3066\u91cd\u8981\u306a\u5f79\u5272\u3092\u62c5\u3063\u3066\u3044\u308b\u3068\u8003\u3048\u3089\u308c\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Word2Vec\u3084Embedding\u5c64\u306b\u3064\u3044\u3066\u81ea\u8eab\u306e\u7406\u89e3\u304c\u66d6\u6627\u3060\u3063\u305f\u306e\u3067\u3001\u5b66\u7fd2\u304c\u3066\u3089\u81ea\u8eab\u306e\u8003\u5bdf\u3092\u793a\u3057\u306a\u304c\u3089\u307e\u3068\u3081\u307e\u3057\u305f\u3002 \u5206\u6563\u8868\u73fe \u540d\u524d\u306a\u3069\u7269\u7406\u7684\u306a\u8a08\u6e2c\u304c\u4e0d\u53ef\u80fd\u306a\u8a18\u53f7\u96c6\u5408\u3092\u30d9\u30af\u30c8\u30eb\u306b\u5bfe\u5fdc\u4ed8\u3051\u305f\u3082\u306e\u3092\u5206 &#8230; <\/p>\n","protected":false},"author":1,"featured_media":2085,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_vk_print_noindex":"","sitemap_hide":"","_veu_custom_css":"","veu_display_promotion_alert":"","vkexunit_cta_each_option":"","_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[170,171,106,174],"tags":[158,146,156,147,157],"class_list":["post-1993","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog","category-learn","category-ml","category-dl","tag-embedding","tag-146","tag-156","tag-147","tag-157"],"veu_head_title_object":{"title":"","add_site_title":""},"jetpack_featured_media_url":"https:\/\/developers.agirobots.com\/jp\/wp-content\/uploads\/2020\/08\/image-2.png","jetpack-related-posts":[],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/developers.agirobots.com\/jp\/wp-json\/wp\/v2\/posts\/1993","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/developers.agirobots.com\/jp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/developers.agirobots.com\/jp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/developers.agirobots.com\/jp\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/developers.agirobots.com\/jp\/wp-json\/wp\/v2\/comments?post=1993"}],"version-history":[{"count":37,"href":"https:\/\/developers.agirobots.com\/jp\/wp-json\/wp\/v2\/posts\/1993\/revisions"}],"predecessor-version":[{"id":4254,"href":"https:\/\/developers.agirobots.com\/jp\/wp-json\/wp\/v2\/posts\/1993\/revisions\/4254"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/developers.agirobots.com\/jp\/wp-json\/wp\/v2\/media\/2085"}],"wp:attachment":[{"href":"https:\/\/developers.agirobots.com\/jp\/wp-json\/wp\/v2\/media?parent=1993"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/developers.agirobots.com\/jp\/wp-json\/wp\/v2\/categories?post=1993"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/developers.agirobots.com\/jp\/wp-json\/wp\/v2\/tags?post=1993"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}