
{"id":351,"date":"2024-11-19T11:37:44","date_gmt":"2024-11-19T16:37:44","guid":{"rendered":"https:\/\/www.otherroute.net\/wordpress\/?p=351"},"modified":"2026-04-07T22:22:06","modified_gmt":"2026-04-08T02:22:06","slug":"king-man-woman-%e2%89%88-king","status":"publish","type":"post","link":"https:\/\/www.otherroute.net\/wordpress\/2024\/11\/king-man-woman-%e2%89%88-king\/","title":{"rendered":"King &#8211; Man + Woman \u2248 King"},"content":{"rendered":"\n<p>An <a href=\"https:\/\/medium.com\/plotly\/understanding-word-embedding-arithmetic-why-theres-no-single-answer-to-king-man-woman-cd2760e2cb7f\" data-type=\"link\" data-id=\"https:\/\/medium.com\/plotly\/understanding-word-embedding-arithmetic-why-theres-no-single-answer-to-king-man-woman-cd2760e2cb7f\">article by Plotly<\/a><sup data-fn=\"6b928c77-f645-47d6-aefa-c870ba2838b7\" class=\"fn\"><a href=\"#6b928c77-f645-47d6-aefa-c870ba2838b7\" id=\"6b928c77-f645-47d6-aefa-c870ba2838b7-link\">1<\/a><\/sup> shows how the main analogy for what embeddings represent is a bit shaky. It sounds good and works like the analogies logic from the SAT. But it only kind of works.<\/p>\n\n\n\n<p>I was reading all this stuff about embeddings and it&#8217;s really a surprising feature that you could do simple vector math to solve analogies. At first I assumed that the major trained models must have been trained with analogies. You really could create layers that subtract and add embeddings and do supervised learning on a known set of analogies, training the embeddings to represent gender with a single, similar vector. But nobody does this. It seems like just an amazing emergent feature of training the hidden layer we get the embeddings from!<\/p>\n\n\n\n<p>It kind of works. But not quite, and it takes a bit of cheating.<sup data-fn=\"c122e310-0ca4-4e92-994c-70ec1897ebd5\" class=\"fn\"><a href=\"#c122e310-0ca4-4e92-994c-70ec1897ebd5\" id=\"c122e310-0ca4-4e92-994c-70ec1897ebd5-link\">2<\/a><\/sup> Taking an embedding vector for King, subtracting the vector for Man and adding the vector for Woman makes a new vector. But the cosine distance isn&#8217;t far enough away from King. You have to exclude King, Man, and Woman in order to make this vector close to the embedding vector for Queen.<\/p>\n\n\n\n<p>I tried this myself with OpenAI&#8217;s modern embedding model, &#8220;text-embedding-3-small&#8221;.<sup data-fn=\"970cd984-7b48-48e4-9a94-eca9b9581a13\" class=\"fn\"><a href=\"#970cd984-7b48-48e4-9a94-eca9b9581a13\" id=\"970cd984-7b48-48e4-9a94-eca9b9581a13-link\">3<\/a><\/sup> It gives the same results. The closest vector is still King. There&#8217;s a lot of error even if you exclude King from the possible results. The embeddings themselves don&#8217;t store good analogy information in just linear vector math. The hidden layers and attention heads will still have to work to make the embeddings into something really useful. It&#8217;s still neat that we get somewhat close values and it shows something is encoded in these embeddings. The results just don&#8217;t work exactly as I&#8217;ve been reading and what I&#8217;ve been taught about embeddings. I&#8217;m not going to start trusting any vector math using real embeddings anytime soon.<\/p>\n\n\n\n<p>This slightly disappointing result does fit some basic intuition. The model wasn&#8217;t trained to make vector addition a feature of its values. It&#8217;s a bunch of information ready for transfer learning. And what other information is in there? Embedding vectors encode a lot more information, maybe important nuances and maybe extraneous values, in the vector values than you would want in a space made for analogies.<\/p>\n\n\n<ol class=\"wp-block-footnotes\"><li id=\"6b928c77-f645-47d6-aefa-c870ba2838b7\">Plotly Graph, &#8220;Understanding Word Embedding Arithmetic: Why there\u2019s no single answer to \u201cKing \u2212 Man + Woman = ?&#8221;. <a href=\"https:\/\/medium.com\/plotly\/understanding-word-embedding-arithmetic-why-theres-no-single-answer-to-king-man-woman-cd2760e2cb7f\">https:\/\/medium.com\/plotly\/understanding-word-embedding-arithmetic-why-theres-no-single-answer-to-king-man-woman-cd2760e2cb7f<\/a>, 2020 <a href=\"#6b928c77-f645-47d6-aefa-c870ba2838b7-link\" aria-label=\"Jump to footnote reference 1\">\u21a9\ufe0e<\/a><\/li><li id=\"c122e310-0ca4-4e92-994c-70ec1897ebd5\">Florian Huber, &#8220;King &#8211; Man + Woman = King ?&#8221;. <a href=\"https:\/\/blog.esciencecenter.nl\/king-man-woman-king-9a7fd2935a85\">https:\/\/blog.esciencecenter.nl\/king-man-woman-king-9a7fd2935a85<\/a>, 2019 <a href=\"#c122e310-0ca4-4e92-994c-70ec1897ebd5-link\" aria-label=\"Jump to footnote reference 2\">\u21a9\ufe0e<\/a><\/li><li id=\"970cd984-7b48-48e4-9a94-eca9b9581a13\">Code to try this with OpenAI&#8217;s embeddings: <a href=\"https:\/\/github.com\/seanmcnealy\/seanmcnealy_samples\/blob\/master\/embeddings.py\">https:\/\/github.com\/seanmcnealy\/seanmcnealy_samples\/blob\/master\/embeddings.py<\/a> <a href=\"#970cd984-7b48-48e4-9a94-eca9b9581a13-link\" aria-label=\"Jump to footnote reference 3\">\u21a9\ufe0e<\/a><\/li><\/ol>","protected":false},"excerpt":{"rendered":"<p>An article by Plotly shows how the main analogy for what embeddings represent is a bit shaky. It sounds good and works like the analogies logic from the SAT. But it only kind of works. I was reading all this &hellip;<\/p>\n<p class=\"read-more\"><a href=\"https:\/\/www.otherroute.net\/wordpress\/2024\/11\/king-man-woman-%e2%89%88-king\/\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":2,"featured_media":353,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":"[{\"id\":\"6b928c77-f645-47d6-aefa-c870ba2838b7\",\"content\":\"Plotly Graph, \\\"Understanding Word Embedding Arithmetic: Why there\\u2019s no single answer to \\u201cKing \\u2212 Man + Woman = ?\\\". <a href=\\\"https:\\\/\\\/medium.com\\\/plotly\\\/understanding-word-embedding-arithmetic-why-theres-no-single-answer-to-king-man-woman-cd2760e2cb7f\\\">https:\\\/\\\/medium.com\\\/plotly\\\/understanding-word-embedding-arithmetic-why-theres-no-single-answer-to-king-man-woman-cd2760e2cb7f<\\\/a>, 2020\"},{\"id\":\"c122e310-0ca4-4e92-994c-70ec1897ebd5\",\"content\":\"Florian Huber, \\\"King - Man + Woman = King ?\\\". <a href=\\\"https:\\\/\\\/blog.esciencecenter.nl\\\/king-man-woman-king-9a7fd2935a85\\\">https:\\\/\\\/blog.esciencecenter.nl\\\/king-man-woman-king-9a7fd2935a85<\\\/a>, 2019\"},{\"id\":\"970cd984-7b48-48e4-9a94-eca9b9581a13\",\"content\":\"Code to try this with OpenAI's embeddings: <a href=\\\"https:\\\/\\\/github.com\\\/seanmcnealy\\\/seanmcnealy_samples\\\/blob\\\/master\\\/embeddings.py\\\">https:\\\/\\\/github.com\\\/seanmcnealy\\\/seanmcnealy_samples\\\/blob\\\/master\\\/embeddings.py<\\\/a>\"}]"},"categories":[1],"tags":[],"class_list":["post-351","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.otherroute.net\/wordpress\/wp-json\/wp\/v2\/posts\/351","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.otherroute.net\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.otherroute.net\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.otherroute.net\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.otherroute.net\/wordpress\/wp-json\/wp\/v2\/comments?post=351"}],"version-history":[{"count":3,"href":"https:\/\/www.otherroute.net\/wordpress\/wp-json\/wp\/v2\/posts\/351\/revisions"}],"predecessor-version":[{"id":404,"href":"https:\/\/www.otherroute.net\/wordpress\/wp-json\/wp\/v2\/posts\/351\/revisions\/404"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.otherroute.net\/wordpress\/wp-json\/wp\/v2\/media\/353"}],"wp:attachment":[{"href":"https:\/\/www.otherroute.net\/wordpress\/wp-json\/wp\/v2\/media?parent=351"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.otherroute.net\/wordpress\/wp-json\/wp\/v2\/categories?post=351"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.otherroute.net\/wordpress\/wp-json\/wp\/v2\/tags?post=351"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}