{
  "source_file": "0930",
  "source_platform": "Medium",
  "author": "Ebrahim Pichka",
  "title_listed": "What are Query, Key, and Value in the Transformer Architecture and Why Are They Used?",
  "keywords": "Transformer,QKV,注意力",
  "domain": "大模型算法",
  "content_type": "深度技术解析",
  "is_paid_flag": "部分免费/会员墙",
  "url": "https://towardsdatascience.com/what-are-query-key-and-value-in-the-transformer-architecture-and-why-are-they-used-acbe73f731f2/",
  "publish_date": "2023-10",
  "corpus_stage": "预训练/SFT",
  "notes": "",
  "id": "796d155eca9c",
  "collected_at": "2026-10-01T23:11:03",
  "title": "What are Query, Key, and Value in the Transformer Architecture and Why Are They Used? | Towards Data Science",
  "body_markdown": "![Revisit consent button](https://cdn-cookieyes.com/assets/images/revisit.svg)\nWe value your privacy\nWe use cookies to enhance your browsing experience, serve personalised ads or content, and analyse our traffic. By clicking \"Accept All\", you consent to our use of cookies.\nCustomise Reject All Accept All\nCustomise Consent Preferences ![](https://cdn-cookieyes.com/assets/images/close.svg)\nWe use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.\nThe cookies that are categorised as \"Necessary\" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... Show more\nNecessaryAlways Active\nNecessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.\n  * Cookie\nBCTempID\n  * Duration\n10 minutes\n  * Description\nNo description available.\n\n\n  * Cookie\n__cf_bm\n  * Duration\n1 hour\n  * Description\nThis cookie, set by Cloudflare, is used to support Cloudflare Bot Management. \n\n\n  * Cookie\nAWSALBCORS\n  * Duration\n7 days\n  * Description\nAmazon Web Services set this cookie for load balancing.\n\n\n  * Cookie\n_cfuvid\n  * Duration\nsession\n  * Description\nCloudflare sets this cookie to track users across sessions to optimize user experience by maintaining session consistency and providing personalized services\n\n\n  * Cookie\nli_gc\n  * Duration\n6 months\n  * Description\nLinkedin set this cookie for storing visitor's consent regarding using cookies for non-essential purposes.\n\n\n  * Cookie\n__hssrc\n  * Duration\nsession\n  * Description\nThis cookie is set by Hubspot whenever it changes the session cookie. The __hssrc cookie set to 1 indicates that the user has restarted the browser, and if the cookie does not exist, it is assumed to be a new session.\n\n\n  * Cookie\n__hssc\n  * Duration\n1 hour\n  * Description\nHubSpot sets this cookie to keep track of sessions and to determine if HubSpot should increment the session number and timestamps in the __hstc cookie.\n\n\n  * Cookie\nwpEmojiSettingsSupports\n  * Duration\nsession\n  * Description\nWordPress sets this cookie when a user interacts with emojis on a WordPress site. It helps determine if the user's browser can display emojis properly.\n\n\n  * Cookie\nBCSessionID\n  * Duration\n1 year 1 month 4 days\n  * Description\nBlueconic sets this cookie as a unique identifier for the BlueConic profile.\n\n\n  * Cookie\n_octo\n  * Duration\n1 year\n  * Description\nNo description available.\n\n\n  * Cookie\nlogged_in\n  * Duration\n1 year\n  * Description\nNo description available.\n\n\n  * Cookie\n__Secure-YEC\n  * Duration\npast\n  * Description\nYouTube sets this cookie to stores the user's video player preferences using embedded YouTube video\n\n\n  * Cookie\n__eoi\n  * Duration\n6 months\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nAWSALBTGCORS\n  * Duration\n7 days\n  * Description\nNo description available.\n\n\n  * Cookie\nlogin-status-p\n  * Duration\npast\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nAWSALBTG\n  * Duration\n7 days\n  * Description\nNo description available.\n\n\n  * Cookie\ncsrf_token\n  * Duration\nsession\n  * Description\nNo description available.\n\n\n  * Cookie\ntoken_v2\n  * Duration\n1 day\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nD\n  * Duration\n1 year\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nPHPSESSID\n  * Duration\nsession\n  * Description\nThis cookie is native to PHP applications. The cookie stores and identifies a user's unique session ID to manage user sessions on the website. The cookie is a session cookie and will be deleted when all the browser windows are closed.\n\n\n  * Cookie\nVISITOR_PRIVACY_METADATA\n  * Duration\n6 months\n  * Description\nYouTube sets this cookie to store the user's cookie consent state for the current domain. \n\n\n  * Cookie\ncookietest\n  * Duration\nsession\n  * Description\nThe cookietest cookie is typically used to determine whether the user's browser accepts cookies, essential for website functionality and user experience.\n\n\n  * Cookie\n__Host-airtable-session\n  * Duration\n1 year\n  * Description\nThis cookie is used to enable us to integrate the services of Airtable.\n\n\n  * Cookie\n__Host-airtable-session.sig\n  * Duration\n1 year\n  * Description\nThis cookie is used to enable us to integrate the services of Airtable.\n\n\n  * Cookie\nm\n  * Duration\n1 year 1 month 4 days\n  * Description\nStripe sets this cookie for fraud prevention purposes. It identifies the device used to access the website, allowing the website to be formatted accordingly.\n\n\n  * Cookie\nBIGipServer*\n  * Duration\nsession\n  * Description\nMarketo sets this cookie to collect information about the user's online activity and build a profile about their interests to provide advertisements relevant to the user. \n\n\n  * Cookie\n__cfruid\n  * Duration\nsession\n  * Description\nCloudflare sets this cookie to identify trusted web traffic.\n\n\n  * Cookie\n_GRECAPTCHA\n  * Duration\n6 months\n  * Description\nGoogle Recaptcha service sets this cookie to identify bots to protect the website against malicious spam attacks.\n\n\n  * Cookie\n__Secure-YNID\n  * Duration\n6 months\n  * Description\nGoogle cookie used to protect user security and prevent fraud, especially during the login process.\n\n\n  * Cookie\ncookieyes-consent\n  * Duration\n1 year\n  * Description\nCookieYes sets this cookie to remember users' consent preferences so that their preferences are respected on subsequent visits to this site. It does not collect or store any personal information about the site visitors.\n\n\nFunctional\nFunctional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.\n  * Cookie\nlidc\n  * Duration\n1 day\n  * Description\nLinkedIn sets the lidc cookie to facilitate data center selection.\n\n\n  * Cookie\nbrw\n  * Duration\n1 year\n  * Description\nNo description available.\n\n\n  * Cookie\nbrwConsent\n  * Duration\n5 minutes\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nWMF-Uniq\n  * Duration\n1 year\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nloom_anon_comment\n  * Duration\n1 year\n  * Description\nNo description available.\n\n\n  * Cookie\nloom_referral_video\n  * Duration\nsession\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nVISITOR_INFO1_LIVE\n  * Duration\n6 months\n  * Description\nA cookie set by YouTube to measure bandwidth that determines whether the user gets the new or old player interface.\n\n\n  * Cookie\nyt-remote-connected-devices\n  * Duration\nNever Expires\n  * Description\nYouTube sets this cookie to store the user's video preferences using embedded YouTube videos.\n\n\n  * Cookie\nytidb::LAST_RESULT_ENTRY_KEY\n  * Duration\nNever Expires\n  * Description\nThe cookie ytidb::LAST_RESULT_ENTRY_KEY is used by YouTube to store the last search result entry that was clicked by the user. This information is used to improve the user experience by providing more relevant search results in the future.\n\n\n  * Cookie\nyt-remote-device-id\n  * Duration\nNever Expires\n  * Description\nYouTube sets this cookie to store the user's video preferences using embedded YouTube videos.\n\n\n  * Cookie\nyt-remote-session-name\n  * Duration\nsession\n  * Description\nThe yt-remote-session-name cookie is used by YouTube to store the user's video player preferences using embedded YouTube video.\n\n\n  * Cookie\nyt-remote-fast-check-period\n  * Duration\nsession\n  * Description\nThe yt-remote-fast-check-period cookie is used by YouTube to store the user's video player preferences for embedded YouTube videos.\n\n\n  * Cookie\nyt-remote-session-app\n  * Duration\nsession\n  * Description\nThe yt-remote-session-app cookie is used by YouTube to store user preferences and information about the interface of the embedded YouTube video player.\n\n\n  * Cookie\nyt-remote-cast-available\n  * Duration\nsession\n  * Description\nThe yt-remote-cast-available cookie is used to store the user's preferences regarding whether casting is available on their YouTube video player.\n\n\n  * Cookie\nyt-remote-cast-installed\n  * Duration\nsession\n  * Description\nThe yt-remote-cast-installed cookie is used to store the user's video player preferences using embedded YouTube video.\n\n\n  * Cookie\ncp_session\n  * Duration\n3 months\n  * Description\nCodepen sets this cookie for Help systems found in the website.\n\n\n  * Cookie\nloid\n  * Duration\n1 year 1 month 4 days\n  * Description\nThis cookie is set by the Reddit. The cookie enables the sharing of content from the website onto the social media platform.\n\n\nAnalytics\nAnalytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.\n  * Cookie\n__hstc\n  * Duration\n6 months\n  * Description\nHubspot set this main cookie for tracking visitors. It contains the domain, initial timestamp (first visit), last timestamp (last visit), current timestamp (this visit), and session number (increments for each subsequent session).\n\n\n  * Cookie\nhubspotutk\n  * Duration\n6 months\n  * Description\nHubSpot sets this cookie to keep track of the visitors to the website. This cookie is passed to HubSpot on form submission and used when deduplicating contacts.\n\n\n  * Cookie\n_ga\n  * Duration\n1 year 1 month 4 days\n  * Description\nGoogle Analytics sets this cookie to calculate visitor, session and campaign data and track site usage for the site's analytics report. The cookie stores information anonymously and assigns a randomly generated number to recognise unique visitors.\n\n\n  * Cookie\n_ga_*\n  * Duration\n1 year 1 month 4 days\n  * Description\nGoogle Analytics sets this cookie to store and count page views.\n\n\n  * Cookie\n__Host-psifi.analyticsTrace\n  * Duration\n6 hours\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\n__Host-psifi.analyticsTraceV2\n  * Duration\n6 hours\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\n_gh_sess\n  * Duration\nsession\n  * Description\nGitHub sets this cookie for temporary application and framework state between pages like what step the user is on in a multiple step form.\n\n\n  * Cookie\nYSC\n  * Duration\nsession\n  * Description\nYSC cookie is set by Youtube and is used to track the views of embedded videos on Youtube pages.\n\n\n  * Cookie\najs_anonymous_id\n  * Duration\n1 year\n  * Description\nThis cookie is set by Segment to count the number of people who visit a certain site by tracking if they have visited before.\n\n\n  * Cookie\nvuid\n  * Duration\n1 year 1 month 4 days\n  * Description\nVimeo installs this cookie to collect tracking information by setting a unique ID to embed videos on the website. \n\n\nPerformance\nPerformance cookies are used to understand and analyse the key performance indexes of the website which helps in delivering a better user experience for the visitors.\n  * Cookie\nAWSALB\n  * Duration\n7 days\n  * Description\nAWSALB is an application load balancer cookie set by Amazon Web Services to map the session to the target.\n\n\n  * Cookie\nacq\n  * Duration\npast\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nacq.sig\n  * Duration\npast\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nptc\n  * Duration\n2 years\n  * Description\nNo description available.\n\n\nAdvertisement\nAdvertisement cookies are used to provide visitors with customised advertisements based on the pages you visited previously and to analyse the effectiveness of the ad campaigns.\n  * Cookie\nmuc_ads\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to collect user behaviour and interaction data to optimize the website.\n\n\n  * Cookie\nguest_id_marketing\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to identify and track the website visitor.\n\n\n  * Cookie\nguest_id_ads\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to identify and track the website visitor.\n\n\n  * Cookie\npersonalization_id\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to integrate and share features for social media and also store information about how the user uses the website, for tracking and targeting.\n\n\n  * Cookie\nguest_id\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to identify and track the website visitor. It registers if a user is signed in to the Twitter platform and collects information about ad preferences.\n\n\n  * Cookie\nbcookie\n  * Duration\n1 year\n  * Description\nLinkedIn sets this cookie from LinkedIn share buttons and ad tags to recognize browser IDs.\n\n\n  * Cookie\n__Secure-ROLLOUT_TOKEN\n  * Duration\n6 months\n  * Description\nYouTube sets this cookie to manage feature rollout and experimentation. It helps Google control which new features or interface changes are shown to users as part of testing and staged rollouts, ensuring consistent experience for a given user during an experiment.\n\n\n  * Cookie\nyt.innertube::nextId\n  * Duration\nNever Expires\n  * Description\nYouTube sets this cookie to register a unique ID to store data on what videos from YouTube the user has seen.\n\n\n  * Cookie\nyt.innertube::requests\n  * Duration\nNever Expires\n  * Description\nYouTube sets this cookie to register a unique ID to store data on what videos from YouTube the user has seen.\n\n\n  * Cookie\nsession_tracker\n  * Duration\nsession\n  * Description\nThis cookie is set by the Reddit. This cookie is used to identify trusted web traffic. It also helps in adverstising on the website.\n\n\n  * Cookie\nedgebucket\n  * Duration\nsession\n  * Description\nReddit sets this cookie to save the information about a log-on Reddit user, for the purpose of advertisement recommendations and updating the content.\n\n\n  * Cookie\ndid\n  * Duration\n1 year\n  * Description\nArbor sets this cookie to show targeted ads to site visitors.This cookie expires after 2 months or 1 year.\n\n\nUncategorised\nOther uncategorised cookies are those that are being analysed and have not been classified into a category as yet.\nNo cookies to display.\nReject All Save My Preferences Accept All\nToggle Search[](https://towardsdatascience.com/)Toggle Mobile Navigation\n[](https://towardsdatascience.com/)\nPublish AI, ML & data-science insights to a global community of data professionals.\nSign in[Submit an Article](https://write.insightmediagroup.io)\n[Latest](https://towardsdatascience.com/latest/)[Editor's Picks](https://towardsdatascience.com/tag/editors-pick/)[Newsletter](https://towardsdatascience.com/tag/the-variable/)[ShipAI](https://towardsdatascience.com/shipai/)\n* * *\n[Write For TDS](https://towardsdatascience.com/submissions/)\n[LinkedIn](https://www.linkedin.com/company/towards-data-science/)[X](https://x.com/TDataScience)Toggle Search\n[Artificial Intelligence](https://towardsdatascience.com/category/artificial-intelligence/)\n# What are Query, Key, and Value in the Transformer Architecture and Why Are They Used?\nAn analysis of the intuition behind the notion of Key, Query, and Value in Transformer architecture and why is it used.\n[Ebrahim Pichka](https://towardsdatascience.com/author/ebrahimpichka/)\nOctober 5, 202310 min read\n![Image by author - generated by Midjourney](https://assets.insightmediagroup.io/media/wp-content/uploads/2023/10/1xRE203HLy8MQj5WsOUu92w.png)\nImage by author - generated by [**Midjourney**](https://www.midjourney.com/)\n## Introduction\nRecent years have seen the Transformer architecture make waves in the field of natural language processing (NLP), achieving state-of-the-art results in a variety of tasks including machine translation, language modeling, and text summarization, as well as other domains of AI i.e. Vision, Speech, RL, etc.\nVaswani et al. (2017), first introduced the transformer in their paper _\"Attention Is All You Need\"_ , in which they used the self-attention mechanism without incorporating recurrent connections while the model can focus selectively on specific portions of input sequences.\n![The Transformer model architecture - Image from the Vaswani et al. \\(2017\\) paper \\(Source: arXiv:1706.03762v7\\)](https://assets.insightmediagroup.io/media/wp-content/uploads/2023/10/1gUxLBgWIh5btuQUIuZIr6g.png)\nThe Transformer model architecture - Image from the Vaswani et al. (2017) paper (Source: [**arXiv:1706.03762v7**](https://arxiv.org/abs/1706.03762v7))\nIn particular, previous sequence models, such as recurrent encoder-decoder models, were limited in their ability to capture long-term dependencies and parallel computations. In fact, right before the Transformers paper came out in 2017, state-of-the-art performance in most NLP tasks was obtained by using RNNs with an attention mechanism on top, so attention kind of existed before transformers. By introducing the multi-head attention mechanism on its own, and dropping the RNN part, the transformer architecture resolves these issues by allowing multiple independent attention mechanisms.\nIn this post, we will go over one of the details of this architecture, namely the Query, Key, and Values, and try to make sense of the intuition used behind this part.\nNote that this post assumes you are already familiar with some basic concepts in NLP and deep learning such as **embeddings** , **Linear (dense) layers** , and in general how a simple neural network works.\n* * *\n## Attention!\nFirst, let's start understanding what the attention mechanism is trying to achieve. And for the sake of simplicity, let's start with **a simple case** of sequential data to understand what problem exactly we are going to solve, without going through all the jargon of the _attention mechanism_.\n### Context Matters\nConsider the case of **smoothing time-series data**. Time series are known to be one of the most basic kinds of sequential data due to the fact that it is already in a numerical and structured form, and is usually in low-dimensional space. So it would be suitable to lay out a good starting example.\nTo smooth a highly variant time series, a common technique is to calculate a \"**weighted average\"** of the proximate timesteps for each timestep, as shown in image 1, the weights are usually chosen based on how close the proximate timesteps are to our desired timestep. For instance, in Gaussian Smoothing, these weights are drawn from a Gaussian function that is centered at our current step.\n![time-series smoothing example - Image by author.](https://assets.insightmediagroup.io/media/wp-content/uploads/2023/10/18dju9CpYYss-0SLcE4Q1jA.png)\ntime-series smoothing example - Image by author.\nWhat we have done here, in a sense, is that:\n  1. We took **a sequence of values** ,\n  2. And for each step of this sequence, we **added (a weighted) context** from its proximate values, while the proportion of added context (**the weight)** is only related to their **proximity** to the target value.\n  3. And finally, we attained a new **contextualized** sequence, which we can understand and analyze more easily.\n\n\n**There are two key points/issues in this example:**\n  * It only uses the **proximity** and **ordinal position** of the values to obtain the weights of the context.\n  * The weights are calculated by fixed arbitrary rules for all points.\n\n\n### The Case of Language\nIn machine learning, textual data always have to be represented by vectors of real-valued numbers AKA **Embeddings**. So we assume that the primary meanings of tokens (or words) are encoded in these vectors. Now in the case of textual sequence data, if we would like to apply the same kind of technique to **contextualize** each token of the sequence as the above example so that each token's new embedding would contain more information about its context, we would encounter some issues which we will discuss now:\nFirstly, in the example above, we **only** used the **proximity of tokens** to determine the importance (weights) of the context to be added, while **words do not work like that.** In language, the context of a word in a sentence is not based only on the ordinal distance and proximity. We can't just blindly use proximity to incorporate context from other words.\nSecondly, adding the context only by taking the (weighted) average of the embeddings of the context tokens itself may not be entirely intuitive. A token's embedding may contain information about different syntactical, semantical, or lexical aspects of that token. All of this information may not be relevant to the target token to be added. So it's better not to add all the information as a whole as context.\nSo if we have some (vector) representation of words in a sequence, **how** do we **obtain the weights** and **the relevant context** to re-weight and contextualize each token of the sequence?\n> The answer, in a broad sense, is that we have to \"**search\"** for it, based on some specific aspects of the tokens meaning (could be semantic, syntactic, or anything). And during this **search** , assign the **weights** and the **context information** based on relevance or importance.\n> It means that for each of the tokens in a sequence, we have to **go through all other tokens** in the sequence, and assign them **weights** and the **context information,** based on a similarity metric that we use to compare our target token with others. **The more similar they are in terms of the desired context, the larger the weight it gets**.\nSo, in general, we could say that the attention mechanism is basically (1) **assigning weights** to **** and (2) extracting** relevant context** from other tokens of a sequence based on their relevance or importance to a target token (i.e. attending to them).\nAnd we said that in order to find this relevance/importance we need to **search through our sequence** and compare tokens one-to-one.\n![Searching through the sequence for relevant context to a token for adding - Image by author.](https://assets.insightmediagroup.io/media/wp-content/uploads/2023/10/1QNFUN1sPvBQTWl8JXPu3Qg.png)\nSearching through the sequence for relevant context to a token for adding - Image by author.\n**This is where the** _**Query**_**,**_**Key**_**, and** _**Values**_**find meaning.**\n* * *\n##  _**Query**_**,**_**Key**_**, and** _**Value**_\nTo make more sense, think of when you search for something on YouTube, for example. Assume YouTube stores all its videos as a pair of \"_video title_ \" and the \"_video file_ \" itself. Which we call a **Key-Value pair** , with the Key being the video title and the Value being the video itself.\nThe text you put in the search box is called a **Query** in search terms. So in a sense, when you search for something, **YouTube compares your search Query with the Keys of all its videos** , then measures the similarity between them, and ranks their **Values** from the highest similarity down.\n![A basic search procedure illustrating the notion of Key, Quey, and Value - Image by author.](https://assets.insightmediagroup.io/media/wp-content/uploads/2023/10/1znapogqDzbOCzVAYi3QT3g.png)\nA basic search procedure illustrating the notion of Key, Quey, and Value - Image by author.\nIn our problem, we have a sequence of token vectors, and we want to search for **the weights** to re-weight and contextualize each token (word) embedding of the sequence, we can think in terms of:\n  1. What you want to look for is the **Query**.\n  2. What you are searching among is **Key-Value** pairs.\n  3. The query is compared to all the Keys to measure the **relevance/importance/similarity**.\n  4. The **Values** are utilized based on the assigned similarity measure.\n\n\nAnother helpful relevant analogy is a dictionary (or hashmap) data structure. A dictionary stores data in key-value pairs and it maps keys to their respective value pairs. When you try to **get a specific** value from the dictionary, you have to provide a **query** to match its corresponding **key** , then it **searches among those keys** , **compares them with the query** , and **if matched** , the desired value will be returned.\nHowever, the difference here is that this is a \"hard-matching\" case, where the Query either **exactly matches** the Key or it doesn't and an in-between similarity is not measured between them.\n![Dictionary Query matching with Key-Value pairs - Image by author](https://assets.insightmediagroup.io/media/wp-content/uploads/2023/10/1jZl_kJXZIXoxpcaI8Q0Cjg.png)\nDictionary Query matching with Key-Value pairs - Image by author\n* * *\nWe earlier mentioned that we are only working with real-valued vectors (token embeddings). So the Query, Key, and Value also need to be vectors. However, so far we only have **one vector for each token** which is its embedding vector. So, how should we obtain the Query, Key, and Value vectors?\nWe **Construct them** using linear projections (linear transformations aka single dense layer with separate sets of weights: Wq, Wₖ, Wᵥ) of the embedding vector of each token. This means we use a **learnable** vector of weights for each of the Query, Key, and Value to do a linear transformation on the word embedding to **obtain the corresponding Query, Key, and Value vectors**.\n![Linear transformation of the word embedding to obtain Query, Key, and Value vectors - Image by author](https://assets.insightmediagroup.io/media/wp-content/uploads/2023/10/1moKYjUdtx-uEyYMbhPWbIw.png)\nLinear transformation of the word embedding to obtain Query, Key, and Value vectors - Image by author\nAn embedding of a token may represent different contextual, structural, and syntactical, aspects or meanings of that token. By using **learnable linear transformation layers** to construct these vectors from the token's embedding, we allow the network to:\n  1. **Extract** and pass a limited specific part of that information into the _**Q**_ , _**K**_ , and _**V**_ vectors.\n  2. Determine a narrower context in which the search and match is going to be done.\n  3. **Learn** what information in an embedding is more important to attend to.\n\n\nNow, having the _**Q**_ , _**K**_ , and _**V**_ vectors in hand, we are able to perform the \"**search and compare\"** procedure that was discussed before, with these vectors. This results in the final derivation of the attention mechanism proposed in the proposed in (Vaswani et al 2017).\nFor each token:\n  * We compare its **Query vector** to all other tokens' **Key vectors**.\n  * Calculate a **vector similarity** score between each two (i.e. the dot-product similarity in the original paper)\n  * Transform these similarity **scores** into **weights** by scaling them into [0,1] (i.e. Softmax)\n  * And add the weighted context by weighting their corresponding **value vectors**.\n\n\n![Dot-product attention procedure -Image by author](https://assets.insightmediagroup.io/media/wp-content/uploads/2023/10/16BEwO4jKy9UC7AzU6nIPPg.png)\nDot-product attention procedure -Image by author\nSo the whole notion of the _**Q**_ , _**K**_ , and _**V**_ vectors is like a **soft** dictionary to mimic a _**search-and-match procedure**_ from which we learn how much two tokens in a sequence are relevant (the weights), and **what should be added** as the context (the values). Also, note that this process does not have to happen sequentially (one token at a time). This all happens in parallel by using matrix operations.\nNote that in the illustration below, the matrix dimensions are switched compared to that of the original paper (_**n_tokens** _by_**dim** _instead of_**dim** _by_**n_tokens** _). Later in this post, you will see the original and complete formulation of the attention mechanism which is the other way around.\n![Matrix form of the dot-product attention - Image by author](https://assets.insightmediagroup.io/media/wp-content/uploads/2023/10/1JWcDjbb3V1TJxsXlpcNfcA.png)\nMatrix form of the dot-product attention - Image by author\nThis results in a more context-aware embedding of each token, where the added context is based on the relevance of the tokens to each other and it is learned through _**Q**_ , _**K**_ , _**V**_ vector transformation. Hence, the dot-product attention mechanism. The original attention mechanism in (Vaswani et al, 2017) also scales the dot-product of _**K**_ and _**Q**_ vectors, meaning it divides the resulting vector by _**sqrt(d)**_ , where _**d**_ is the dimension of the Query vector. Hence the name, _**\"scaled dot-product attention\"**_. This scaling helps with reducing the variance of the dot-product before being passed to the Softmax function:\n![Attention mechanism formula - Vaswani et al. \\(2017\\) \\(Source: arXiv:1706.03762v7\\)](https://assets.insightmediagroup.io/media/wp-content/uploads/2023/10/1kxcBAMTR6bd4K4PaaTsIDA.png)\nAttention mechanism formula - Vaswani et al. (2017) (Source: [**arXiv:1706.03762v7**](https://arxiv.org/abs/1706.03762v7))\nFinally, we mentioned that the linear layers that transform the embedding into _**Q**_ , _**K**_ , _**V,**_ may extract only a specific pattern in the embedding for finding the attention weights. To enable the model to learn different complex relations between the sequence tokens, create and use multiple different versions of these _**Q**_ , _**K**_ , _**V**_ , so that each will focus on different patterns existing in our embeddings. These multiple versions are called **attention heads** resulting in the name \"multi-head attention\". These heads can also be vectorized and computed in parallel using current popular deep learning frameworks.\n![Multi-head scaled dot-product attention - Image from the Vaswani et al. \\(2017\\) paper \\(Source: arXiv:1706.03762v7\\)](https://assets.insightmediagroup.io/media/wp-content/uploads/2023/10/1sQP6cxjpXZ_lxDFYYe9Vdw.png)\nMulti-head scaled dot-product attention - Image from the Vaswani et al. (2017) paper (Source: [**arXiv:1706.03762v7**](https://arxiv.org/abs/1706.03762v7))\n## Conclusion\nSo to wrap up, in this post I tried to picture and analyze the intuition behind the use of Query, Key, and Value which are key components in the attention mechanism and may be a little difficult to make sense of, at first encounters.\nThe attention mechanism discussed in this post was proposed in the transformer architecture that is introduced in the (Vaswani et al, 2017) paper \"Attention is all you need\" and has been one of the top-performing architectures since, in several different tasks and benchmarks in deep learning. With its vast use cases and applicability, it would be helpful to have an understanding of the intuition behind the nuts and bolts used in this architecture and know why we use it.\nI attempted to be as clear and as basic as possible while explaining this topic by laying down examples and illustrations wherever possible.\n## References\n[1] Vaswani, Ashish, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N. Gomez, Lukasz Kaiser, and Illia Polosukhin. \"_Attention Is All You Need._ \" arXiv, August 1, 2023. [https://doi.org/10.48550/arXiv.1706.03762](https://doi.org/10.48550/arXiv.1706.03762.).\n## Register Now to Continue Reading\n### Unlock Towards Data Science with a Free Account\nAll articles on Towards Data Science are available to registered users. Create a free account today to access this article and thousands more.\nRegister for freeSign in to your account\n* * *\n![](https://assets.insightmediagroup.io/media/1787657518176_ovfxiv.jpeg)\nWritten By\n## [Ebrahim Pichka](https://towardsdatascience.com/author/ebrahimpichka/)\n[See all from Ebrahim Pichka](https://towardsdatascience.com/author/ebrahimpichka/)\n[Artificial Intelligence](https://towardsdatascience.com/tag/artificial-intelligence/)[Deep Learning](https://towardsdatascience.com/tag/deep-learning/)[Machine Learning](https://towardsdatascience.com/tag/machine-learning/)[NLP](https://towardsdatascience.com/tag/nlp/)[Transformers](https://towardsdatascience.com/tag/transformers/)\nShare This Article\n  * [](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Ftowardsdatascience.com%2Fwhat-are-query-key-and-value-in-the-transformer-architecture-and-why-are-they-used-acbe73f731f2%2F&title=What%20are%20Query%2C%20Key%2C%20and%20Value%20in%20the%20Transformer%20Architecture%20and%20Why%20Are%20They%20Used%3F)\n  * [](https://www.linkedin.com/shareArticle?mini=true&url=https%3A%2F%2Ftowardsdatascience.com%2Fwhat-are-query-key-and-value-in-the-transformer-architecture-and-why-are-they-used-acbe73f731f2%2F&title=What%20are%20Query%2C%20Key%2C%20and%20Value%20in%20the%20Transformer%20Architecture%20and%20Why%20Are%20They%20Used%3F)\n  * [](https://x.com/share?url=https%3A%2F%2Ftowardsdatascience.com%2Fwhat-are-query-key-and-value-in-the-transformer-architecture-and-why-are-they-used-acbe73f731f2%2F&text=What%20are%20Query%2C%20Key%2C%20and%20Value%20in%20the%20Transformer%20Architecture%20and%20Why%20Are%20They%20Used%3F)\n\n\nTowards Data Science is a community publication. Submit your insights to reach our global audience and earn through the TDS Author Payment Program.\n[Write for TDS](https://towardsdatascience.com/submissions/)\n## Related Articles\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2020/11/0FG64yrHAq3Ob3ZwA-scaled.jpeg)](https://towardsdatascience.com/practical-sql-create-and-query-a-relational-database-8bac84d78703/)\n## [Practical SQL: Create and Query a Relational Database](https://towardsdatascience.com/practical-sql-create-and-query-a-relational-database-8bac84d78703/)\n[Artificial Intelligence](https://towardsdatascience.com/category/artificial-intelligence/)\nHands-on tutorial for SQL\n[Soner Yıldırım](https://towardsdatascience.com/author/sonery/)\nNovember 28, 20206 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2023/03/1PCbnNVWsqdVx-XWdeAphZA.jpg)](https://towardsdatascience.com/neural-graph-databases-cc35c9e1d04f/)\n## [Neural Graph Databases](https://towardsdatascience.com/neural-graph-databases-cc35c9e1d04f/)\n[Artificial Intelligence](https://towardsdatascience.com/category/artificial-intelligence/)\nA new milestone in graph data management\n[Michael Galkin](https://towardsdatascience.com/author/mgalkin/)\nMarch 28, 202315 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2020/09/0tq3-Ff0H1oXD_y2w.png)](https://towardsdatascience.com/must-know-ml-techniques-for-digital-analysts-part-2-customer-lifetime-value-22cd7496beca/)\n## [Must know ML techniques for digital analysts: Part 2 - Customer Lifetime Value](https://towardsdatascience.com/must-know-ml-techniques-for-digital-analysts-part-2-customer-lifetime-value-22cd7496beca/)\n[Machine Learning](https://towardsdatascience.com/category/artificial-intelligence/machine-learning/)\nIntroduction to machine learning techniques that can help you to optimize your digital analytics value chain\n[Abhinav Sharma](https://towardsdatascience.com/author/abhinavsharma_64776/)\nSeptember 16, 20209 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2022/04/1de7mGw4BS4TfcQHw5N-6lQ.jpeg)](https://towardsdatascience.com/postgres-fuzzy-search-with-pg-trgm-smart-database-guesses-what-you-want-and-returns-cat-food-4b174d9bede8/)\n## [Postgres Fuzzy Search With pg_trgm: Smart Database Guesses What You Want and Returns \"Cat Food\"...](https://towardsdatascience.com/postgres-fuzzy-search-with-pg-trgm-smart-database-guesses-what-you-want-and-returns-cat-food-4b174d9bede8/)\n[Machine Learning](https://towardsdatascience.com/category/artificial-intelligence/machine-learning/)\nIntelligent search with pg_trgm and Levenshtein distance in Postgres\n[Alina Zhang](https://towardsdatascience.com/author/alina-li-zhang/)\nApril 19, 20225 min read\n  * [![](https://assets.insightmediagroup.io/media/1788953859505_rmzjk2.webp)](https://towardsdatascience.com/stop-managing-alarms-an-incident-first-blueprint-for-telecom-aiops/)\n## [Stop Managing Alarms: An Incident-First Blueprint for Telecom AIOps](https://towardsdatascience.com/stop-managing-alarms-an-incident-first-blueprint-for-telecom-aiops/)\n[AI applications](https://towardsdatascience.com/category/artificial-intelligence/ai-applications/)\nWhat large operators can teach us about turning alert fatigue into faster, safer service assurance\n[Amir Hossein Karami](https://towardsdatascience.com/author/ah.karami.dl/)\nSeptember 12, 20267 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2022/08/0UnxbaQNZOBP0-B5H-scaled.jpg)](https://towardsdatascience.com/seven-killer-memory-optimization-techniques-every-pandas-user-should-know-64707348ab20/)\n## [Seven Killer Memory Optimization Techniques Every Pandas User Should Know](https://towardsdatascience.com/seven-killer-memory-optimization-techniques-every-pandas-user-should-know-64707348ab20/)\n[Artificial Intelligence](https://towardsdatascience.com/category/artificial-intelligence/)\nSimple tips to optimize the memory utilization in Pandas\n[Avi Chawla](https://towardsdatascience.com/author/avi_chawla/)\nAugust 22, 20229 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2021/04/0YtqkI3lw669HSsxv.png)](https://towardsdatascience.com/survival-models-for-histopathology-b26efffdba1b/)\n## [Survival Models for Histopathology](https://towardsdatascience.com/survival-models-for-histopathology-b26efffdba1b/)\n[Deep Learning](https://towardsdatascience.com/category/artificial-intelligence/deep-learning/)\nA review of machine learning techniques for predicting patient outcomes from whole slide images.\n[Heather Couture](https://towardsdatascience.com/author/hdcouture/)\nApril 12, 202117 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2021/06/17SDeYdw4LOH2n_IcZcZwxw.png)](https://towardsdatascience.com/unit-1-optimization-theory-e416dcf30ba8/)\n## [Unit 1) Optimization Theory](https://towardsdatascience.com/unit-1-optimization-theory-e416dcf30ba8/)\n[Artificial Intelligence](https://towardsdatascience.com/category/artificial-intelligence/)\nOverview of Optimization Theory and the Four main types of Optimization Problems\n[Brandon Morgan](https://towardsdatascience.com/author/morganscottbrandon/)\nJune 24, 202110 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2021/08/1EM9TykLHdedkFpzF0viVFQ.png)](https://towardsdatascience.com/how-to-use-reinforcement-learning-to-recommend-content-6d7f9171b956/)\n## [How to Use Reinforcement Learning to Recommend Content](https://towardsdatascience.com/how-to-use-reinforcement-learning-to-recommend-content-6d7f9171b956/)\n[Deep Learning](https://towardsdatascience.com/category/artificial-intelligence/deep-learning/)\nA new RL framework develop by researchers at Google.\n[Michael Berk](https://towardsdatascience.com/author/michaelberk/)\nAugust 23, 20216 min read\n\n\n  * [YouTube](https://www.youtube.com/c/TowardsDataScience)\n  * [X](https://x.com/TDataScience)\n  * [LinkedIn](https://www.linkedin.com/company/towards-data-science/)\n  * [Threads](https://www.threads.net/@towardsdatascience)\n  * [Bluesky](https://bsky.app/profile/towardsdatascience.com)\n\n\n[](https://towardsdatascience.com/)\nYour home for data science and AI. The world's leading publication for data science, data analytics, data engineering, machine learning, and artificial intelligence professionals.\nSubscribe to Our Newsletter[Write For TDS](https://towardsdatascience.com/submissions/)•[About](https://towardsdatascience.com/about-towards-data-science-d691af11cc2f/)•[Advertise](https://contact.towardsdatascience.com/advertise-with-towards-data-science)•[Privacy Policy](https://towardsdatascience.com/privacy-policy/)•[Terms of Use](https://towardsdatascience.com/website-terms-of-use/)\n© Insight Media Group, LLC 2026•[The New Stack](https://thenewstack.io)•[roadmap.sh](https://roadmap.sh)•[Creator Network](https://insightmediagroup.io/creator-network)\n####  Recommended Articles \nClose\n  * [ ![](https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/607631/image?etag=1781543525510&width=500&height=500) Critical Mistakes Companies Make When Integrating AI/ML into Their Processes ](https://towardsdatascience.com/critical-mistakes-companies-make-when-integrating-ai-ml-into-their-processes/ \"Critical Mistakes Companies Make When Integrating AI/ML into Their Processes\")\n  * [ ![](https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/607686/image?etag=1782161464448&width=500&height=500) How Relevance Models Foreshadowed Transformers for NLP ](https://towardsdatascience.com/how-relevance-models-foreshadowed-transformers-for-nlp/ \"How Relevance Models Foreshadowed Transformers for NLP\")\n  * [ ![](https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/607639/image?etag=1781250125848&width=500&height=500) Javascript Fatigue: HTMX Is All You Need to Build ChatGPT — Part 1 ](https://towardsdatascience.com/javascript-fatigue-you-dont-need-js-to-build-chatgpt/ \"Javascript Fatigue: HTMX Is All You Need to Build ChatGPT — Part 1\")\n  * [ ![](https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/607930/image?etag=1782124566054&width=500&height=500) The Subset Sum Problem Solved in Linear Time for Dense Enough Inputs ](https://towardsdatascience.com/subset-sum-problem-solved-in-linear-time-for-dense-enough-inputs/ \"The Subset Sum Problem Solved in Linear Time for Dense Enough Inputs\")\n\n\n",
  "metadata": {
    "title": "What are Query, Key, and Value in the Transformer Architecture and Why Are They Used? | Towards Data Science",
    "description": "An analysis of the intuition behind the notion of Key, Query, and Value in Transformer architecture and why is it used.",
    "keywords": null,
    "author": "Ebrahim Pichka",
    "og:locale": "en_US",
    "og:type": "article",
    "og:title": "What are Query, Key, and Value in the Transformer Architecture and Why Are They Used?",
    "og:description": "An analysis of the intuition behind the notion of Key, Query, and Value in Transformer architecture and why is it used.",
    "og:url": "https://towardsdatascience.com/what-are-query-key-and-value-in-the-transformer-architecture-and-why-are-they-used-acbe73f731f2/",
    "og:site_name": "Towards Data Science",
    "og:image": "https://assets.insightmediagroup.io/media/wp-content/uploads/2023/10/1xRE203HLy8MQj5WsOUu92w.png",
    "og:image:width": "1024",
    "og:image:height": "1024",
    "og:image:type": "image/png",
    "twitter:card": "summary_large_image",
    "twitter:site": "@TDataScience",
    "twitter:creator": "@TDataScience",
    "twitter:label1": "Written by",
    "twitter:data1": "Ebrahim Pichka",
    "twitter:label2": "Est. reading time",
    "twitter:data2": "10 min read",
    "article:published_time": "2023-10-05T00:57:05.000Z",
    "article:modified_time": "2023-10-05T00:57:05.000Z",
    "article:author": "https://towardsdatascience.com/author/ebrahimpichka/"
  },
  "paywall": {
    "listed_paid": true,
    "detected": false,
    "marker": "",
    "public_only": true,
    "policy": "付费/会员内容只保留页面公开可见部分，不绕过付费墙"
  },
  "crawl": {
    "success": true,
    "status_code": 200,
    "error": ""
  },
  "code_blocks": [],
  "images": [
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2023/10/1xRE203HLy8MQj5WsOUu92w.png",
      "alt": "Image by author - generated by Midjourney",
      "local_path": "attachments/796d155eca9c/images/000.png",
      "bytes": 1695140,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2023/10/1gUxLBgWIh5btuQUIuZIr6g.png",
      "alt": "The Transformer model architecture - Image from the Vaswani et al. (2017) paper (Source: arXiv:1706.03762v7)",
      "local_path": "attachments/796d155eca9c/images/001.png",
      "bytes": 70242,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2023/10/18dju9CpYYss-0SLcE4Q1jA.png",
      "alt": "time-series smoothing example - Image by author.",
      "local_path": "attachments/796d155eca9c/images/002.png",
      "bytes": 22118,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2023/10/1QNFUN1sPvBQTWl8JXPu3Qg.png",
      "alt": "Searching through the sequence for relevant context to a token for adding - Image by author.",
      "local_path": "attachments/796d155eca9c/images/003.png",
      "bytes": 43787,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2023/10/1znapogqDzbOCzVAYi3QT3g.png",
      "alt": "A basic search procedure illustrating the notion of Key, Quey, and Value - Image by author.",
      "local_path": "attachments/796d155eca9c/images/004.png",
      "bytes": 54465,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2023/10/1jZl_kJXZIXoxpcaI8Q0Cjg.png",
      "alt": "Dictionary Query matching with Key-Value pairs - Image by author",
      "local_path": "attachments/796d155eca9c/images/005.png",
      "bytes": 20757,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2023/10/1moKYjUdtx-uEyYMbhPWbIw.png",
      "alt": "Linear transformation of the word embedding to obtain Query, Key, and Value vectors - Image by author",
      "local_path": "attachments/796d155eca9c/images/006.png",
      "bytes": 39948,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2023/10/16BEwO4jKy9UC7AzU6nIPPg.png",
      "alt": "Dot-product attention procedure -Image by author",
      "local_path": "attachments/796d155eca9c/images/007.png",
      "bytes": 35188,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2023/10/1JWcDjbb3V1TJxsXlpcNfcA.png",
      "alt": "Matrix form of the dot-product attention - Image by author",
      "local_path": "attachments/796d155eca9c/images/008.png",
      "bytes": 17932,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2023/10/1kxcBAMTR6bd4K4PaaTsIDA.png",
      "alt": "Attention mechanism formula - Vaswani et al. (2017) (Source: arXiv:1706.03762v7)",
      "local_path": "attachments/796d155eca9c/images/009.png",
      "bytes": 7722,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2023/10/1sQP6cxjpXZ_lxDFYYe9Vdw.png",
      "alt": "Multi-head scaled dot-product attention - Image from the Vaswani et al. (2017) paper (Source: arXiv:1706.03762v7)",
      "local_path": "attachments/796d155eca9c/images/010.png",
      "bytes": 54554,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2020/11/0FG64yrHAq3Ob3ZwA-scaled.jpeg",
      "alt": "",
      "local_path": "attachments/796d155eca9c/images/011.jpeg",
      "bytes": 588961,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2023/03/1PCbnNVWsqdVx-XWdeAphZA.jpg",
      "alt": "",
      "local_path": "attachments/796d155eca9c/images/012.jpg",
      "bytes": 210768,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2020/09/0tq3-Ff0H1oXD_y2w.png",
      "alt": "",
      "local_path": "attachments/796d155eca9c/images/013.png",
      "bytes": 80730,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2022/04/1de7mGw4BS4TfcQHw5N-6lQ.jpeg",
      "alt": "",
      "local_path": "attachments/796d155eca9c/images/014.jpeg",
      "bytes": 50630,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/1788953859505_rmzjk2.webp",
      "alt": "",
      "local_path": "attachments/796d155eca9c/images/015.webp",
      "bytes": 234080,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2022/08/0UnxbaQNZOBP0-B5H-scaled.jpg",
      "alt": "",
      "local_path": "attachments/796d155eca9c/images/016.jpg",
      "bytes": 468262,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2021/04/0YtqkI3lw669HSsxv.png",
      "alt": "",
      "local_path": "attachments/796d155eca9c/images/017.png",
      "bytes": 148272,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2021/06/17SDeYdw4LOH2n_IcZcZwxw.png",
      "alt": "",
      "local_path": "attachments/796d155eca9c/images/018.png",
      "bytes": 4412,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2021/08/1EM9TykLHdedkFpzF0viVFQ.png",
      "alt": "",
      "local_path": "attachments/796d155eca9c/images/019.png",
      "bytes": 46391,
      "downloaded": true
    }
  ],
  "audio": [],
  "videos": [
    {
      "src": "https://www.youtube.com/c/TowardsDataScience",
      "quality": "unavailable",
      "local_path": "",
      "note": "无1080p且无720p，未交付更低清晰度"
    }
  ],
  "links": [
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/latest/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/editors-pick/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/the-variable/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/shipai/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/submissions/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/category/artificial-intelligence/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/author/ebrahimpichka/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/artificial-intelligence/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/deep-learning/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/machine-learning/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/nlp/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/transformers/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/practical-sql-create-and-query-a-relational-database-8bac84d78703/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/author/sonery/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/neural-graph-databases-cc35c9e1d04f/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/author/mgalkin/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/must-know-ml-techniques-for-digital-analysts-part-2-customer-lifetime-value-22cd7496beca/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/category/artificial-intelligence/machine-learning/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/author/abhinavsharma_64776/"
    },
    {
      "type": "external",
      "href": "https://write.insightmediagroup.io"
    },
    {
      "type": "external",
      "href": "https://www.linkedin.com/company/towards-data-science/"
    },
    {
      "type": "external",
      "href": "https://x.com/TDataScience"
    },
    {
      "type": "external",
      "href": "https://www.midjourney.com/"
    },
    {
      "type": "external",
      "href": "https://arxiv.org/abs/1706.03762v7"
    },
    {
      "type": "external",
      "href": "https://doi.org/10.48550/arXiv.1706.03762."
    },
    {
      "type": "external",
      "href": "https://www.facebook.com/sharer/sharer.php?title=What+are+Query%2C+Key%2C+and+Value+in+the+Transformer+Architecture+and+Why+Are+They+Used%3F&u=https%3A%2F%2Ftowardsdatascience.com%2Fwhat-are-query-key-and-value-in-the-transformer-architecture-and-why-are-they-used-acbe73f731f2%2F"
    },
    {
      "type": "external",
      "href": "https://www.linkedin.com/shareArticle?mini=true&title=What+are+Query%2C+Key%2C+and+Value+in+the+Transformer+Architecture+and+Why+Are+They+Used%3F&url=https%3A%2F%2Ftowardsdatascience.com%2Fwhat-are-query-key-and-value-in-the-transformer-architecture-and-why-are-they-used-acbe73f731f2%2F"
    },
    {
      "type": "external",
      "href": "https://x.com/share?text=What+are+Query%2C+Key%2C+and+Value+in+the+Transformer+Architecture+and+Why+Are+They+Used%3F&url=https%3A%2F%2Ftowardsdatascience.com%2Fwhat-are-query-key-and-value-in-the-transformer-architecture-and-why-are-they-used-acbe73f731f2%2F"
    },
    {
      "type": "external",
      "href": "https://www.youtube.com/c/TowardsDataScience"
    },
    {
      "type": "external",
      "href": "https://www.threads.net/@towardsdatascience"
    },
    {
      "type": "external",
      "href": "https://bsky.app/profile/towardsdatascience.com"
    },
    {
      "type": "external",
      "href": "https://thenewstack.io"
    },
    {
      "type": "external",
      "href": "https://roadmap.sh"
    },
    {
      "type": "external",
      "href": "https://insightmediagroup.io/creator-network"
    }
  ],
  "repair_version": 2,
  "repaired_at": "2026-10-14T11:11:49Z",
  "source_url": "https://towardsdatascience.com/what-are-query-key-and-value-in-the-transformer-architecture-and-why-are-they-used-acbe73f731f2/",
  "delivery_status": "excluded_paid",
  "discovery_status": "excluded_paid",
  "missing_reason": "按原约定排除付费/会员全文"
}