{"id":499109,"date":"2026-10-18T13:56:56","date_gmt":"2026-10-18T10:56:56","guid":{"rendered":"https:\/\/savepearlharbor.com\/?p=499109"},"modified":"2026-10-18T13:56:56","modified_gmt":"2026-10-18T10:56:56","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=499109","title":{"rendered":"\u041a\u0430\u043a \u0443\u0441\u0442\u0440\u043e\u0435\u043d\u0430 decision-\u043c\u043e\u0434\u0435\u043b\u044c Clef: \u0440\u0430\u0437\u0431\u043e\u0440 \u043c\u043e\u0434\u0435\u043b\u0438 \u043f\u0440\u0438\u043d\u044f\u0442\u0438\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u0439"},"content":{"rendered":"<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440! \u041d\u0430 \u0444\u043e\u043d\u0435 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u043e\u0441\u0442\u0438 decision-\u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u043c\u043d\u0435 \u0437\u0430\u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u043f\u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u044c\u0441\u044f \u0441 \u0438\u0445 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u043e\u043c \u0440\u0430\u0431\u043e\u0442\u044b. \u041e\u0431\u044a\u0435\u043a\u0442\u043e\u043c \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044f \u044f \u0432\u044b\u0431\u0440\u0430\u043b \u043c\u043e\u0434\u0435\u043b\u044c Clef \u043e\u0442 Cloudflare \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u043e\u043d\u0430 \u0431\u043e\u043b\u044c\u0448\u0435 \u0432\u0441\u0435\u0433\u043e \u043d\u0430 \u0441\u043b\u0443\u0445\u0443.<\/p>\n<p>\u0421\u0442\u0430\u0442\u044c\u044f \u043d\u043e\u0441\u0438\u0442 \u043f\u043e\u0437\u043d\u0430\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440 \u0438 \u0431\u0443\u0434\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0430 \u0442\u0435\u043c, \u043a\u0442\u043e, \u043a\u0430\u043a \u0438 \u044f, \u0437\u0430\u0445\u043e\u0447\u0435\u0442 \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u0432 \u0440\u0430\u0431\u043e\u0442\u0435 \u043c\u043e\u0434\u0435\u043b\u0438. \u0424\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u044b \u043a\u043e\u0434\u0430 \u0438 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u0432\u0437\u044f\u0442\u044b \u0438\u0437 <a href=\"https:\/\/huggingface.co\/Cloudflare\/clef\" rel=\"noopener nofollow\">\u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f<\/a> \u0430\u0432\u0442\u043e\u0440\u043e\u0432.<\/p>\n<p>\u041f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c!<\/p>\n<h3>\u041e\u0431\u0449\u0430\u044f \u0441\u0445\u0435\u043c\u0430 \u0438 \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f<\/h3>\n<figure class=\"full-width \"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/extt\/76\/ff\/34\/76ff34232c9cc095c2c5674ab98b04d2.png\" width=\"2360\" height=\"2482\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/extt\/76\/ff\/34\/76ff34232c9cc095c2c5674ab98b04d2.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/extt\/76\/ff\/34\/76ff34232c9cc095c2c5674ab98b04d2.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<th data-colwidth=\"183\" width=\"183\">\n<p align=\"left\">\u0421\u0438\u043c\u0432\u043e\u043b<\/p>\n<\/th>\n<th>\n<p align=\"left\">\u0417\u043d\u0430\u0447\u0435\u043d\u0438\u0435<\/p>\n<\/th>\n<\/tr>\n<tr>\n<td data-colwidth=\"183\" width=\"183\">\n<p align=\"left\"><img decoding=\"async\" class=\"formula inline\" source=\"N\" alt=\"N\" src=\"https:\/\/habrastorage.org\/extt\/8f\/8c\/19\/8f8c1939b9683684f3a117468e366ee8.svg\" width=\"17\" height=\"13\" data-width=\"2.009\" data-height=\"1.545\" style=\"width: 2.009ex; height: 1.545ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/8f\/8c\/19\/8f8c1939b9683684f3a117468e366ee8.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/8f\/8c\/19\/8f8c1939b9683684f3a117468e366ee8.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0447\u0438\u0441\u043b\u043e \u0442\u043e\u043a\u0435\u043d\u043e\u0432 \u0432 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"183\" width=\"183\">\n<p align=\"left\"><img decoding=\"async\" class=\"formula inline\" source=\"d\" alt=\"d\" src=\"https:\/\/habrastorage.org\/extt\/17\/5e\/2a\/175e2a887fa7bb5fa5055dea40c1b8b7.svg\" width=\"10\" height=\"13\" data-width=\"1.176\" data-height=\"1.593\" data-vertical-align=\"-0.023\" style=\"width: 1.176ex; height: 1.593ex; vertical-align: -0.023ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/17\/5e\/2a\/175e2a887fa7bb5fa5055dea40c1b8b7.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/17\/5e\/2a\/175e2a887fa7bb5fa5055dea40c1b8b7.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0440\u0430\u0437\u043c\u0435\u0440 \u0441\u043a\u0440\u044b\u0442\u043e\u0433\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f Qwen<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"183\" width=\"183\">\n<p align=\"left\"><img decoding=\"async\" class=\"formula inline\" source=\"w\" alt=\"w\" src=\"https:\/\/habrastorage.org\/extt\/d7\/91\/ea\/d791ea08918a8d30a8659ec2945f45bf.svg\" width=\"14\" height=\"9\" data-width=\"1.62\" data-height=\"1.027\" data-vertical-align=\"-0.025\" style=\"width: 1.62ex; height: 1.027ex; vertical-align: -0.025ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/d7\/91\/ea\/d791ea08918a8d30a8659ec2945f45bf.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/d7\/91\/ea\/d791ea08918a8d30a8659ec2945f45bf.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0448\u0438\u0440\u0438\u043d\u0430 \u0433\u043e\u043b\u043e\u0432\u044b<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"183\" width=\"183\">\n<p align=\"left\"><img decoding=\"async\" class=\"formula inline\" source=\"K\" alt=\"K\" src=\"https:\/\/habrastorage.org\/extt\/ad\/1e\/6c\/ad1e6cc49f58c597b0c1884947132b46.svg\" width=\"17\" height=\"13\" data-width=\"2.011\" data-height=\"1.545\" style=\"width: 2.011ex; height: 1.545ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/ad\/1e\/6c\/ad1e6cc49f58c597b0c1884947132b46.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/ad\/1e\/6c\/ad1e6cc49f58c597b0c1884947132b46.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0447\u0438\u0441\u043b\u043e \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"183\" width=\"183\">\n<p align=\"left\"><img decoding=\"async\" class=\"formula inline\" source=\"n_k\" alt=\"n_k\" src=\"https:\/\/habrastorage.org\/extt\/ea\/77\/cf\/ea77cf0b2a24cf5c0ab61972a1f39519.svg\" width=\"20\" height=\"11\" data-width=\"2.379\" data-height=\"1.357\" data-vertical-align=\"-0.357\" style=\"width: 2.379ex; height: 1.357ex; vertical-align: -0.357ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/ea\/77\/cf\/ea77cf0b2a24cf5c0ab61972a1f39519.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/ea\/77\/cf\/ea77cf0b2a24cf5c0ab61972a1f39519.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0447\u0438\u0441\u043b\u043e \u043e\u043f\u0446\u0438\u0439 \u0443 \u0432\u043e\u043f\u0440\u043e\u0441\u0430 <img decoding=\"async\" class=\"formula inline\" source=\"k\" alt=\"k\" src=\"https:\/\/habrastorage.org\/extt\/20\/b0\/13\/20b01358d5396bbc78a05035dab81e94.svg\" width=\"10\" height=\"13\" data-width=\"1.179\" data-height=\"1.595\" data-vertical-align=\"-0.025\" style=\"width: 1.179ex; height: 1.595ex; vertical-align: -0.025ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/20\/b0\/13\/20b01358d5396bbc78a05035dab81e94.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/20\/b0\/13\/20b01358d5396bbc78a05035dab81e94.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"183\" width=\"183\">\n<p align=\"left\"><img decoding=\"async\" class=\"formula inline\" source=\"M=\\sum_k n_k\" alt=\"M=\\sum_k n_k\" src=\"https:\/\/habrastorage.org\/extt\/fa\/10\/80\/fa108087539fe4f3e3d4438028441286.svg\" width=\"96\" height=\"41\" data-width=\"11.418\" data-height=\"4.899\" data-vertical-align=\"-2.75\" style=\"width: 11.418ex; height: 4.899ex; vertical-align: -2.75ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/fa\/10\/80\/fa108087539fe4f3e3d4438028441286.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/fa\/10\/80\/fa108087539fe4f3e3d4438028441286.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0432\u0441\u0435\u0433\u043e \u043e\u043f\u0446\u0438\u0439<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"183\" width=\"183\">\n<p align=\"left\"><img decoding=\"async\" class=\"formula inline\" source=\"S_k=[s_k,e_k)\" alt=\"S_k=[s_k,e_k)\" src=\"https:\/\/habrastorage.org\/extt\/bd\/19\/d0\/bd19d0fa9e127a8402d3979481e0faee.svg\" width=\"102\" height=\"19\" data-width=\"12.098\" data-height=\"2.262\" data-vertical-align=\"-0.566\" style=\"width: 12.098ex; height: 2.262ex; vertical-align: -0.566ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/bd\/19\/d0\/bd19d0fa9e127a8402d3979481e0faee.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/bd\/19\/d0\/bd19d0fa9e127a8402d3979481e0faee.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0441\u043f\u0430\u043d \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 \u0432\u043e\u043f\u0440\u043e\u0441\u0430 <img decoding=\"async\" class=\"formula inline\" source=\"k\" alt=\"k\" src=\"https:\/\/habrastorage.org\/extt\/29\/8c\/62\/298c6246d059d8ffba34a92ce88496ff.svg\" width=\"10\" height=\"13\" data-width=\"1.179\" data-height=\"1.595\" data-vertical-align=\"-0.025\" style=\"width: 1.179ex; height: 1.595ex; vertical-align: -0.025ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/29\/8c\/62\/298c6246d059d8ffba34a92ce88496ff.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/29\/8c\/62\/298c6246d059d8ffba34a92ce88496ff.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"183\" width=\"183\">\n<p align=\"left\"><img decoding=\"async\" class=\"formula inline\" source=\"O_{kj}=[a_{kj},b_{kj})\" alt=\"O_{kj}=[a_{kj},b_{kj})\" src=\"https:\/\/habrastorage.org\/extt\/7a\/ed\/c6\/7aedc68ca066737c95721b5b9bfda200.svg\" width=\"122\" height=\"20\" data-width=\"14.467\" data-height=\"2.363\" data-vertical-align=\"-0.666\" style=\"width: 14.467ex; height: 2.363ex; vertical-align: -0.666ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/7a\/ed\/c6\/7aedc68ca066737c95721b5b9bfda200.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/7a\/ed\/c6\/7aedc68ca066737c95721b5b9bfda200.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0441\u043f\u0430\u043d \u043e\u043f\u0446\u0438\u0438 <img decoding=\"async\" class=\"formula inline\" source=\"j\" alt=\"j\" src=\"https:\/\/habrastorage.org\/extt\/47\/20\/7f\/47207f7a095c9d22852a8196e27d86cf.svg\" width=\"8\" height=\"17\" data-width=\"0.932\" data-height=\"1.957\" data-vertical-align=\"-0.462\" style=\"width: 0.932ex; height: 1.957ex; vertical-align: -0.462ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/47\/20\/7f\/47207f7a095c9d22852a8196e27d86cf.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/47\/20\/7f\/47207f7a095c9d22852a8196e27d86cf.svg 781w\" loading=\"lazy\" decode=\"async\"\/> \u0432\u043e\u043f\u0440\u043e\u0441\u0430 <img decoding=\"async\" class=\"formula inline\" source=\"k\" alt=\"k\" src=\"https:\/\/habrastorage.org\/extt\/88\/9e\/ca\/889eca301b33558a9c0826444b09dc43.svg\" width=\"10\" height=\"13\" data-width=\"1.179\" data-height=\"1.595\" data-vertical-align=\"-0.025\" style=\"width: 1.179ex; height: 1.595ex; vertical-align: -0.025ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/88\/9e\/ca\/889eca301b33558a9c0826444b09dc43.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/88\/9e\/ca\/889eca301b33558a9c0826444b09dc43.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"183\" width=\"183\">\n<p align=\"left\"><img decoding=\"async\" class=\"formula inline\" source=\"\\tilde H\" alt=\"\\tilde H\" src=\"https:\/\/habrastorage.org\/extt\/fa\/f2\/60\/faf2607f3844fea3b1f2fde0bb83dd1e.svg\" width=\"17\" height=\"19\" data-width=\"2.009\" data-height=\"2.242\" style=\"width: 2.009ex; height: 2.242ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/fa\/f2\/60\/faf2607f3844fea3b1f2fde0bb83dd1e.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/fa\/f2\/60\/faf2607f3844fea3b1f2fde0bb83dd1e.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0432\u044b\u0445\u043e\u0434 Qwen \u043f\u043e\u0441\u043b\u0435 LayerNorm \u0433\u043e\u043b\u043e\u0432\u044b, <img decoding=\"async\" class=\"formula inline\" source=\"[N\\times d]\" alt=\"[N\\times d]\" src=\"https:\/\/habrastorage.org\/extt\/9b\/8a\/30\/9b8a30fa6d211d264c5bebcc8508828e.svg\" width=\"61\" height=\"19\" data-width=\"7.209\" data-height=\"2.262\" data-vertical-align=\"-0.566\" style=\"width: 7.209ex; height: 2.262ex; vertical-align: -0.566ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/9b\/8a\/30\/9b8a30fa6d211d264c5bebcc8508828e.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/9b\/8a\/30\/9b8a30fa6d211d264c5bebcc8508828e.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"183\" width=\"183\">\n<p align=\"left\"><img decoding=\"async\" class=\"formula inline\" source=\"E\\in\\mathbb{R}^{V\\times d}\" alt=\"E\\in\\mathbb{R}^{V\\times d}\" src=\"https:\/\/habrastorage.org\/extt\/b7\/27\/56\/b72756cdd56422f8ede8777ac67e9057.svg\" width=\"81\" height=\"18\" data-width=\"9.623\" data-height=\"2.135\" data-vertical-align=\"-0.09\" style=\"width: 9.623ex; height: 2.135ex; vertical-align: -0.09ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/b7\/27\/56\/b72756cdd56422f8ede8777ac67e9057.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/b7\/27\/56\/b72756cdd56422f8ede8777ac67e9057.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u043c\u0430\u0442\u0440\u0438\u0446\u0430 <code>lm_head<\/code> Qwen<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"183\" width=\"183\">\n<p align=\"left\"><img decoding=\"async\" class=\"formula inline\" source=\"x_t\" alt=\"x_t\" src=\"https:\/\/habrastorage.org\/extt\/5f\/84\/46\/5f844613aa10eedc3881ac6ae5730610.svg\" width=\"17\" height=\"11\" data-width=\"2.059\" data-height=\"1.357\" data-vertical-align=\"-0.357\" style=\"width: 2.059ex; height: 1.357ex; vertical-align: -0.357ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/5f\/84\/46\/5f844613aa10eedc3881ac6ae5730610.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/5f\/84\/46\/5f844613aa10eedc3881ac6ae5730610.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u043d\u043e\u043c\u0435\u0440 \u0442\u043e\u043a\u0435\u043d\u0430 \u0432 \u043f\u043e\u0437\u0438\u0446\u0438\u0438 <img decoding=\"async\" class=\"formula inline\" source=\"t\" alt=\"t\" src=\"https:\/\/habrastorage.org\/extt\/c2\/70\/f8\/c270f8530dda10daebb56628932abb24.svg\" width=\"7\" height=\"12\" data-width=\"0.817\" data-height=\"1.441\" data-vertical-align=\"-0.025\" style=\"width: 0.817ex; height: 1.441ex; vertical-align: -0.025ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/c2\/70\/f8\/c270f8530dda10daebb56628932abb24.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/c2\/70\/f8\/c270f8530dda10daebb56628932abb24.svg 781w\" loading=\"lazy\" decode=\"async\"\/> (<code>input_ids[t]<\/code>)<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<h3>\u0412\u0445\u043e\u0434: \u0437\u0430\u043f\u0440\u043e\u0441 API<\/h3>\n<p>\u0417\u0430\u043f\u0440\u043e\u0441 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 <strong>state<\/strong> (\u043e \u0447\u0451\u043c \u0440\u0435\u0448\u0430\u0435\u043c) \u0438 <strong>questions<\/strong> (\u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0440\u0435\u0448\u0438\u0442\u044c). \u041f\u0440\u0438\u043c\u0435\u0440 \u043e\u0442 Cloudflare:<\/p>\n<pre><code class=\"json\">{  \"model\": \"clef\",  \"state\": \"Checkout has been failing for every customer for the last hour.\",  \"questions\": {    \"urgent\": { \"type\": \"noul\", \"instructions\": \"Is this support request urgent?\" },    \"team\": {      \"type\": \"choice\",      \"instructions\": \"Which team should handle this request?\",      \"criteria\": {        \"billing\": \"Payments, invoices, and refunds\",        \"technical\": \"Outages, errors, and configuration\",        \"sales\": \"Plans and upgrades\"      }    },    \"severity\": {      \"type\": \"score\",      \"instructions\": \"How severe is the customer impact?\",      \"criteria\": [\"No impact\", \"Minor\", \"Major\", \"Critical\"]    }  }}<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><span class=\"sc-logo-wrapper\"><\/span><\/a><\/div><\/pre>\n<h4>\u0422\u0438\u043f\u044b \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432<\/h4>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<th data-colwidth=\"96\" width=\"96\">\n<p align=\"left\">\u0422\u0438\u043f<\/p>\n<\/th>\n<th data-colwidth=\"163\" width=\"163\">\n<p align=\"left\">\u0421\u043c\u044b\u0441\u043b<\/p>\n<\/th>\n<th data-colwidth=\"302\" width=\"302\">\n<p align=\"left\">\u041e\u0442\u043a\u0443\u0434\u0430 \u0431\u0435\u0440\u0443\u0442\u0441\u044f \u043e\u043f\u0446\u0438\u0438<\/p>\n<\/th>\n<th>\n<p align=\"left\">\u041e\u043f\u0446\u0438\u0439 \u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u0435<\/p>\n<\/th>\n<\/tr>\n<tr>\n<td data-colwidth=\"96\" width=\"96\">\n<p align=\"left\"><code>noul<\/code><\/p>\n<\/td>\n<td data-colwidth=\"163\" width=\"163\">\n<p align=\"left\">\u0434\u0430 \/ \u043d\u0435\u0442<\/p>\n<\/td>\n<td data-colwidth=\"302\" width=\"302\">\n<p align=\"left\">\u0441\u043e\u0437\u0434\u0430\u044e\u0442\u0441\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438: <code>true<\/code>, <code>false<\/code><\/p>\n<\/td>\n<td>\n<p align=\"center\">2<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"96\" width=\"96\">\n<p align=\"left\"><code>choice<\/code><\/p>\n<\/td>\n<td data-colwidth=\"163\" width=\"163\">\n<p align=\"left\">\u043e\u0434\u0438\u043d \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0438\u0437 \u0441\u043f\u0438\u0441\u043a\u0430<\/p>\n<\/td>\n<td data-colwidth=\"302\" width=\"302\">\n<p align=\"left\">\u043a\u043b\u044e\u0447\u0438 <code>criteria<\/code>, \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043f\u043e \u0430\u043b\u0444\u0430\u0432\u0438\u0442\u0443<\/p>\n<\/td>\n<td>\n<p align=\"center\">3<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"96\" width=\"96\">\n<p align=\"left\"><code>score<\/code><\/p>\n<\/td>\n<td data-colwidth=\"163\" width=\"163\">\n<p align=\"left\">\u0443\u0440\u043e\u0432\u0435\u043d\u044c \u043d\u0430 \u0448\u043a\u0430\u043b\u0435<\/p>\n<\/td>\n<td data-colwidth=\"302\" width=\"302\">\n<p align=\"left\">\u0438\u043d\u0434\u0435\u043a\u0441\u044b \u0441\u043f\u0438\u0441\u043a\u0430 <code>criteria<\/code>: <code>\"0\"<\/code>, <code>\"1\"<\/code>, \u2026<\/p>\n<\/td>\n<td>\n<p align=\"center\">4<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<h4>\u041a\u0430\u043a \u0432\u043e\u043f\u0440\u043e\u0441 \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0432 \u0441\u043f\u0438\u0441\u043e\u043a \u043e\u043f\u0446\u0438\u0439<\/h4>\n<p>\u041a\u043e\u0434 \u0438\u0437 <code>joint_schema_model.py<\/code>:<\/p>\n<pre><code class=\"python\">QUESTION_TYPES = {\"noul\": 0, \"choice\": 1, \"score\": 2}def question_options(question: dict[str, Any]) -&gt; list[tuple[str, Any]]:    question_type = str(question[\"type\"])    if question_type == \"noul\":        criteria = {            \"true\": \"The proposition is true or the answer is yes.\",            \"false\": \"The proposition is false or the answer is no.\",        }        criteria.update(question.get(\"criteria\") or {})        return [(key, criteria[key]) for key in (\"true\", \"false\")]    if question_type == \"choice\":        return sorted((str(key), value) for key, value in question[\"criteria\"].items())    return [(str(index), value) for index, value in enumerate(question[\"criteria\"])]<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><span class=\"sc-logo-wrapper icon-only\"><\/span><\/a><\/div><\/pre>\n<p>\u0414\u043b\u044f <code>team<\/code> \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043f\u043e ID \u0441\u043f\u0438\u0441\u043e\u043a:<\/p>\n<pre><code class=\"python\">[(\"billing\",   \"Payments, invoices, and refunds\"), (\"sales\",     \"Plans and upgrades\"), (\"technical\", \"Outages, errors, and configuration\")]<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><span class=\"sc-logo-wrapper icon-only\"><\/span><\/a><\/div><\/pre>\n<h3>\u042d\u0442\u0430\u043f 1. encode_record: \u0437\u0430\u043f\u0440\u043e\u0441 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0442\u0435\u043a\u0441\u0442\u043e\u043c<\/h3>\n<figure class=\"full-width \"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/extt\/1c\/46\/32\/1c4632712deb535d6dc02612fa60656a.png\" width=\"2360\" height=\"2482\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/extt\/1c\/46\/32\/1c4632712deb535d6dc02612fa60656a.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/extt\/1c\/46\/32\/1c4632712deb535d6dc02612fa60656a.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<p><code>encode_record<\/code> \u0441\u043a\u043b\u0435\u0438\u0432\u0430\u0435\u0442 \u0432\u0441\u0435 \u043f\u043e\u043b\u044f JSON \u0432 \u043e\u0434\u0438\u043d \u043f\u0440\u043e\u043c\u043f\u0442 \u0438 \u043f\u043e\u043f\u0443\u0442\u043d\u043e \u0437\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u0435\u0442, \u0433\u0434\u0435 \u0432 \u043d\u0451\u043c \u043b\u0435\u0436\u0438\u0442 \u043a\u0430\u0436\u0434\u044b\u0439 \u0432\u043e\u043f\u0440\u043e\u0441 \u0438 \u043a\u0430\u0436\u0434\u0430\u044f \u043e\u043f\u0446\u0438\u044f.<\/p>\n<p>\u042d\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432 \u0442\u0440\u0438 \u0448\u0430\u0433\u0430.<\/p>\n<p><strong>\u0428\u0430\u0433 1.<\/strong> <code>question_options<\/code> \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u0442 <code>criteria<\/code> \u0432 \u0441\u043f\u0438\u0441\u043e\u043a \u043f\u0430\u0440 (\u0440\u0430\u0437\u0434\u0435\u043b 2).<\/p>\n<p><strong>\u0428\u0430\u0433 2.<\/strong> \u041a\u0430\u0436\u0434\u0430\u044f \u043f\u0430\u0440\u0430 \u0437\u0430\u0432\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u0438\u0439 \u0441\u043b\u043e\u0432\u0430\u0440\u044c:<\/p>\n<pre><code class=\"python\">semantics = {\"option_id\": option_id}if description is not None:    semantics[\"description\"] = description<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><span class=\"sc-logo-wrapper icon-only\"><\/span><\/a><\/div><\/pre>\n<p><strong>\u0428\u0430\u0433 3.<\/strong> \u0421\u043b\u043e\u0432\u0430\u0440\u044c \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0432 \u0441\u0442\u0440\u043e\u043a\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 <code>render<\/code>:<\/p>\n<pre><code class=\"python\">def render(value: Any) -&gt; str:    if isinstance(value, str):        return value    return json.dumps(        value,        ensure_ascii=False,        separators=(\",\", \":\"),        sort_keys=True,    )<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><span class=\"sc-logo-wrapper icon-only\"><\/span><\/a><\/div><\/pre>\n<p>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f:<\/p>\n<pre><code class=\"json\">{\"description\":\"Payments, invoices, and refunds\",\"option_id\":\"billing\"}<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><span class=\"sc-logo-wrapper icon-only\"><\/span><\/a><\/div><\/pre>\n<p>\u0424\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u043a\u043b\u044e\u0447\u0435\u0439 \u0438 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u043f\u0440\u043e\u0431\u0435\u043b\u043e\u0432 \u043d\u0443\u0436\u043d\u044b, \u0447\u0442\u043e\u0431\u044b \u043e\u0434\u043d\u0430 \u0438 \u0442\u0430 \u0436\u0435 \u043e\u043f\u0446\u0438\u044f \u0432\u0441\u0435\u0433\u0434\u0430 \u0434\u0430\u0432\u0430\u043b\u0430 \u043e\u0434\u043d\u0438 \u0438 \u0442\u0435 \u0436\u0435 \u0442\u043e\u043a\u0435\u043d\u044b.<\/p>\n<p><strong>\u041f\u0440\u043e\u043c\u043f\u0442 \u0446\u0435\u043b\u0438\u043a\u043e\u043c ([\u043f\u0440\u0435\u0444\u0438\u043a\u0441], [state] \u0438 \u0442.\u0434 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u044b \u0434\u043b\u044f \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e\u0441\u0442\u0438):<\/strong><\/p>\n<pre><code>[\u043f\u0440\u0435\u0444\u0438\u043a\u0441]  &lt;|im_start|&gt;system           Read the complete state and schema. Decide every field jointly. ...&lt;|im_end|&gt;           &lt;|im_start|&gt;user           STATE:[state]    Checkout has been failing for every customer for the last hour.[\u0441\u0445\u0435\u043c\u0430]           SCHEMA FIELDS:           FIELD 1           ID: urgent           TYPE: noul           INSTRUCTION: Is this support request urgent?                    \u2190 question_span           ALLOWED OPTIONS:           OPTION 1: {\"description\":\"The proposition is true or the answer is yes.\",\"option_id\":\"true\"}   \u2190 option_span           OPTION 2: {\"description\":\"The proposition is false or the answer is no.\",\"option_id\":\"false\"} \u2190 option_span           END FIELD           FIELD 2           ID: team           TYPE: choice           INSTRUCTION: Which team should handle this request?             \u2190 question_span           ALLOWED OPTIONS:           OPTION 1: {\"description\":\"Payments, invoices, and refunds\",\"option_id\":\"billing\"}           OPTION 2: {\"description\":\"Plans and upgrades\",\"option_id\":\"sales\"}           OPTION 3: {\"description\":\"Outages, errors, and configuration\",\"option_id\":\"technical\"}           END FIELD           FIELD 3           ID: severity           TYPE: score           INSTRUCTION: How severe is the customer impact?                 \u2190 question_span           ALLOWED OPTIONS:           OPTION 1: {\"description\":\"No impact\",\"option_id\":\"0\"}           OPTION 2: {\"description\":\"Minor\",\"option_id\":\"1\"}           OPTION 3: {\"description\":\"Major\",\"option_id\":\"2\"}           OPTION 4: {\"description\":\"Critical\",\"option_id\":\"3\"}           END FIELD[\u0441\u0443\u0444\u0444\u0438\u043a\u0441]  &lt;|im_end|&gt;           &lt;|im_start|&gt;assistant           &lt;think&gt;           &lt;\/think&gt;           JOINT SCHEMA DECISIONS:<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><span class=\"sc-logo-wrapper icon-only\"><\/span><\/a><\/div><\/pre>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434<\/summary>\n<div class=\"spoiler__content\">\n<p>\u041f\u043e\u0441\u043b\u0435 \u0442\u043e\u043a\u0435\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0437\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u0435\u0442 \u043f\u043e\u0437\u0438\u0446\u0438\u0438 \u0432\u00a0\u043f\u0440\u043e\u043c\u043f\u0442\u0435 \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432 \u0438 \u043e\u043f\u0446\u0438\u0439:<\/p>\n<pre><code class=\"python\">def encode_record(    tokenizer: Any,    record: dict[str, Any],    max_length: int = 16384,    max_state_tokens: int | None = None,    processor: Any | None = None,) -&gt; EncodedRecord:    schema_ids = _tokens(tokenizer, \"\\n\\nSCHEMA FIELDS:\\n\")    questions: list[EncodedQuestion] = []    for question_index, (question_id, question) in enumerate(record[\"questions\"].items()):        schema_ids.extend(            _tokens(                tokenizer,                f\"\\nFIELD {question_index + 1}\\nID: {question_id}\\nTYPE: {question['type']}\\nINSTRUCTION: \",            )        )        question_start = len(schema_ids)        instructions = question.get(\"instructions\")        if instructions is None or instructions == \"\":            instructions = str(question_id)        schema_ids.extend(_tokens(tokenizer, render(instructions)))        question_end = len(schema_ids)        schema_ids.extend(_tokens(tokenizer, \"\\nALLOWED OPTIONS:\\n\"))        option_spans: list[tuple[int, int]] = []        option_ids: list[str] = []        for option_index, (option_id, description) in enumerate(question_options(question)):            schema_ids.extend(_tokens(tokenizer, f\"OPTION {option_index + 1}: \"))            option_start = len(schema_ids)            semantics = {\"option_id\": option_id}            if description is not None:                semantics[\"description\"] = description            schema_ids.extend(_tokens(tokenizer, render(semantics)))            option_spans.append((option_start, len(schema_ids)))            option_ids.append(option_id)            schema_ids.extend(_tokens(tokenizer, \"\\n\"))        schema_ids.extend(_tokens(tokenizer, \"END FIELD\\n\"))<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><span class=\"sc-logo-wrapper icon-only\"><\/span><\/a><\/div><\/pre>\n<p>\u041a\u0430\u0436\u0434\u044b\u0439 \u043a\u0443\u0441\u043e\u043a \u0442\u043e\u043a\u0435\u043d\u0438\u0437\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u043b\u043e \u0441\u043a\u043b\u0435\u0438\u0432\u0430\u043d\u0438\u0435 (\u0435\u0441\u043b\u0438 \u0442\u043e\u043a\u0435\u043d\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u0435\u0441\u044c \u043f\u0440\u043e\u043c\u043f\u0442 \u0446\u0435\u043b\u0438\u043a\u043e\u043c, BPE \u043c\u043e\u0436\u0435\u0442 \u0441\u043a\u043b\u0435\u0438\u0442\u044c \u043a\u043e\u043d\u0435\u0446 <code>\"OPTION 1: \"<\/code> \u0441 \u043d\u0430\u0447\u0430\u043b\u043e\u043c JSON \u0432 \u043e10. \u0434\u0438\u043d \u0442\u043e\u043a\u0435\u043d)<\/p>\n<p>\u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0441\u0434\u0432\u0438\u0433 \u0432\u0441\u0435\u0439 \u0441\u0445\u0435\u043c\u044b \u043d\u0430 \u0434\u043b\u0438\u043d\u0443 \u043f\u0440\u0435\u0444\u0438\u043a\u0441\u0430 \u0438 state:<\/p>\n<pre><code class=\"python\">    schema_offset = len(prefix_ids) + len(state_ids)    shifted_questions = tuple(        EncodedQuestion(            question_id=question.question_id,            question_type=question.question_type,            question_span=(                question.question_span[0] + schema_offset,                question.question_span[1] + schema_offset,            ),            option_spans=tuple(                (start + schema_offset, end + schema_offset)                for start, end in question.option_spans            ),            option_ids=question.option_ids,        )        for question in questions    )    input_ids = tuple(prefix_ids + state_ids + schema_ids + suffix_ids)<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><span class=\"sc-logo-wrapper icon-only\"><\/span><\/a><\/div><\/pre>\n<\/div>\n<\/details>\n<h4>\u0412\u044b\u0445\u043e\u0434 \u044d\u0442\u0430\u043f\u0430<\/h4>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<th>\n<p align=\"left\">\u0412\u044b\u0445\u043e\u0434<\/p>\n<\/th>\n<th>\n<p align=\"left\">\u0420\u0430\u0437\u043c\u0435\u0440<\/p>\n<\/th>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\"><code>input_ids<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\"><img decoding=\"async\" class=\"formula inline\" source=\"N\" alt=\"N\" src=\"https:\/\/habrastorage.org\/extt\/85\/58\/ef\/8558ef55db20a6d7b536573e20348311.svg\" width=\"17\" height=\"13\" data-width=\"2.009\" data-height=\"1.545\" style=\"width: 2.009ex; height: 1.545ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/85\/58\/ef\/8558ef55db20a6d7b536573e20348311.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/85\/58\/ef\/8558ef55db20a6d7b536573e20348311.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\"><code>question_span<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\"><img decoding=\"async\" class=\"formula inline\" source=\"K = 3\" alt=\"K = 3\" src=\"https:\/\/habrastorage.org\/extt\/28\/43\/a1\/2843a1a61d3098ab57c124e4831ed8b8.svg\" width=\"52\" height=\"15\" data-width=\"6.16\" data-height=\"1.731\" data-vertical-align=\"-0.186\" style=\"width: 6.16ex; height: 1.731ex; vertical-align: -0.186ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/28\/43\/a1\/2843a1a61d3098ab57c124e4831ed8b8.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/28\/43\/a1\/2843a1a61d3098ab57c124e4831ed8b8.svg 781w\" loading=\"lazy\" decode=\"async\"\/> \u043f\u0430\u0440\u044b \u0447\u0438\u0441\u0435\u043b<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\"><code>option_spans<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\"><img decoding=\"async\" class=\"formula inline\" source=\"M = 9\" alt=\"M = 9\" src=\"https:\/\/habrastorage.org\/extt\/88\/13\/d0\/8813d0766c8d00f5b4c318043c0e20cf.svg\" width=\"55\" height=\"15\" data-width=\"6.526\" data-height=\"1.731\" data-vertical-align=\"-0.186\" style=\"width: 6.526ex; height: 1.731ex; vertical-align: -0.186ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/88\/13\/d0\/8813d0766c8d00f5b4c318043c0e20cf.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/88\/13\/d0\/8813d0766c8d00f5b4c318043c0e20cf.svg 781w\" loading=\"lazy\" decode=\"async\"\/> \u043f\u0430\u0440 \u0447\u0438\u0441\u0435\u043b, \u0441\u0433\u0440\u0443\u043f\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u043f\u043e \u0432\u043e\u043f\u0440\u043e\u0441\u0430\u043c<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\"><code>option_ids<\/code>, <code>question_type<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u043c\u0435\u0442\u0430\u0434\u0430\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u0441\u0431\u043e\u0440\u043a\u0438 \u043e\u0442\u0432\u0435\u0442\u0430<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<h3>\u042d\u0442\u0430\u043f 2. Qwen: \u043e\u0434\u0438\u043d \u043f\u0440\u043e\u0445\u043e\u0434<\/h3>\n<figure class=\"full-width \"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/extt\/67\/32\/f8\/6732f890c0a7bad6f32077e172f31c92.png\" width=\"2360\" height=\"2486\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/extt\/67\/32\/f8\/6732f890c0a7bad6f32077e172f31c92.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/extt\/67\/32\/f8\/6732f890c0a7bad6f32077e172f31c92.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<p>\u041d\u0430 \u044d\u0442\u043e\u043c \u044d\u0442\u0430\u043f\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0440\u0430\u0441\u0447\u0435\u0442 \u043f\u043e \u0432\u0441\u0435\u043c \u0441\u043b\u043e\u044f\u043c \u0431\u0435\u0437 \u0433\u043e\u043b\u043e\u0432\u044b \u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 LayerNorm \u043a \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u043c\u0443 \u0432\u044b\u0445\u043e\u0434\u043d\u043e\u043c\u0443 \u0441\u043b\u043e\u044e:<\/p>\n<p><img decoding=\"async\" class=\"formula inline\" source=\"H=\\mathrm{Qwen}(x_1,\\dots,x_N)\\in\\mathbb{R}^{N\\times d},\\qquad \\tilde H=\\mathrm{LN}_h(H)\" alt=\"H=\\mathrm{Qwen}(x_1,\\dots,x_N)\\in\\mathbb{R}^{N\\times d},\\qquad \\tilde H=\\mathrm{LN}_h(H)\" src=\"https:\/\/habrastorage.org\/extt\/40\/e2\/b2\/40e2b237996e6010cf14c4ca27df6739.svg\" width=\"417\" height=\"24\" data-width=\"49.298\" data-height=\"2.808\" data-vertical-align=\"-0.566\" style=\"width: 49.298ex; height: 2.808ex; vertical-align: -0.566ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/40\/e2\/b2\/40e2b237996e6010cf14c4ca27df6739.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/40\/e2\/b2\/40e2b237996e6010cf14c4ca27df6739.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<h4>\u0412\u044b\u0445\u043e\u0434 \u044d\u0442\u0430\u043f\u0430<\/h4>\n<p><code>last_hidden_state<\/code> <img decoding=\"async\" class=\"formula inline\" source=\"[B\\times N\\times5120] \" alt=\"[B\\times N\\times5120] \" src=\"https:\/\/habrastorage.org\/extt\/d5\/a7\/a4\/d5a7a496a729a9095b769490822ab360.svg\" width=\"127\" height=\"19\" data-width=\"15.04\" data-height=\"2.262\" data-vertical-align=\"-0.566\" style=\"width: 15.04ex; height: 2.262ex; vertical-align: -0.566ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/d5\/a7\/a4\/d5a7a496a729a9095b769490822ab360.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/d5\/a7\/a4\/d5a7a496a729a9095b769490822ab360.svg 781w\" loading=\"lazy\" decode=\"async\"\/>\u2014 \u043f\u043e \u0432\u0435\u043a\u0442\u043e\u0440\u0443 \u043d\u0430 \u043a\u0430\u0436\u0434\u044b\u0439 \u0442\u043e\u043a\u0435\u043d \u043a\u0430\u0436\u0434\u043e\u0439 \u0437\u0430\u043f\u0438\u0441\u0438 \u0431\u0430\u0442\u0447\u0430.<\/p>\n<h3>\u042d\u0442\u0430\u043f A. \u0418\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u0435 \u0432\u0435\u043a\u0442\u043e\u0440\u043e\u0432<\/h3>\n<figure class=\"full-width \"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/extt\/4b\/86\/e4\/4b86e4626e099c8fe0eb14ef2aa06020.png\" width=\"2360\" height=\"2486\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/extt\/4b\/86\/e4\/4b86e4626e099c8fe0eb14ef2aa06020.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/extt\/4b\/86\/e4\/4b86e4626e099c8fe0eb14ef2aa06020.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<p>\u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u0430\u043f\u0430 2 \u0435\u0441\u0442\u044c \u0442\u0430\u0431\u043b\u0438\u0446\u0430 <img decoding=\"async\" class=\"formula inline\" source=\"\\tilde H\" alt=\"\\tilde H\" src=\"https:\/\/habrastorage.org\/extt\/e5\/32\/a8\/e532a8279e9c7237f099e37362d46c1a.svg\" width=\"17\" height=\"19\" data-width=\"2.009\" data-height=\"2.242\" style=\"width: 2.009ex; height: 2.242ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/e5\/32\/a8\/e532a8279e9c7237f099e37362d46c1a.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/e5\/32\/a8\/e532a8279e9c7237f099e37362d46c1a.svg 781w\" loading=\"lazy\" decode=\"async\"\/>. \u041d\u043e\u043c\u0435\u0440 \u0441\u0442\u0440\u043e\u043a\u0438 \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0435\u0442 \u0441 \u043d\u043e\u043c\u0435\u0440\u043e\u043c \u0442\u043e\u043a\u0435\u043d\u0430 \u0432 <code>input_ids<\/code>. \u042d\u0442\u0430\u043f A \u0432\u044b\u0440\u0435\u0437\u0430\u0435\u0442 \u0438\u0437 \u044d\u0442\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u043d\u0443\u0436\u043d\u044b\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 (\u0441\u043f\u0430\u043d\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u044b\u043b\u0438 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u044b \u0440\u0430\u043d\u0435\u0435).<\/p>\n<pre><code>\u0441\u0442\u0440\u043e\u043a\u0430   \u0442\u043e\u043a\u0435\u043d            \u0432\u0435\u043a\u0442\u043e\u0440  0      &lt;|im_start|&gt;     [ ... ] ... 152     Which            [ ... ]  \u2510 ...                               \u251c question_span team = (152, 160) 159     ?                [ ... ]  \u2518 ... 164     {\"               [ ... ]  \u2510 165     description      [ ... ]  \u2502 ...                               \u251c option_span billing = (164, 184) 183     \"}               [ ... ]  \u2518 ... 319     :                [ ... ]  \u2190 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0442\u043e\u043a\u0435\u043d<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><span class=\"sc-logo-wrapper icon-only\"><\/span><\/a><\/div><\/pre>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">    def forward(        self,        hidden_states: torch.Tensor,        input_ids: torch.Tensor,        attention_mask: torch.Tensor,        records: list[EncodedRecord],        output_embedding_weight: torch.Tensor,    ) -&gt; list[list[torch.Tensor]]:        results: list[list[torch.Tensor]] = []        normalized_hidden = self.hidden_norm(hidden_states)        for batch_index, record in enumerate(records):            sequence_length = int(attention_mask[batch_index].sum().item())            sequence_hidden = normalized_hidden[batch_index, :sequence_length]            memory = self.memory_projection(sequence_hidden).unsqueeze(0)            global_vector = sequence_hidden[-1]            question_vectors = torch.stack(                [                    self._mean_span(sequence_hidden, question.question_span)                    for question in record.questions                ]            )            type_ids = torch.tensor(                [question.question_type for question in record.questions],                device=hidden_states.device,            )            option_contexts: list[torch.Tensor] = []            lexical_options: list[torch.Tensor] = []            option_counts = []            for question in record.questions:                context_vectors = torch.stack(                    [                        self._mean_span(sequence_hidden, span)                        for span in question.option_spans                    ]                )                lexical_vectors = []                for start, end in question.option_spans:                    token_ids = input_ids[batch_index, start:end]                    lexical_vectors.append(output_embedding_weight[token_ids].mean(dim=0))                lexical = torch.stack(lexical_vectors)                option_contexts.append(context_vectors)                lexical_options.append(lexical)                option_counts.append(len(question.option_spans))```<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><span class=\"sc-logo-wrapper icon-only\"><\/span><\/a><\/div><\/pre>\n<\/div>\n<\/details>\n<p>\u0421\u0430\u043c\u0430 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u0441\u0440\u0435\u0434\u043d\u0435\u0433\u043e \u043f\u043e \u0441\u043f\u0430\u043d\u0443:<\/p>\n<pre><code class=\"python\">    @staticmethod    def _mean_span(values: torch.Tensor, span: tuple[int, int]) -&gt; torch.Tensor:        start, end = span        return values[start:end].mean(dim=0)<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><span class=\"sc-logo-wrapper icon-only\"><\/span><\/a><\/div><\/pre>\n<p>\u0412 \u0438\u0442\u043e\u0433\u0435 \u0438\u043c\u0435\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438:<\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<th data-colwidth=\"122\" width=\"122\">\n<p align=\"left\">\u0412\u044b\u0445\u043e\u0434<\/p>\n<\/th>\n<th data-colwidth=\"250\" width=\"250\">\n<p align=\"left\">\u041a\u0430\u043a\u0438\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 \u0431\u0435\u0440\u0443\u0442\u0441\u044f<\/p>\n<\/th>\n<th data-colwidth=\"117\" width=\"117\">\n<p align=\"left\">\u0420\u0430\u0437\u043c\u0435\u0440<\/p>\n<\/th>\n<th>\n<p align=\"left\">\u0421\u043c\u044b\u0441\u043b<\/p>\n<\/th>\n<\/tr>\n<tr>\n<td data-colwidth=\"122\" width=\"122\">\n<p align=\"left\">memory <img decoding=\"async\" class=\"formula inline\" source=\"\\mathcal M\" alt=\"\\mathcal M\" src=\"https:\/\/habrastorage.org\/extt\/b7\/40\/ac\/b740acdd7fc9cad7455f5134a6b7c1e4.svg\" width=\"23\" height=\"14\" data-width=\"2.717\" data-height=\"1.708\" data-vertical-align=\"-0.113\" style=\"width: 2.717ex; height: 1.708ex; vertical-align: -0.113ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/b7\/40\/ac\/b740acdd7fc9cad7455f5134a6b7c1e4.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/b7\/40\/ac\/b740acdd7fc9cad7455f5134a6b7c1e4.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<\/td>\n<td data-colwidth=\"250\" width=\"250\">\n<p align=\"left\"> <img decoding=\"async\" class=\"formula inline\" source=\"\\tilde H\" alt=\"\\tilde H\" src=\"https:\/\/habrastorage.org\/extt\/e2\/a6\/56\/e2a65631a98c03fef5656687d1fd882e.svg\" width=\"17\" height=\"19\" data-width=\"2.009\" data-height=\"2.242\" style=\"width: 2.009ex; height: 2.242ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/e2\/a6\/56\/e2a65631a98c03fef5656687d1fd882e.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/e2\/a6\/56\/e2a65631a98c03fef5656687d1fd882e.svg 781w\" loading=\"lazy\" decode=\"async\"\/>\u0443\u043c\u043d\u043e\u0436\u0435\u043d\u043d\u0430\u044f \u043d\u0430 <img decoding=\"async\" class=\"formula inline\" source=\"W_{\\text{mem}}\" alt=\"W_{\\text{mem}}\" src=\"https:\/\/habrastorage.org\/extt\/98\/3c\/c3\/983cc3395fdeb6d11bb22ef64a0ff09b.svg\" width=\"48\" height=\"16\" data-width=\"5.699\" data-height=\"1.902\" data-vertical-align=\"-0.357\" style=\"width: 5.699ex; height: 1.902ex; vertical-align: -0.357ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/98\/3c\/c3\/983cc3395fdeb6d11bb22ef64a0ff09b.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/98\/3c\/c3\/983cc3395fdeb6d11bb22ef64a0ff09b.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<\/td>\n<td data-colwidth=\"117\" width=\"117\">\n<p align=\"left\"><img decoding=\"async\" class=\"formula inline\" source=\"[N\\times1024]\" alt=\"[N\\times1024]\" src=\"https:\/\/habrastorage.org\/extt\/7b\/10\/82\/7b1082f58414431125ea690da8c5a343.svg\" width=\"89\" height=\"19\" data-width=\"10.558\" data-height=\"2.262\" data-vertical-align=\"-0.566\" style=\"width: 10.558ex; height: 2.262ex; vertical-align: -0.566ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/7b\/10\/82\/7b1082f58414431125ea690da8c5a343.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/7b\/10\/82\/7b1082f58414431125ea690da8c5a343.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u00ab\u0431\u0430\u0437\u0430 \u0443\u043b\u0438\u043a\u00bb, \u0432\u0435\u0441\u044c \u0442\u0435\u043a\u0441\u0442<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"122\" width=\"122\">\n<p align=\"left\"><img decoding=\"async\" class=\"formula inline\" source=\"g\" alt=\"g\" src=\"https:\/\/habrastorage.org\/extt\/e0\/57\/d1\/e057d17ed8877e9db9b0f120933d8a62.svg\" width=\"9\" height=\"12\" data-width=\"1.079\" data-height=\"1.464\" data-vertical-align=\"-0.464\" style=\"width: 1.079ex; height: 1.464ex; vertical-align: -0.464ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/e0\/57\/d1\/e057d17ed8877e9db9b0f120933d8a62.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/e0\/57\/d1\/e057d17ed8877e9db9b0f120933d8a62.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<\/td>\n<td data-colwidth=\"250\" width=\"250\">\n<p align=\"left\">\u043e\u0434\u043d\u0430 \u0441\u0442\u0440\u043e\u043a\u0430<img decoding=\"async\" class=\"formula inline\" source=\" L-1\" alt=\" L-1\" src=\"https:\/\/habrastorage.org\/extt\/76\/5b\/7b\/765b7be1d3479402f33a4031db2cfeca.svg\" width=\"46\" height=\"15\" data-width=\"5.438\" data-height=\"1.731\" data-vertical-align=\"-0.186\" style=\"width: 5.438ex; height: 1.731ex; vertical-align: -0.186ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/76\/5b\/7b\/765b7be1d3479402f33a4031db2cfeca.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/76\/5b\/7b\/765b7be1d3479402f33a4031db2cfeca.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<\/td>\n<td data-colwidth=\"117\" width=\"117\">\n<p align=\"left\"><img decoding=\"async\" class=\"formula inline\" source=\"[5120]\" alt=\"[5120]\" src=\"https:\/\/habrastorage.org\/extt\/40\/13\/f6\/4013f6e5ae1749b2964d93fdafd24b4e.svg\" width=\"49\" height=\"19\" data-width=\"5.783\" data-height=\"2.262\" data-vertical-align=\"-0.566\" style=\"width: 5.783ex; height: 2.262ex; vertical-align: -0.566ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/40\/13\/f6\/4013f6e5ae1749b2964d93fdafd24b4e.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/40\/13\/f6\/4013f6e5ae1749b2964d93fdafd24b4e.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0441\u0436\u0430\u0442\u043e\u0435 \u00ab\u0432\u0441\u0451 \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u043d\u043d\u043e\u0435\u00bb<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"122\" width=\"122\">\n<p align=\"left\"><img decoding=\"async\" class=\"formula inline\" source=\"q_k\" alt=\"q_k\" src=\"https:\/\/habrastorage.org\/extt\/89\/4e\/f2\/894ef2db84c544b088b921745aa09ff4.svg\" width=\"17\" height=\"12\" data-width=\"2.03\" data-height=\"1.439\" data-vertical-align=\"-0.439\" style=\"width: 2.03ex; height: 1.439ex; vertical-align: -0.439ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/89\/4e\/f2\/894ef2db84c544b088b921745aa09ff4.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/89\/4e\/f2\/894ef2db84c544b088b921745aa09ff4.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<\/td>\n<td data-colwidth=\"250\" width=\"250\">\n<p align=\"left\">\u0441\u0442\u0440\u043e\u043a\u0438 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 \u0432\u043e\u043f\u0440\u043e\u0441\u0430<\/p>\n<\/td>\n<td data-colwidth=\"117\" width=\"117\">\n<p align=\"left\"><img decoding=\"async\" class=\"formula inline\" source=\"K\\times[5120]\" alt=\"K\\times[5120]\" src=\"https:\/\/habrastorage.org\/extt\/61\/0e\/34\/610e3416bdd92bd3a983164e35c3416f.svg\" width=\"89\" height=\"19\" data-width=\"10.56\" data-height=\"2.262\" data-vertical-align=\"-0.566\" style=\"width: 10.56ex; height: 2.262ex; vertical-align: -0.566ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/61\/0e\/34\/610e3416bdd92bd3a983164e35c3416f.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/61\/0e\/34\/610e3416bdd92bd3a983164e35c3416f.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0441\u043c\u044b\u0441\u043b \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0432\u043e\u043f\u0440\u043e\u0441\u0430<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"122\" width=\"122\">\n<p align=\"left\"><img decoding=\"async\" class=\"formula inline\" source=\"c_{kj} (ctx)\" alt=\"c_{kj} (ctx)\" src=\"https:\/\/habrastorage.org\/extt\/19\/17\/e3\/1917e335c6626bcdb44a27f4af2a3661.svg\" width=\"63\" height=\"20\" data-width=\"7.511\" data-height=\"2.363\" data-vertical-align=\"-0.666\" style=\"width: 7.511ex; height: 2.363ex; vertical-align: -0.666ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/19\/17\/e3\/1917e335c6626bcdb44a27f4af2a3661.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/19\/17\/e3\/1917e335c6626bcdb44a27f4af2a3661.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<\/td>\n<td data-colwidth=\"250\" width=\"250\">\n<p align=\"left\">\u0441\u0442\u0440\u043e\u043a\u0438 \u043e\u043f\u0446\u0438\u0438 \u0432 <img decoding=\"async\" class=\"formula inline\" source=\"\\tilde H\" alt=\"\\tilde H\" src=\"https:\/\/habrastorage.org\/extt\/5e\/77\/bd\/5e77bd2d0b97a802a28ee6cda5f1c7d8.svg\" width=\"17\" height=\"19\" data-width=\"2.009\" data-height=\"2.242\" style=\"width: 2.009ex; height: 2.242ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/5e\/77\/bd\/5e77bd2d0b97a802a28ee6cda5f1c7d8.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/5e\/77\/bd\/5e77bd2d0b97a802a28ee6cda5f1c7d8.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<\/td>\n<td data-colwidth=\"117\" width=\"117\">\n<p align=\"left\"><img decoding=\"async\" class=\"formula inline\" source=\"M\\times[5120]\" alt=\"M\\times[5120]\" src=\"https:\/\/habrastorage.org\/extt\/0f\/8a\/ff\/0f8aff01fd1178c7407c16807657ad10.svg\" width=\"92\" height=\"19\" data-width=\"10.926\" data-height=\"2.262\" data-vertical-align=\"-0.566\" style=\"width: 10.926ex; height: 2.262ex; vertical-align: -0.566ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/0f\/8a\/ff\/0f8aff01fd1178c7407c16807657ad10.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/0f\/8a\/ff\/0f8aff01fd1178c7407c16807657ad10.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u043e\u043f\u0446\u0438\u044f \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"122\" width=\"122\">\n<p align=\"left\"><img decoding=\"async\" class=\"formula inline\" source=\"\\ell_{kj} (lex)\" alt=\"\\ell_{kj} (lex)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/b\/bc\/bc7\/bc763fe94f602c2384b908e828bba64a.svg\" width=\"59\" height=\"19\" data-width=\"7.407\" data-height=\"2.363\" data-vertical-align=\"-0.616\" style=\"width: 7.407ex; height: 2.363ex; vertical-align: -0.616ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/b\/bc\/bc7\/bc763fe94f602c2384b908e828bba64a.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/b\/bc\/bc7\/bc763fe94f602c2384b908e828bba64a.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<\/td>\n<td data-colwidth=\"250\" width=\"250\">\n<p align=\"left\">\u0442\u0435 \u0436\u0435 \u043f\u043e\u0437\u0438\u0446\u0438\u0438, \u043d\u043e \u0447\u0435\u0440\u0435\u0437 <code>input_ids<\/code> \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 <code>lm_head<\/code><\/p>\n<\/td>\n<td data-colwidth=\"117\" width=\"117\">\n<p align=\"left\"><img decoding=\"async\" class=\"formula inline\" source=\"M\\times[5120]\" alt=\"M\\times[5120]\" src=\"https:\/\/habrastorage.org\/extt\/18\/32\/91\/183291a0f50208ac03953419dd5f117d.svg\" width=\"92\" height=\"19\" data-width=\"10.926\" data-height=\"2.262\" data-vertical-align=\"-0.566\" style=\"width: 10.926ex; height: 2.262ex; vertical-align: -0.566ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/18\/32\/91\/183291a0f50208ac03953419dd5f117d.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/18\/32\/91\/183291a0f50208ac03953419dd5f117d.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0441\u043b\u043e\u0432\u0430\u0440\u043d\u044b\u0439 \u0441\u043c\u044b\u0441\u043b \u0441\u043b\u043e\u0432 \u043e\u043f\u0446\u0438\u0438<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u041d\u0435\u043c\u043d\u043e\u0433\u043e \u0444\u043e\u0440\u043c\u0443\u043b:<\/p>\n<p><img decoding=\"async\" class=\"formula inline\" source=\"\\mathcal M=\\tilde HW_{\\text{mem}},\\qquad g=\\tilde H_{L-1}\" alt=\"\\mathcal M=\\tilde HW_{\\text{mem}},\\qquad g=\\tilde H_{L-1}\" src=\"https:\/\/habrastorage.org\/extt\/b9\/eb\/97\/b9eb9722c5294cac5674d0a5baedf23f.svg\" width=\"239\" height=\"23\" data-width=\"28.271\" data-height=\"2.713\" data-vertical-align=\"-0.471\" style=\"width: 28.271ex; height: 2.713ex; vertical-align: -0.471ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/b9\/eb\/97\/b9eb9722c5294cac5674d0a5baedf23f.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/b9\/eb\/97\/b9eb9722c5294cac5674d0a5baedf23f.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<p><img decoding=\"async\" class=\"formula inline\" source=\"q_k = \\frac{1}{|S_k|} \\sum_{t \\in S_k} \\tilde{H}_t, \\qquad c_{kj} = \\frac{1}{|O_{kj}|} \\sum_{t \\in O_{kj}} \\tilde{H}_t, \\qquad \\ell_{kj} = \\frac{1}{|O_{kj}|} \\sum_{t \\in O_{kj}} E x_t \" alt=\"q_k = \\frac{1}{|S_k|} \\sum_{t \\in S_k} \\tilde{H}_t, \\qquad c_{kj} = \\frac{1}{|O_{kj}|} \\sum_{t \\in O_{kj}} \\tilde{H}_t, \\qquad \\ell_{kj} = \\frac{1}{|O_{kj}|} \\sum_{t \\in O_{kj}} E x_t \" src=\"https:\/\/habrastorage.org\/extt\/32\/4a\/c4\/324ac4a481d9068252026be3f53d62b0.svg\" width=\"559\" height=\"53\" data-width=\"66.204\" data-height=\"6.255\" data-vertical-align=\"-3.219\" style=\"width: 66.204ex; height: 6.255ex; vertical-align: -3.219ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/32\/4a\/c4\/324ac4a481d9068252026be3f53d62b0.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/32\/4a\/c4\/324ac4a481d9068252026be3f53d62b0.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<details class=\"spoiler\">\n<summary>\u041f\u0440\u0438\u043c\u0435\u0440:<\/summary>\n<div class=\"spoiler__content\">\n<p><strong>\u0412\u0435\u043a\u0442\u043e\u0440 \u0432\u043e\u043f\u0440\u043e\u0441\u0430.<\/strong> \u041f\u0443\u0441\u0442\u044c <code>question_span<\/code> team = (5, 8), \u0442\u043e \u0435\u0441\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u0438 5, 6, 7:<\/p>\n<pre><code>\u0441\u0442\u0440\u043e\u043a\u0430 5  \"Which\"   [ 0.2,  1.0, -0.4,  0.6 ]\u0441\u0442\u0440\u043e\u043a\u0430 6  \"team\"    [ 0.8,  0.6,  0.0,  0.2 ]\u0441\u0442\u0440\u043e\u043a\u0430 7  \"?\"       [-0.1,  0.2,  0.4,  1.0 ]                    \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 \u0441\u0440\u0435\u0434\u043d\u0435\u0435 \u043f\u043e \u0441\u0442\u043e\u043b\u0431\u0446\u0430\u043cq_team            = [ 0.3,  0.6,  0.0,  0.6 ]<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><span class=\"sc-logo-wrapper icon-only\"><\/span><\/a><\/div><\/pre>\n<p>\u041a\u0430\u0436\u0434\u0430\u044f \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u0430 &#8212; \u0441\u0440\u0435\u0434\u043d\u0435\u0435 \u0442\u0440\u0451\u0445 \u0447\u0438\u0441\u0435\u043b \u0432 \u0441\u0442\u043e\u043b\u0431\u0446\u0435: \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, (0.2+0.8-0.1)\/3=0.3.<\/p>\n<p>\u041a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043d\u044b\u0439 \u0432\u0435\u043a\u0442\u043e\u0440 \u043e\u043f\u0446\u0438\u0438. \u041f\u0443\u0441\u0442\u044c <code>option_span<\/code> billing = (9, 11), \u0442\u043e \u0435\u0441\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u0438 9 \u0438 10:<\/p>\n<pre><code>\u0441\u0442\u0440\u043e\u043a\u0430  9  \"billing\"    [ 1.2, -0.2,  0.4,  0.0 ]\u0441\u0442\u0440\u043e\u043a\u0430 10  \"payments\"   [ 0.6,  0.4,  0.2,  0.8 ]                        \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500ctx_billing           = [ 0.9,  0.1,  0.3,  0.4 ]<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><span class=\"sc-logo-wrapper icon-only\"><\/span><\/a><\/div><\/pre>\n<p><strong>\u041b\u0435\u043a\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0432\u0435\u043a\u0442\u043e\u0440 \u043e\u043f\u0446\u0438\u0438.<\/strong> \u041f\u043e\u0437\u0438\u0446\u0438\u0438 \u0442\u0435 \u0436\u0435 (9, 11), \u043d\u043e \u0441\u0442\u0440\u043e\u043a\u0438 \u0431\u0435\u0440\u0443\u0442\u0441\u044f \u043d\u0435 \u0438\u0437 <img decoding=\"async\" class=\"formula inline\" source=\"\\tilde H\" alt=\"\\tilde H\" src=\"https:\/\/habrastorage.org\/extt\/6c\/7f\/93\/6c7f9300efcd0cf38b196f6fa517759b.svg\" width=\"17\" height=\"19\" data-width=\"2.009\" data-height=\"2.242\" style=\"width: 2.009ex; height: 2.242ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/6c\/7f\/93\/6c7f9300efcd0cf38b196f6fa517759b.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/6c\/7f\/93\/6c7f9300efcd0cf38b196f6fa517759b.svg 781w\" loading=\"lazy\" decode=\"async\"\/>. \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u043e \u0441\u043f\u0430\u043d\u0443 \u0447\u0438\u0442\u0430\u044e\u0442\u0441\u044f \u043d\u043e\u043c\u0435\u0440\u0430 \u0442\u043e\u043a\u0435\u043d\u043e\u0432, \u043f\u043e\u0442\u043e\u043c \u043f\u043e \u044d\u0442\u0438\u043c \u043d\u043e\u043c\u0435\u0440\u0430\u043c \u0431\u0435\u0440\u0443\u0442\u0441\u044f \u0441\u0442\u0440\u043e\u043a\u0438 <code>lm_head<\/code> (\u043d\u043e\u043c\u0435\u0440\u0430 \u0443\u0441\u043b\u043e\u0432\u043d\u044b\u0435):<\/p>\n<pre><code>input_ids[9]  = 3729    \u2192  E[3729]  = [ 0.05, -0.02,  0.10,  0.01 ]input_ids[10] = 14310   \u2192  E[14310] = [ 0.03,  0.04,  0.02, -0.01 ]                                       \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500lex_billing                          = [ 0.04,  0.01,  0.06,  0.00 ]<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><span class=\"sc-logo-wrapper icon-only\"><\/span><\/a><\/div><\/pre>\n<p>\u0420\u0430\u0437\u043d\u0438\u0446\u0430 \u043c\u0435\u0436\u0434\u0443 ctx \u0438 lex: \u0441\u0442\u0440\u043e\u043a\u0430 9 \u0432 <img decoding=\"async\" class=\"formula inline\" source=\"\\tilde H\" alt=\"\\tilde H\" src=\"https:\/\/habrastorage.org\/extt\/6b\/c8\/dc\/6bc8dcfb5c8b5daab44dc236ad983b6e.svg\" width=\"17\" height=\"19\" data-width=\"2.009\" data-height=\"2.242\" style=\"width: 2.009ex; height: 2.242ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/6b\/c8\/dc\/6bc8dcfb5c8b5daab44dc236ad983b6e.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/6b\/c8\/dc\/6bc8dcfb5c8b5daab44dc236ad983b6e.svg 781w\" loading=\"lazy\" decode=\"async\"\/>&#8212; \u044d\u0442\u043e \u0441\u043b\u043e\u0432\u043e \u00abbilling\u00bb, \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u043d\u043d\u043e\u0435 Qwen \u043f\u043e\u0441\u043b\u0435 \u0442\u0438\u043a\u0435\u0442\u0430, \u0438 \u043e\u043d\u0430 \u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u043e\u0442 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043a \u0437\u0430\u043f\u0440\u043e\u0441\u0443. \u0421\u0442\u0440\u043e\u043a\u0430 <img decoding=\"async\" class=\"formula inline\" source=\"E_{3729}\" alt=\"E_{3729}\" src=\"https:\/\/habrastorage.org\/extt\/0f\/bf\/5c\/0fbf5cd1885a5a2c87ff46852705745f.svg\" width=\"43\" height=\"16\" data-width=\"5.057\" data-height=\"1.913\" data-vertical-align=\"-0.375\" style=\"width: 5.057ex; height: 1.913ex; vertical-align: -0.375ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/0f\/bf\/5c\/0fbf5cd1885a5a2c87ff46852705745f.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/0f\/bf\/5c\/0fbf5cd1885a5a2c87ff46852705745f.svg 781w\" loading=\"lazy\" decode=\"async\"\/> &#8212; \u0441\u043b\u043e\u0432\u043e \u00abbilling\u00bb \u0441\u0430\u043c\u043e \u043f\u043e \u0441\u0435\u0431\u0435, \u0438 \u043e\u043d\u0430 \u0432\u0441\u0435\u0433\u0434\u0430 \u043e\u0434\u043d\u0430 \u0438 \u0442\u0430 \u0436\u0435.<\/p>\n<p><strong>g \u0438 memory.<\/strong> g &#8212; \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u044f\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u0442\u0430\u0431\u043b\u0438\u0446\u044b. memory &#8212; \u0432\u0441\u0435 \u0441\u0442\u0440\u043e\u043a\u0438, \u043a\u0430\u0436\u0434\u0430\u044f \u0443\u043c\u043d\u043e\u0436\u0435\u043d\u043d\u0430\u044f \u043d\u0430 <img decoding=\"async\" class=\"formula inline\" source=\"W_{\\text{mem}}\" alt=\"W_{\\text{mem}}\" src=\"https:\/\/habrastorage.org\/extt\/37\/e9\/51\/37e9518bc22e0828dec034969827bd57.svg\" width=\"48\" height=\"16\" data-width=\"5.699\" data-height=\"1.902\" data-vertical-align=\"-0.357\" style=\"width: 5.699ex; height: 1.902ex; vertical-align: -0.357ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/37\/e9\/51\/37e9518bc22e0828dec034969827bd57.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/37\/e9\/51\/37e9518bc22e0828dec034969827bd57.svg 781w\" loading=\"lazy\" decode=\"async\"\/>. \u0421\u043f\u0430\u043d\u044b \u0442\u0443\u0442 \u043d\u0435 \u043d\u0443\u0436\u043d\u044b.<\/p>\n<\/div>\n<\/details>\n<h4>\u0412\u044b\u0445\u043e\u0434 \u044d\u0442\u0430\u043f\u0430<\/h4>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<th data-colwidth=\"175\" width=\"175\">\n<p align=\"left\">\u0412\u044b\u0445\u043e\u0434<\/p>\n<\/th>\n<th data-colwidth=\"158\" width=\"158\">\n<p align=\"left\">\u0420\u0430\u0437\u043c\u0435\u0440<\/p>\n<\/th>\n<th>\n<p align=\"left\">\u041a\u0430\u043a \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f<\/p>\n<\/th>\n<\/tr>\n<tr>\n<td data-colwidth=\"175\" width=\"175\">\n<p align=\"left\">memory<\/p>\n<\/td>\n<td data-colwidth=\"158\" width=\"158\">\n<p align=\"left\"><img decoding=\"async\" class=\"formula inline\" source=\"[N\\times1024]\" alt=\"[N\\times1024]\" src=\"https:\/\/habrastorage.org\/extt\/99\/96\/e7\/9996e7e476eed8596e37c9061bcb36cc.svg\" width=\"89\" height=\"19\" data-width=\"10.558\" data-height=\"2.262\" data-vertical-align=\"-0.566\" style=\"width: 10.558ex; height: 2.262ex; vertical-align: -0.566ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/99\/96\/e7\/9996e7e476eed8596e37c9061bcb36cc.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/99\/96\/e7\/9996e7e476eed8596e37c9061bcb36cc.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u043e\u0434\u043d\u0430 \u043c\u0430\u0442\u0440\u0438\u0446\u0430<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"175\" width=\"175\">\n<p align=\"left\"><img decoding=\"async\" class=\"formula inline\" source=\"g\" alt=\"g\" src=\"https:\/\/habrastorage.org\/extt\/3f\/b6\/90\/3fb6900f9addc4a280bdd40b8b2e757d.svg\" width=\"9\" height=\"12\" data-width=\"1.079\" data-height=\"1.464\" data-vertical-align=\"-0.464\" style=\"width: 1.079ex; height: 1.464ex; vertical-align: -0.464ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/3f\/b6\/90\/3fb6900f9addc4a280bdd40b8b2e757d.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/3f\/b6\/90\/3fb6900f9addc4a280bdd40b8b2e757d.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<\/td>\n<td data-colwidth=\"158\" width=\"158\">\n<p align=\"left\"><img decoding=\"async\" class=\"formula inline\" source=\"[5120]\" alt=\"[5120]\" src=\"https:\/\/habrastorage.org\/extt\/17\/31\/34\/1731340be30bcc87d7d6f37aefc0523b.svg\" width=\"49\" height=\"19\" data-width=\"5.783\" data-height=\"2.262\" data-vertical-align=\"-0.566\" style=\"width: 5.783ex; height: 2.262ex; vertical-align: -0.566ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/17\/31\/34\/1731340be30bcc87d7d6f37aefc0523b.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/17\/31\/34\/1731340be30bcc87d7d6f37aefc0523b.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u043e\u0434\u0438\u043d \u0432\u0435\u043a\u0442\u043e\u0440<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"175\" width=\"175\">\n<p align=\"left\"><img decoding=\"async\" class=\"formula inline\" source=\"q\" alt=\"q\" src=\"https:\/\/habrastorage.org\/extt\/6f\/b0\/be\/6fb0befd81f5ceb612d6b8b9dc1c1913.svg\" width=\"9\" height=\"12\" data-width=\"1.041\" data-height=\"1.439\" data-vertical-align=\"-0.439\" style=\"width: 1.041ex; height: 1.439ex; vertical-align: -0.439ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/6f\/b0\/be\/6fb0befd81f5ceb612d6b8b9dc1c1913.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/6f\/b0\/be\/6fb0befd81f5ceb612d6b8b9dc1c1913.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<\/td>\n<td data-colwidth=\"158\" width=\"158\">\n<p align=\"left\"><img decoding=\"async\" class=\"formula inline\" source=\"K\\times[5120]\" alt=\"K\\times[5120]\" src=\"https:\/\/habrastorage.org\/extt\/00\/32\/c3\/0032c3fcec21c0bc3296c168b14d3c3f.svg\" width=\"89\" height=\"19\" data-width=\"10.56\" data-height=\"2.262\" data-vertical-align=\"-0.566\" style=\"width: 10.56ex; height: 2.262ex; vertical-align: -0.566ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/00\/32\/c3\/0032c3fcec21c0bc3296c168b14d3c3f.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/00\/32\/c3\/0032c3fcec21c0bc3296c168b14d3c3f.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u043f\u043e \u0432\u0435\u043a\u0442\u043e\u0440\u0443 \u043d\u0430 \u0432\u043e\u043f\u0440\u043e\u0441, \u0432 \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"175\" width=\"175\">\n<p align=\"left\"><img decoding=\"async\" class=\"formula inline\" source=\"ctx\" alt=\"ctx\" src=\"https:\/\/habrastorage.org\/extt\/b5\/70\/2b\/b5702bd2dc4bd18ff31217874f5d74fb.svg\" width=\"26\" height=\"12\" data-width=\"3.09\" data-height=\"1.441\" data-vertical-align=\"-0.025\" style=\"width: 3.09ex; height: 1.441ex; vertical-align: -0.025ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/b5\/70\/2b\/b5702bd2dc4bd18ff31217874f5d74fb.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/b5\/70\/2b\/b5702bd2dc4bd18ff31217874f5d74fb.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<\/td>\n<td data-colwidth=\"158\" width=\"158\">\n<p align=\"left\"><img decoding=\"async\" class=\"formula inline\" source=\"M\\times[5120]\" alt=\"M\\times[5120]\" src=\"https:\/\/habrastorage.org\/extt\/ce\/aa\/da\/ceaada1ff76d1c2d05b4918a97657728.svg\" width=\"92\" height=\"19\" data-width=\"10.926\" data-height=\"2.262\" data-vertical-align=\"-0.566\" style=\"width: 10.926ex; height: 2.262ex; vertical-align: -0.566ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/ce\/aa\/da\/ceaada1ff76d1c2d05b4918a97657728.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/ce\/aa\/da\/ceaada1ff76d1c2d05b4918a97657728.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0441\u043f\u0438\u0441\u043a\u0438 \u043f\u043e \u0432\u043e\u043f\u0440\u043e\u0441\u0430\u043c: 2, 3, 4<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"175\" width=\"175\">\n<p align=\"left\"><img decoding=\"async\" class=\"formula inline\" source=\"lex\" alt=\"lex\" src=\"https:\/\/habrastorage.org\/extt\/ce\/7c\/83\/ce7c83c4b45e7d1e52fb4993bd396af6.svg\" width=\"26\" height=\"13\" data-width=\"3.023\" data-height=\"1.595\" data-vertical-align=\"-0.025\" style=\"width: 3.023ex; height: 1.595ex; vertical-align: -0.025ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/ce\/7c\/83\/ce7c83c4b45e7d1e52fb4993bd396af6.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/ce\/7c\/83\/ce7c83c4b45e7d1e52fb4993bd396af6.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<\/td>\n<td data-colwidth=\"158\" width=\"158\">\n<p align=\"left\"><img decoding=\"async\" class=\"formula inline\" source=\"M\\times[5120]\" alt=\"M\\times[5120]\" src=\"https:\/\/habrastorage.org\/extt\/e8\/d3\/78\/e8d37888ab5d365a5c56c2c820452e88.svg\" width=\"92\" height=\"19\" data-width=\"10.926\" data-height=\"2.262\" data-vertical-align=\"-0.566\" style=\"width: 10.926ex; height: 2.262ex; vertical-align: -0.566ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/e8\/d3\/78\/e8d37888ab5d365a5c56c2c820452e88.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/e8\/d3\/78\/e8d37888ab5d365a5c56c2c820452e88.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0441\u043f\u0438\u0441\u043a\u0438 \u043f\u043e \u0432\u043e\u043f\u0440\u043e\u0441\u0430\u043c: 2, 3, 4<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"175\" width=\"175\">\n<p align=\"left\"><code>option_counts<\/code><\/p>\n<\/td>\n<td data-colwidth=\"158\" width=\"158\">\n<p align=\"left\"><code>[2, 3, 4]<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043e\u043f\u0446\u0438\u0439 \u0443 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0432\u043e\u043f\u0440\u043e\u0441\u0430<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"175\" width=\"175\">\n<p align=\"left\"><code>type_ids<\/code><\/p>\n<\/td>\n<td data-colwidth=\"158\" width=\"158\">\n<p align=\"left\"><code>[0, 1, 2]<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0442\u0438\u043f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0432\u043e\u043f\u0440\u043e\u0441\u0430<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u041f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u0442\u044c \u043a \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c\u0443 \u044d\u0442\u0430\u043f\u0443 \u0440\u0430\u0441\u043f\u0438\u0448\u0443 \u043a\u0430\u043a\u0438\u0435 \u043f\u0440\u043e\u0435\u043a\u0446\u0438\u0438 \u043c\u044b \u0438\u043c\u0435\u0435\u043c:<\/p>\n<pre><code class=\"python\">self.hidden_norm = torch.nn.LayerNorm(hidden_size)self.memory_projection = torch.nn.Linear(hidden_size, width, bias=False)self.question_projection = torch.nn.Linear(hidden_size, width, bias=False)self.option_question_projection = torch.nn.Linear(hidden_size, width, bias=False)self.global_projection = torch.nn.Linear(hidden_size, width, bias=False)self.option_context_projection = torch.nn.Linear(hidden_size, width, bias=False)self.option_lexical_projection = torch.nn.Linear(hidden_size, width, bias=False)self.type_embedding = torch.nn.Embedding(3, width)<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><span class=\"sc-logo-wrapper icon-only\"><\/span><\/a><\/div><\/pre>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<th data-colwidth=\"114\" width=\"114\">\n<p align=\"left\">\u041c\u0430\u0442\u0440\u0438\u0446\u0430<\/p>\n<\/th>\n<th data-colwidth=\"290\" width=\"290\">\n<p align=\"left\">\u0421\u043b\u043e\u0439 \u0432 \u043a\u043e\u0434\u0435<\/p>\n<\/th>\n<th>\n<p align=\"left\">\u0412\u0445\u043e\u0434<\/p>\n<\/th>\n<\/tr>\n<tr>\n<td data-colwidth=\"114\" width=\"114\">\n<p align=\"left\"><img decoding=\"async\" class=\"formula inline\" source=\"W_{\\text{mem}}\" alt=\"W_{\\text{mem}}\" src=\"https:\/\/habrastorage.org\/extt\/8c\/4d\/18\/8c4d184884c2f66232f06a31922458b8.svg\" width=\"48\" height=\"16\" data-width=\"5.699\" data-height=\"1.902\" data-vertical-align=\"-0.357\" style=\"width: 5.699ex; height: 1.902ex; vertical-align: -0.357ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/8c\/4d\/18\/8c4d184884c2f66232f06a31922458b8.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/8c\/4d\/18\/8c4d184884c2f66232f06a31922458b8.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<\/td>\n<td data-colwidth=\"290\" width=\"290\">\n<p align=\"left\"><code>memory_projection<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0432\u0441\u0435 \u0442\u043e\u043a\u0435\u043d\u044b <img decoding=\"async\" class=\"formula inline\" source=\"\\tilde H [N\\times5120]\" alt=\"\\tilde H [N\\times5120]\" src=\"https:\/\/habrastorage.org\/extt\/0b\/62\/0c\/0b620ce465894e784be88e2df461708c.svg\" width=\"106\" height=\"24\" data-width=\"12.567\" data-height=\"2.808\" data-vertical-align=\"-0.566\" style=\"width: 12.567ex; height: 2.808ex; vertical-align: -0.566ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/0b\/62\/0c\/0b620ce465894e784be88e2df461708c.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/0b\/62\/0c\/0b620ce465894e784be88e2df461708c.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"114\" width=\"114\">\n<p align=\"left\"><img decoding=\"async\" class=\"formula inline\" source=\"W_c\" alt=\"W_c\" src=\"https:\/\/habrastorage.org\/extt\/2d\/99\/bb\/2d99bbeb097d258f1bc058d8b78123aa.svg\" width=\"25\" height=\"16\" data-width=\"3.016\" data-height=\"1.902\" data-vertical-align=\"-0.357\" style=\"width: 3.016ex; height: 1.902ex; vertical-align: -0.357ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/2d\/99\/bb\/2d99bbeb097d258f1bc058d8b78123aa.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/2d\/99\/bb\/2d99bbeb097d258f1bc058d8b78123aa.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<\/td>\n<td data-colwidth=\"290\" width=\"290\">\n<p align=\"left\"><code>option_context_projection<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\"><img decoding=\"async\" class=\"formula inline\" source=\"ctx\" alt=\"ctx\" src=\"https:\/\/habrastorage.org\/extt\/21\/86\/64\/21866461d4e3c1a8068f0762f0bdbc27.svg\" width=\"26\" height=\"12\" data-width=\"3.09\" data-height=\"1.441\" data-vertical-align=\"-0.025\" style=\"width: 3.09ex; height: 1.441ex; vertical-align: -0.025ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/21\/86\/64\/21866461d4e3c1a8068f0762f0bdbc27.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/21\/86\/64\/21866461d4e3c1a8068f0762f0bdbc27.svg 781w\" loading=\"lazy\" decode=\"async\"\/> \u043a\u0430\u0436\u0434\u043e\u0439 \u043e\u043f\u0446\u0438\u0438 <img decoding=\"async\" class=\"formula inline\" source=\"[M\\times5120]\" alt=\"[M\\times5120]\" src=\"https:\/\/habrastorage.org\/extt\/57\/f0\/2a\/57f02a8cba69583de44f31b51a4e8154.svg\" width=\"92\" height=\"19\" data-width=\"10.926\" data-height=\"2.262\" data-vertical-align=\"-0.566\" style=\"width: 10.926ex; height: 2.262ex; vertical-align: -0.566ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/57\/f0\/2a\/57f02a8cba69583de44f31b51a4e8154.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/57\/f0\/2a\/57f02a8cba69583de44f31b51a4e8154.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"114\" width=\"114\">\n<p align=\"left\"><img decoding=\"async\" class=\"formula inline\" source=\"W_\\ell\" alt=\"W_\\ell\" src=\"https:\/\/habrastorage.org\/extt\/67\/d4\/7c\/67d47c338a4bbb57bc810152c1923e2f.svg\" width=\"25\" height=\"16\" data-width=\"2.991\" data-height=\"1.917\" data-vertical-align=\"-0.371\" style=\"width: 2.991ex; height: 1.917ex; vertical-align: -0.371ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/67\/d4\/7c\/67d47c338a4bbb57bc810152c1923e2f.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/67\/d4\/7c\/67d47c338a4bbb57bc810152c1923e2f.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<\/td>\n<td data-colwidth=\"290\" width=\"290\">\n<p align=\"left\"><code>option_lexical_projection<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\"><img decoding=\"async\" class=\"formula inline\" source=\"lex\" alt=\"lex\" src=\"https:\/\/habrastorage.org\/extt\/3f\/50\/89\/3f50897382de28d567c2b29610a8c075.svg\" width=\"26\" height=\"13\" data-width=\"3.023\" data-height=\"1.595\" data-vertical-align=\"-0.025\" style=\"width: 3.023ex; height: 1.595ex; vertical-align: -0.025ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/3f\/50\/89\/3f50897382de28d567c2b29610a8c075.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/3f\/50\/89\/3f50897382de28d567c2b29610a8c075.svg 781w\" loading=\"lazy\" decode=\"async\"\/> \u043a\u0430\u0436\u0434\u043e\u0439 \u043e\u043f\u0446\u0438\u0438 <img decoding=\"async\" class=\"formula inline\" source=\"[M\\times5120]\" alt=\"[M\\times5120]\" src=\"https:\/\/habrastorage.org\/extt\/20\/dd\/7e\/20dd7e94479ac54c16dfebcd6bc7f553.svg\" width=\"92\" height=\"19\" data-width=\"10.926\" data-height=\"2.262\" data-vertical-align=\"-0.566\" style=\"width: 10.926ex; height: 2.262ex; vertical-align: -0.566ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/20\/dd\/7e\/20dd7e94479ac54c16dfebcd6bc7f553.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/20\/dd\/7e\/20dd7e94479ac54c16dfebcd6bc7f553.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"114\" width=\"114\">\n<p align=\"left\"><img decoding=\"async\" class=\"formula inline\" source=\"W_{oq}\" alt=\"W_{oq}\" src=\"https:\/\/habrastorage.org\/extt\/9c\/9d\/4a\/9c9d4af5832c47280a3100b546aeda28.svg\" width=\"32\" height=\"19\" data-width=\"3.835\" data-height=\"2.195\" data-vertical-align=\"-0.65\" style=\"width: 3.835ex; height: 2.195ex; vertical-align: -0.65ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/9c\/9d\/4a\/9c9d4af5832c47280a3100b546aeda28.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/9c\/9d\/4a\/9c9d4af5832c47280a3100b546aeda28.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<\/td>\n<td data-colwidth=\"290\" width=\"290\">\n<p align=\"left\"><code>option_question_projection<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\"><img decoding=\"async\" class=\"formula inline\" source=\"q\" alt=\"q\" src=\"https:\/\/habrastorage.org\/extt\/4c\/2b\/ad\/4c2bad996cc0184cb41d11863c0b19f6.svg\" width=\"9\" height=\"12\" data-width=\"1.041\" data-height=\"1.439\" data-vertical-align=\"-0.439\" style=\"width: 1.041ex; height: 1.439ex; vertical-align: -0.439ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/4c\/2b\/ad\/4c2bad996cc0184cb41d11863c0b19f6.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/4c\/2b\/ad\/4c2bad996cc0184cb41d11863c0b19f6.svg 781w\" loading=\"lazy\" decode=\"async\"\/> \u0432\u043e\u043f\u0440\u043e\u0441\u0430, \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u0438\u0442 \u043e\u043f\u0446\u0438\u044f<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"114\" width=\"114\">\n<p align=\"left\"><img decoding=\"async\" class=\"formula inline\" source=\"W_q\" alt=\"W_q\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/2\/2c\/2cd\/2cd1ee420e376bb596b3933e403d18ce.svg\" width=\"24\" height=\"18\" data-width=\"3.059\" data-height=\"2.195\" data-vertical-align=\"-0.65\" style=\"width: 3.059ex; height: 2.195ex; vertical-align: -0.65ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/2\/2c\/2cd\/2cd1ee420e376bb596b3933e403d18ce.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/2\/2c\/2cd\/2cd1ee420e376bb596b3933e403d18ce.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<\/td>\n<td data-colwidth=\"290\" width=\"290\">\n<p align=\"left\"><code>question_projection<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\"><img decoding=\"async\" class=\"formula inline\" source=\"q\" alt=\"q\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/7\/76\/769\/7694f4a66316e53c8cdd9d9954bd611d.svg\" width=\"12\" height=\"12\" data-width=\"1.041\" data-height=\"1.439\" data-vertical-align=\"-0.439\" style=\"width: 1.041ex; height: 1.439ex; vertical-align: -0.439ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/7\/76\/769\/7694f4a66316e53c8cdd9d9954bd611d.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/7\/76\/769\/7694f4a66316e53c8cdd9d9954bd611d.svg 781w\" loading=\"lazy\" decode=\"async\"\/> \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0432\u043e\u043f\u0440\u043e\u0441\u0430 <img decoding=\"async\" class=\"formula inline\" source=\"[K\\times5120]\" alt=\"[K\\times5120]\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/e\/e4\/e46\/e4656d0890a1b2f7794bd801f898591a.svg\" width=\"84\" height=\"18\" data-width=\"10.56\" data-height=\"2.262\" data-vertical-align=\"-0.566\" style=\"width: 10.56ex; height: 2.262ex; vertical-align: -0.566ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/e\/e4\/e46\/e4656d0890a1b2f7794bd801f898591a.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/e\/e4\/e46\/e4656d0890a1b2f7794bd801f898591a.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"114\" width=\"114\">\n<p align=\"left\"><img decoding=\"async\" class=\"formula inline\" source=\"W_g\" alt=\"W_g\" src=\"https:\/\/habrastorage.org\/extt\/a0\/3d\/21\/a03d2142ca19d045057bfed2a1174df6.svg\" width=\"26\" height=\"19\" data-width=\"3.087\" data-height=\"2.213\" data-vertical-align=\"-0.667\" style=\"width: 3.087ex; height: 2.213ex; vertical-align: -0.667ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/a0\/3d\/21\/a03d2142ca19d045057bfed2a1174df6.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/a0\/3d\/21\/a03d2142ca19d045057bfed2a1174df6.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<\/td>\n<td data-colwidth=\"290\" width=\"290\">\n<p align=\"left\"><code>global_projection<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\"><img decoding=\"async\" class=\"formula inline\" source=\"g [5120]\" alt=\"g [5120]\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/d\/d4\/d44\/d44cfeed6dbef47301761aa94bb0c99f.svg\" width=\"55\" height=\"18\" data-width=\"6.862\" data-height=\"2.262\" data-vertical-align=\"-0.566\" style=\"width: 6.862ex; height: 2.262ex; vertical-align: -0.566ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/d\/d4\/d44\/d44cfeed6dbef47301761aa94bb0c99f.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/d\/d4\/d44\/d44cfeed6dbef47301761aa94bb0c99f.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"114\" width=\"114\">\n<p align=\"left\"><img decoding=\"async\" class=\"formula inline\" source=\"T\" alt=\"T\" src=\"https:\/\/habrastorage.org\/extt\/1f\/8d\/52\/1f8d52cd2ff249508b96821fd9d6797c.svg\" width=\"13\" height=\"13\" data-width=\"1.593\" data-height=\"1.532\" style=\"width: 1.593ex; height: 1.532ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/1f\/8d\/52\/1f8d52cd2ff249508b96821fd9d6797c.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/1f\/8d\/52\/1f8d52cd2ff249508b96821fd9d6797c.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<\/td>\n<td data-colwidth=\"290\" width=\"290\">\n<p align=\"left\"><code>type_embedding<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0442\u0438\u043f \u0432\u043e\u043f\u0440\u043e\u0441\u0430 (0, 1, 2)<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<h3>\u042d\u0442\u0430\u043f B. Evidence routing \u00d72<\/h3>\n<figure class=\"full-width \"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/extt\/08\/21\/28\/082128d42ca6c478a77107e50dfaec94.png\" width=\"2360\" height=\"2486\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/extt\/08\/21\/28\/082128d42ca6c478a77107e50dfaec94.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/extt\/08\/21\/28\/082128d42ca6c478a77107e50dfaec94.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<p>Evidence routing &#8212; \u044d\u0442\u0430\u043f, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043a\u0430\u0436\u0434\u0430\u044f \u043e\u043f\u0446\u0438\u044f \u0441\u0430\u043c\u0430 \u0438\u0449\u0435\u0442 \u0432 \u0442\u0435\u043a\u0441\u0442\u0435 \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u0441\u0435\u0431\u044f. \u042d\u0442\u043e \u0434\u0432\u0430 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0445 \u043f\u043e \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0443 \u0441\u043b\u043e\u044f <code>EvidenceRoutingLayer<\/code>, \u043a\u0430\u0436\u0434\u044b\u0439 \u0441\u043e \u0441\u0432\u043e\u0438\u043c\u0438 \u0432\u0435\u0441\u0430\u043c\u0438.<\/p>\n<details class=\"spoiler\">\n<summary>\u0421\u0430\u043c \u0421\u043b\u043e\u0439<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">class EvidenceRoutingLayer(torch.nn.Module):    def __init__(        self,        width: int,        heads: int,        feedforward: int,        dropout: float = 0.0,    ) -&gt; None:        super().__init__()        self.query_norm = torch.nn.LayerNorm(width)        self.memory_norm = torch.nn.LayerNorm(width)        self.attention = torch.nn.MultiheadAttention(            width,            heads,            dropout=dropout,            batch_first=True,        )        self.attention_dropout = torch.nn.Dropout(dropout)        self.feedforward_norm = torch.nn.LayerNorm(width)        self.feedforward = torch.nn.Sequential(            torch.nn.Linear(width, feedforward),            torch.nn.GELU(),            torch.nn.Dropout(dropout),            torch.nn.Linear(feedforward, width),            torch.nn.Dropout(dropout),        )    def forward(self, queries: torch.Tensor, memory: torch.Tensor) -&gt; torch.Tensor:        normalized_queries = self.query_norm(queries)        routed, _ = self.attention(            normalized_queries,            self.memory_norm(memory),            self.memory_norm(memory),            need_weights=False,        )        queries = queries + self.attention_dropout(routed)        return queries + self.feedforward(self.feedforward_norm(queries))<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><span class=\"sc-logo-wrapper icon-only\"><\/span><\/a><\/div><\/pre>\n<p>\u041a\u0430\u0436\u0434\u0430\u044f \u043e\u043f\u0446\u0438\u044f \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e \u0438 \u043d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u00ab\u0432\u0430\u0436\u043d\u043e\u0441\u0442\u0438\u00bb \u0442\u043e\u043a\u0435\u043d\u0430 \u0432\u0441\u0435\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043a \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0439 \u043e\u043f\u0446\u0438\u0438.<\/p>\n<\/div>\n<\/details>\n<h4>\u0412\u0445\u043e\u0434<\/h4>\n<p><img decoding=\"async\" class=\"formula inline\" source=\"u^{(0)}_{kj}=W_c c_{kj}+W_\\ell\\ell_{kj}+W_{oq}q_k\" alt=\"u^{(0)}_{kj}=W_c c_{kj}+W_\\ell\\ell_{kj}+W_{oq}q_k\" src=\"https:\/\/habrastorage.org\/extt\/4d\/0a\/80\/4d0a80755b8cace97f98f9c533f8aef3.svg\" width=\"247\" height=\"29\" data-width=\"29.231\" data-height=\"3.444\" data-vertical-align=\"-1.044\" style=\"width: 29.231ex; height: 3.444ex; vertical-align: -1.044ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/4d\/0a\/80\/4d0a80755b8cace97f98f9c533f8aef3.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/4d\/0a\/80\/4d0a80755b8cace97f98f9c533f8aef3.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<details class=\"spoiler\">\n<summary>\u0414\u043b\u044f \u0432\u043e\u043f\u0440\u043e\u0441\u0430 team:<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"markdown\">u_billing   = W_c\u00b7ctx_billing   + W_\u2113\u00b7lex_billing   + W_oq\u00b7q_teamu_sales     = W_c\u00b7ctx_sales     + W_\u2113\u00b7lex_sales     + W_oq\u00b7q_teamu_technical = W_c\u00b7ctx_technical + W_\u2113\u00b7lex_technical + W_oq\u00b7q_team<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><span class=\"sc-logo-wrapper icon-only\"><\/span><\/a><\/div><\/pre>\n<\/div>\n<\/details>\n<p>\u0427\u0442\u043e \u0434\u0430\u0451\u0442 \u043a\u0430\u0436\u0434\u043e\u0435 \u0441\u043b\u0430\u0433\u0430\u0435\u043c\u043e\u0435:<\/p>\n<ul>\n<li>\n<p><img decoding=\"async\" class=\"formula inline\" source=\"W_c\\,c\" alt=\"W_c\\,c\" src=\"https:\/\/habrastorage.org\/extt\/cc\/f4\/11\/ccf411e5d6e4049588bbbaf2a9338711.svg\" width=\"37\" height=\"16\" data-width=\"4.374\" data-height=\"1.902\" data-vertical-align=\"-0.357\" style=\"width: 4.374ex; height: 1.902ex; vertical-align: -0.357ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/cc\/f4\/11\/ccf411e5d6e4049588bbbaf2a9338711.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/cc\/f4\/11\/ccf411e5d6e4049588bbbaf2a9338711.svg 781w\" loading=\"lazy\" decode=\"async\"\/> &#8212; \u0447\u0442\u043e Qwen \u043f\u043e\u043d\u044f\u043b \u043e\u0431 \u043e\u043f\u0446\u0438\u0438 \u043f\u043e\u0441\u043b\u0435 \u043f\u0440\u043e\u0447\u0442\u0435\u043d\u0438\u044f \u0442\u0438\u043a\u0435\u0442\u0430;<\/p>\n<\/li>\n<li>\n<p><img decoding=\"async\" class=\"formula inline\" source=\"W_\\ell\\,\\ell \" alt=\"W_\\ell\\,\\ell \" src=\"https:\/\/habrastorage.org\/extt\/18\/f7\/a3\/18f7a312a22fe8c1fe962a64117524da.svg\" width=\"36\" height=\"17\" data-width=\"4.312\" data-height=\"1.966\" data-vertical-align=\"-0.371\" style=\"width: 4.312ex; height: 1.966ex; vertical-align: -0.371ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/18\/f7\/a3\/18f7a312a22fe8c1fe962a64117524da.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/18\/f7\/a3\/18f7a312a22fe8c1fe962a64117524da.svg 781w\" loading=\"lazy\" decode=\"async\"\/>&#8212; \u0447\u0442\u043e \u0437\u043d\u0430\u0447\u0430\u0442 \u0441\u043b\u043e\u0432\u0430 \u043e\u043f\u0446\u0438\u0438 \u0441\u0430\u043c\u0438 \u043f\u043e \u0441\u0435\u0431\u0435;<\/p>\n<\/li>\n<li>\n<p><img decoding=\"async\" class=\"formula inline\" source=\"W_{oq}\\,q \" alt=\"W_{oq}\\,q \" src=\"https:\/\/habrastorage.org\/extt\/db\/00\/83\/db00832cd69125ecd01f7a735a35853e.svg\" width=\"44\" height=\"19\" data-width=\"5.254\" data-height=\"2.195\" data-vertical-align=\"-0.65\" style=\"width: 5.254ex; height: 2.195ex; vertical-align: -0.65ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/db\/00\/83\/db00832cd69125ecd01f7a735a35853e.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/db\/00\/83\/db00832cd69125ecd01f7a735a35853e.svg 781w\" loading=\"lazy\" decode=\"async\"\/>&#8212; \u043a \u043a\u0430\u043a\u043e\u043c\u0443 \u0432\u043e\u043f\u0440\u043e\u0441\u0443 \u043e\u043f\u0446\u0438\u044f \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0441\u044f. \u041e\u043f\u0446\u0438\u044f \u0438\u0449\u0435\u0442 \u0432 \u0442\u0435\u043a\u0441\u0442\u0435 \u00ab\u0447\u0442\u043e-\u0442\u043e \u043f\u0440\u043e \u0441\u0435\u0431\u044f \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u044d\u0442\u043e\u0433\u043e \u0432\u043e\u043f\u0440\u043e\u0441\u0430\u00bb.<\/p>\n<\/li>\n<\/ul>\n<p>\u041e\u043f\u0446\u0438\u0438 \u0432\u0441\u0435\u0445 \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432 \u0441\u043a\u043b\u0435\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u0432 \u043e\u0434\u043d\u0443 \u043c\u0430\u0442\u0440\u0438\u0446\u0443 <img decoding=\"async\" class=\"formula inline\" source=\"U^{(0)} [9\\times1024]\" alt=\"U^{(0)} [9\\times1024]\" src=\"https:\/\/habrastorage.org\/extt\/40\/6e\/46\/406e46d361f61b3d8095e7a162deecd7.svg\" width=\"116\" height=\"23\" data-width=\"13.77\" data-height=\"2.7\" data-vertical-align=\"-0.566\" style=\"width: 13.77ex; height: 2.7ex; vertical-align: -0.566ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/40\/6e\/46\/406e46d361f61b3d8095e7a162deecd7.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/40\/6e\/46\/406e46d361f61b3d8095e7a162deecd7.svg 781w\" loading=\"lazy\" decode=\"async\"\/>. \u042d\u0442\u043e \u0436\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u043e\u043f\u0430\u0434\u0430\u0435\u0442 \u043d\u0430 \u0432\u0445\u043e\u0434 \u0432\u0442\u043e\u0440\u043e\u0433\u043e <code>EvidenceRoutingLayer<\/code><\/p>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434<\/summary>\n<div class=\"spoiler__content\">\n<p>\u0421\u0431\u043e\u0440\u043a\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0438 \u0432\u044b\u0437\u043e\u0432 \u0441\u043b\u043e\u0451\u0432 \u0432 <code>JointSchemaHead.forward<\/code>:<\/p>\n<pre><code class=\"python\">option_queries = []for question_index, (context_vectors, lexical) in enumerate(    zip(option_contexts, lexical_options)):    option_queries.append(        self.option_context_projection(context_vectors)        + self.option_lexical_projection(lexical)        + self.option_question_projection(            question_vectors[question_index]        ).unsqueeze(0)    )routed_options = torch.cat(option_queries, dim=0).unsqueeze(0)for layer in self.evidence_layers:    routed_options = layer(routed_options, memory)routed_options = routed_options[0]split_options = list(torch.split(routed_options, option_counts, dim=0))<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><span class=\"sc-logo-wrapper icon-only\"><\/span><\/a><\/div><\/pre>\n<\/div>\n<\/details>\n<h4>\u0412\u044b\u0445\u043e\u0434 \u044d\u0442\u0430\u043f\u0430<\/h4>\n<p><img decoding=\"async\" class=\"formula inline\" source=\"R [9\\times1024]\" alt=\"R [9\\times1024]\" src=\"https:\/\/habrastorage.org\/extt\/ad\/03\/2c\/ad032c017b09738917682961f35e0fa3.svg\" width=\"96\" height=\"19\" data-width=\"11.397\" data-height=\"2.262\" data-vertical-align=\"-0.566\" style=\"width: 11.397ex; height: 2.262ex; vertical-align: -0.566ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/ad\/03\/2c\/ad032c017b09738917682961f35e0fa3.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/ad\/03\/2c\/ad032c017b09738917682961f35e0fa3.svg 781w\" loading=\"lazy\" decode=\"async\"\/> \u0440\u0435\u0436\u0435\u0442\u0441\u044f \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u043d\u0430 \u0433\u0440\u0443\u043f\u043f\u044b \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432 (\u043e\u0431\u043e\u0433\u0430\u0449\u0435\u043d\u043d\u044b\u0435). <\/p>\n<h3>\u042d\u0442\u0430\u043f C1. \u0421\u0431\u043e\u0440\u043a\u0430 \u043f\u043e\u043b\u044f \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0432\u043e\u043f\u0440\u043e\u0441\u0430<\/h3>\n<figure class=\"full-width \"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/extt\/ec\/df\/52\/ecdf527133eca7a1e712f7aeb7e06cdc.png\" width=\"2360\" height=\"2482\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/extt\/ec\/df\/52\/ecdf527133eca7a1e712f7aeb7e06cdc.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/extt\/ec\/df\/52\/ecdf527133eca7a1e712f7aeb7e06cdc.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<p>\u041d\u0430 \u044d\u0442\u043e\u043c \u044d\u0442\u0430\u043f\u0435 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0432\u043e\u043f\u0440\u043e\u0441\u0430 \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u0442\u0441\u044f \u043e\u0434\u0438\u043d \u0432\u0435\u043a\u0442\u043e\u0440 &#8212; <strong>\u043f\u043e\u043b\u0435<\/strong>. \u041f\u043e\u043b\u0435 \u0434\u0430\u043b\u044c\u0448\u0435 \u043f\u043e\u0439\u0434\u0451\u0442 \u0432 joint-\u0441\u043b\u043e\u0438, \u0438 \u0432 \u043a\u043e\u043d\u0446\u0435 \u0441 \u043d\u0438\u043c \u0431\u0443\u0434\u0443\u0442 \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u043e\u043f\u0446\u0438\u0438.<\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<th data-colwidth=\"588\" width=\"588\">\n<p align=\"left\">\u0412\u0445\u043e\u0434<\/p>\n<\/th>\n<th>\n<p align=\"left\">\u0420\u0430\u0437\u043c\u0435\u0440<\/p>\n<\/th>\n<\/tr>\n<tr>\n<td data-colwidth=\"588\" width=\"588\">\n<p align=\"left\"><img decoding=\"async\" class=\"formula inline\" source=\"q_k\" alt=\"q_k\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/1\/1f\/1fc\/1fcf841ba6cb2c8ae44b2ca642079582.svg\" width=\"16\" height=\"12\" data-width=\"2.03\" data-height=\"1.439\" data-vertical-align=\"-0.439\" style=\"width: 2.03ex; height: 1.439ex; vertical-align: -0.439ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/1\/1f\/1fc\/1fcf841ba6cb2c8ae44b2ca642079582.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/1\/1f\/1fc\/1fcf841ba6cb2c8ae44b2ca642079582.svg 781w\" loading=\"lazy\" decode=\"async\"\/> &#8212; \u0432\u0435\u043a\u0442\u043e\u0440 \u0432\u043e\u043f\u0440\u043e\u0441\u0430<\/p>\n<\/td>\n<td>\n<p align=\"left\"><img decoding=\"async\" class=\"formula inline\" source=\"K\\times5120\" alt=\"K\\times5120\" src=\"https:\/\/habrastorage.org\/extt\/09\/d2\/fa\/09d2fa6ae06cb9abe04b2b8bb186fb60.svg\" width=\"79\" height=\"13\" data-width=\"9.302\" data-height=\"1.595\" data-vertical-align=\"-0.05\" style=\"width: 9.302ex; height: 1.595ex; vertical-align: -0.05ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/09\/d2\/fa\/09d2fa6ae06cb9abe04b2b8bb186fb60.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/09\/d2\/fa\/09d2fa6ae06cb9abe04b2b8bb186fb60.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"588\" width=\"588\">\n<p align=\"left\"><img decoding=\"async\" class=\"formula inline\" source=\"R_k\" alt=\"R_k\" src=\"https:\/\/habrastorage.org\/extt\/24\/99\/3e\/24993e6debf32c68fe72d2aac93792d7.svg\" width=\"23\" height=\"16\" data-width=\"2.738\" data-height=\"1.902\" data-vertical-align=\"-0.357\" style=\"width: 2.738ex; height: 1.902ex; vertical-align: -0.357ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/24\/99\/3e\/24993e6debf32c68fe72d2aac93792d7.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/24\/99\/3e\/24993e6debf32c68fe72d2aac93792d7.svg 781w\" loading=\"lazy\" decode=\"async\"\/> &#8212; \u043e\u0431\u043e\u0433\u0430\u0449\u0451\u043d\u043d\u044b\u0435 \u043e\u043f\u0446\u0438\u0438 \u0432\u043e\u043f\u0440\u043e\u0441\u0430<\/p>\n<\/td>\n<td>\n<p align=\"left\"><img decoding=\"async\" class=\"formula inline\" source=\"n_k\\times1024\" alt=\"n_k\\times1024\" src=\"https:\/\/habrastorage.org\/extt\/62\/f4\/aa\/62f4aa5687aadbe2928920ef60db4d1a.svg\" width=\"82\" height=\"16\" data-width=\"9.669\" data-height=\"1.889\" data-vertical-align=\"-0.357\" style=\"width: 9.669ex; height: 1.889ex; vertical-align: -0.357ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/62\/f4\/aa\/62f4aa5687aadbe2928920ef60db4d1a.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/62\/f4\/aa\/62f4aa5687aadbe2928920ef60db4d1a.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"588\" width=\"588\">\n<p align=\"left\"><img decoding=\"async\" class=\"formula inline\" source=\"g\" alt=\"g\" src=\"https:\/\/habrastorage.org\/extt\/5d\/58\/ca\/5d58caa51fe3d93669866c6b323d9faa.svg\" width=\"9\" height=\"12\" data-width=\"1.079\" data-height=\"1.464\" data-vertical-align=\"-0.464\" style=\"width: 1.079ex; height: 1.464ex; vertical-align: -0.464ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/5d\/58\/ca\/5d58caa51fe3d93669866c6b323d9faa.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/5d\/58\/ca\/5d58caa51fe3d93669866c6b323d9faa.svg 781w\" loading=\"lazy\" decode=\"async\"\/> &#8212; \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0442\u043e\u043a\u0435\u043d<\/p>\n<\/td>\n<td>\n<p align=\"left\"><img decoding=\"async\" class=\"formula inline\" source=\"5120\" alt=\"5120\" src=\"https:\/\/habrastorage.org\/extt\/e8\/35\/e3\/e835e3e2a53ed7574b29622f7652dfe6.svg\" width=\"38\" height=\"13\" data-width=\"4.525\" data-height=\"1.557\" data-vertical-align=\"-0.05\" style=\"width: 4.525ex; height: 1.557ex; vertical-align: -0.05ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/e8\/35\/e3\/e835e3e2a53ed7574b29622f7652dfe6.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/e8\/35\/e3\/e835e3e2a53ed7574b29622f7652dfe6.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"588\" width=\"588\">\n<p align=\"left\"><code>type_ids<\/code> &#8212; \u0442\u0438\u043f \u0432\u043e\u043f\u0440\u043e\u0441\u0430<\/p>\n<\/td>\n<td>\n<p align=\"left\"><img decoding=\"async\" class=\"formula inline\" source=\"K\" alt=\"K\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/a\/a5\/a5f\/a5f3c6a11b03839d46af9fb43c97c188.svg\" width=\"16\" height=\"12\" data-width=\"2.011\" data-height=\"1.545\" style=\"width: 2.011ex; height: 1.545ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/a\/a5\/a5f\/a5f3c6a11b03839d46af9fb43c97c188.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/a\/a5\/a5f\/a5f3c6a11b03839d46af9fb43c97c188.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">base_fields = self.question_projection(question_vectors)option_summaries = []for field, options in zip(base_fields, split_options):    routing_weights = torch.softmax(        torch.matmul(options, field) \/ math.sqrt(options.shape[-1]),        dim=0,    )    option_summaries.append(        torch.sum(routing_weights.unsqueeze(-1) * options, dim=0)    )fields = (    base_fields    + self.option_summary_norm(torch.stack(option_summaries))    + self.global_projection(global_vector).unsqueeze(0)    + self.type_embedding(type_ids))<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><span class=\"sc-logo-wrapper icon-only\"><\/span><\/a><\/div><\/pre>\n<\/div>\n<\/details>\n<h4>\u0428\u0430\u0433\u0438 \u043f\u043e \u043f\u043e\u0440\u044f\u0434\u043a\u0443<\/h4>\n<p>1.<img decoding=\"async\" class=\"formula inline\" source=\" b_k=W_qq_k,\\qquad W_q\\in\\mathbb{R}^{1024\\times5120},\\quad b_k\\in\\mathbb{R}^{1024}\" alt=\" b_k=W_qq_k,\\qquad W_q\\in\\mathbb{R}^{1024\\times5120},\\quad b_k\\in\\mathbb{R}^{1024}\" src=\"https:\/\/habrastorage.org\/extt\/e8\/62\/15\/e862153c1ede2555590b8d1f544d994d.svg\" width=\"372\" height=\"23\" data-width=\"43.967\" data-height=\"2.667\" data-vertical-align=\"-0.65\" style=\"width: 43.967ex; height: 2.667ex; vertical-align: -0.65ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/e8\/62\/15\/e862153c1ede2555590b8d1f544d994d.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/e8\/62\/15\/e862153c1ede2555590b8d1f544d994d.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<p>2. <img decoding=\"async\" class=\"formula inline\" source=\"s_{kj}=\\frac{r_{kj}\\cdot b_k}{\\sqrt{1024}}\" alt=\"s_{kj}=\\frac{r_{kj}\\cdot b_k}{\\sqrt{1024}}\" src=\"https:\/\/habrastorage.org\/extt\/51\/d6\/0c\/51d60c4b4bf5244e2b9148f9d9deefce.svg\" width=\"112\" height=\"47\" data-width=\"13.209\" data-height=\"5.584\" data-vertical-align=\"-2.308\" style=\"width: 13.209ex; height: 5.584ex; vertical-align: -2.308ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/51\/d6\/0c\/51d60c4b4bf5244e2b9148f9d9deefce.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/51\/d6\/0c\/51d60c4b4bf5244e2b9148f9d9deefce.svg 781w\" loading=\"lazy\" decode=\"async\"\/>&#8212; \u043e\u0446\u0435\u043d\u043a\u0430 \u043a\u0430\u0436\u0434\u043e\u0439 \u043e\u043f\u0446\u0438\u0438.<\/p>\n<p>3. <img decoding=\"async\" class=\"formula inline\" source=\"\\alpha_{kj} = \\frac{e^{s_{kj}}}{\\sum_{j\u2019=1}^{n_k} e^{s_{kj\u2019}}}\" alt=\"\\alpha_{kj} = \\frac{e^{s_{kj}}}{\\sum_{j\u2019=1}^{n_k} e^{s_{kj\u2019}}}\" src=\"https:\/\/habrastorage.org\/extt\/16\/89\/eb\/1689eb0d53ee0e0e5912d588a8f941a6.svg\" width=\"142\" height=\"49\" data-width=\"16.828\" data-height=\"5.756\" data-vertical-align=\"-2.698\" style=\"width: 16.828ex; height: 5.756ex; vertical-align: -2.698ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/16\/89\/eb\/1689eb0d53ee0e0e5912d588a8f941a6.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/16\/89\/eb\/1689eb0d53ee0e0e5912d588a8f941a6.svg 781w\" loading=\"lazy\" decode=\"async\"\/>&#8212; Softmax. \u0420\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043e\u043f\u0446\u0438\u0439 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0432\u043e\u043f\u0440\u043e\u0441\u0430.<\/p>\n<p>4. <img decoding=\"async\" class=\"formula inline\" source=\"\\bar{r}_k = \\sum_j \\alpha_{kj}r_{kj} = \\alpha_k^\\top R_k \\quad \\in \\mathbb{R}^{1024}\" alt=\"\\bar{r}_k = \\sum_j \\alpha_{kj}r_{kj} = \\alpha_k^\\top R_k \\quad \\in \\mathbb{R}^{1024}\" src=\"https:\/\/habrastorage.org\/extt\/04\/6f\/71\/046f717722be3da4ff9ecc45f6fd0853.svg\" width=\"281\" height=\"44\" data-width=\"33.217\" data-height=\"5.155\" data-vertical-align=\"-3.006\" style=\"width: 33.217ex; height: 5.155ex; vertical-align: -3.006ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/04\/6f\/71\/046f717722be3da4ff9ecc45f6fd0853.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/04\/6f\/71\/046f717722be3da4ff9ecc45f6fd0853.svg 781w\" loading=\"lazy\" decode=\"async\"\/>&#8212; \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0432\u0435\u043a\u0442\u043e\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u043e\u0431\u0449\u0443\u044e \u043a\u0430\u0440\u0442\u0438\u043d\u0443 \u043f\u043e \u0432\u0441\u0435\u043c \u043e\u043f\u0446\u0438\u044f\u043c \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0432\u043e\u043f\u0440\u043e\u0441\u0430.<\/p>\n<p>5. <img decoding=\"async\" class=\"formula inline\" source=\"\\mathrm{LN}_s(\\bar r_k)\" alt=\"\\mathrm{LN}_s(\\bar r_k)\" src=\"https:\/\/habrastorage.org\/extt\/07\/1f\/86\/071f864a3e18083b7c871fcf4c2345e5.svg\" width=\"66\" height=\"19\" data-width=\"7.851\" data-height=\"2.262\" data-vertical-align=\"-0.566\" style=\"width: 7.851ex; height: 2.262ex; vertical-align: -0.566ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/07\/1f\/86\/071f864a3e18083b7c871fcf4c2345e5.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/07\/1f\/86\/071f864a3e18083b7c871fcf4c2345e5.svg 781w\" loading=\"lazy\" decode=\"async\"\/> &#8212; \u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f.<\/p>\n<p>6. <img decoding=\"async\" class=\"formula inline\" source=\"W_gg\" alt=\"W_gg\" src=\"https:\/\/habrastorage.org\/extt\/8f\/8c\/dc\/8f8cdc6ae0b0283fd32b1355ec33453e.svg\" width=\"35\" height=\"19\" data-width=\"4.166\" data-height=\"2.213\" data-vertical-align=\"-0.667\" style=\"width: 4.166ex; height: 2.213ex; vertical-align: -0.667ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/8f\/8c\/dc\/8f8cdc6ae0b0283fd32b1355ec33453e.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/8f\/8c\/dc\/8f8cdc6ae0b0283fd32b1355ec33453e.svg 781w\" loading=\"lazy\" decode=\"async\"\/> <img decoding=\"async\" class=\"formula inline\" source=\"W_g\\in\\mathbb{R}^{1024\\times5120}\" alt=\"W_g\\in\\mathbb{R}^{1024\\times5120}\" src=\"https:\/\/habrastorage.org\/extt\/11\/5f\/0f\/115f0ff0436f29fbbcdda0d3988bc960.svg\" width=\"129\" height=\"23\" data-width=\"15.318\" data-height=\"2.685\" data-vertical-align=\"-0.667\" style=\"width: 15.318ex; height: 2.685ex; vertical-align: -0.667ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/11\/5f\/0f\/115f0ff0436f29fbbcdda0d3988bc960.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/11\/5f\/0f\/115f0ff0436f29fbbcdda0d3988bc960.svg 781w\" loading=\"lazy\" decode=\"async\"\/> &#8212; \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u0430\u044f \u0434\u043e\u0431\u0430\u0432\u043a\u0430. \u0412\u0441\u0435 \u043f\u043e\u043b\u044f \u00ab\u0437\u043d\u0430\u044e\u0442\u00bb, \u043e \u0447\u0451\u043c \u0432\u0435\u0441\u044c \u0442\u0438\u043a\u0435\u0442.<\/p>\n<p>7. <img decoding=\"async\" class=\"formula inline\" source=\"T_{\\tau_k}\" alt=\"T_{\\tau_k}\" src=\"https:\/\/habrastorage.org\/extt\/d9\/be\/55\/d9be55e424987a7ccc8d599b283d1645.svg\" width=\"25\" height=\"18\" data-width=\"2.93\" data-height=\"2.123\" data-vertical-align=\"-0.592\" style=\"width: 2.93ex; height: 2.123ex; vertical-align: -0.592ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/d9\/be\/55\/d9be55e424987a7ccc8d599b283d1645.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/d9\/be\/55\/d9be55e424987a7ccc8d599b283d1645.svg 781w\" loading=\"lazy\" decode=\"async\"\/> <img decoding=\"async\" class=\"formula inline\" source=\"T\\in\\mathbb{R}^{3\\times1024}\" alt=\"T\\in\\mathbb{R}^{3\\times1024}\" src=\"https:\/\/habrastorage.org\/extt\/bf\/4b\/83\/bf4b83d6e333da32a6989098d0f3e5da.svg\" width=\"97\" height=\"18\" data-width=\"11.424\" data-height=\"2.108\" data-vertical-align=\"-0.09\" style=\"width: 11.424ex; height: 2.108ex; vertical-align: -0.09ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/bf\/4b\/83\/bf4b83d6e333da32a6989098d0f3e5da.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/bf\/4b\/83\/bf4b83d6e333da32a6989098d0f3e5da.svg 781w\" loading=\"lazy\" decode=\"async\"\/> &#8212; \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433 \u0442\u0438\u043f\u0430. \u0422\u0430\u0431\u043b\u0438\u0446\u0430 \u0438\u0437 \u0442\u0440\u0451\u0445 \u043e\u0431\u0443\u0447\u0430\u0435\u043c\u044b\u0445 \u0441\u0442\u0440\u043e\u043a: noul, choice, score. \u041f\u043e\u043b\u0435 \u0437\u043d\u0430\u0435\u0442, \u043a\u0430\u043a \u0431\u0443\u0434\u0443\u0442 \u0447\u0438\u0442\u0430\u0442\u044c\u0441\u044f \u0435\u0433\u043e \u043e\u043f\u0446\u0438\u0438.<\/p>\n<p><img decoding=\"async\" class=\"formula inline\" source=\"f^{(0)}_k = \\underbrace{b_k}_{\\text{\u0432\u043e\u043f\u0440\u043e\u0441}} + \\underbrace{\\mathrm{LN}_s(\\bar{r}_k)}_{\\text{\u0435\u0433\u043e \u043e\u043f\u0446\u0438\u0438}} + \\underbrace{W_g g}_{\\text{\u0432\u0435\u0441\u044c \u0437\u0430\u043f\u0440\u043e\u0441}} + \\underbrace{T_{\\tau_k}}_{\\text{\u0442\u0438\u043f}}\" alt=\"f^{(0)}_k = \\underbrace{b_k}_{\\text{\u0432\u043e\u043f\u0440\u043e\u0441}} + \\underbrace{\\mathrm{LN}_s(\\bar{r}_k)}_{\\text{\u0435\u0433\u043e \u043e\u043f\u0446\u0438\u0438}} + \\underbrace{W_g g}_{\\text{\u0432\u0435\u0441\u044c \u0437\u0430\u043f\u0440\u043e\u0441}} + \\underbrace{T_{\\tau_k}}_{\\text{\u0442\u0438\u043f}}\" src=\"https:\/\/habrastorage.org\/extt\/59\/bf\/98\/59bf986e478acb968ef3bf5a2d9eaf69.svg\" width=\"362\" height=\"56\" data-width=\"42.82\" data-height=\"6.594\" data-vertical-align=\"-4.194\" style=\"width: 42.82ex; height: 6.594ex; vertical-align: -4.194ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/59\/bf\/98\/59bf986e478acb968ef3bf5a2d9eaf69.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/59\/bf\/98\/59bf986e478acb968ef3bf5a2d9eaf69.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<h4>\u0412\u044b\u0445\u043e\u0434 \u044d\u0442\u0430\u043f\u0430<\/h4>\n<p><img decoding=\"async\" class=\"formula inline\" source=\"F^{(0)} [3\\times1024]\" alt=\"F^{(0)} [3\\times1024]\" src=\"https:\/\/habrastorage.org\/extt\/79\/d6\/50\/79d650e6d3b0013ab758881e3992630c.svg\" width=\"116\" height=\"23\" data-width=\"13.732\" data-height=\"2.7\" data-vertical-align=\"-0.566\" style=\"width: 13.732ex; height: 2.7ex; vertical-align: -0.566ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/79\/d6\/50\/79d650e6d3b0013ab758881e3992630c.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/79\/d6\/50\/79d650e6d3b0013ab758881e3992630c.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<h3>\u042d\u0442\u0430\u043f C2. Joint-\u0441\u043b\u043e\u0438 \u00d74<\/h3>\n<figure class=\"full-width \"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/extt\/1a\/15\/8b\/1a158b42df8dc0a63b97e2be47aaabfc.png\" width=\"2360\" height=\"2486\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/extt\/1a\/15\/8b\/1a158b42df8dc0a63b97e2be47aaabfc.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/extt\/1a\/15\/8b\/1a158b42df8dc0a63b97e2be47aaabfc.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<p>\u041d\u0430 \u044d\u0442\u043e\u043c \u044d\u0442\u0430\u043f\u0435 \u0432\u043e\u043f\u0440\u043e\u0441\u044b \u0432\u043f\u0435\u0440\u0432\u044b\u0435 \u0443\u0437\u043d\u0430\u044e\u0442 \u0434\u0440\u0443\u0433 \u043e \u0434\u0440\u0443\u0433\u0435. \u041f\u043e\u043b\u044f \u043e\u0431\u043c\u0435\u043d\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0435\u0439 \u0438 \u0435\u0449\u0451 \u0440\u0430\u0437 \u0441\u0432\u0435\u0440\u044f\u044e\u0442\u0441\u044f \u0441 \u0442\u0435\u043a\u0441\u0442\u043e\u043c.<\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<th data-colwidth=\"50\" width=\"50\">\n<p align=\"left\">\u0412\u0445\u043e\u0434<\/p>\n<\/th>\n<th data-colwidth=\"50\" width=\"50\">\n<p align=\"center\">\u0420\u0430\u0437\u043c\u0435\u0440<\/p>\n<\/th>\n<\/tr>\n<tr>\n<td data-colwidth=\"50\" width=\"50\">\n<p align=\"left\"><img decoding=\"async\" class=\"formula inline\" source=\"F^{(0)} \" alt=\"F^{(0)} \" src=\"https:\/\/habrastorage.org\/extt\/aa\/ae\/87\/aaae875d070295d16bb21cad8547c49d.svg\" width=\"34\" height=\"18\" data-width=\"4.052\" data-height=\"2.134\" style=\"width: 4.052ex; height: 2.134ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/aa\/ae\/87\/aaae875d070295d16bb21cad8547c49d.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/aa\/ae\/87\/aaae875d070295d16bb21cad8547c49d.svg 781w\" loading=\"lazy\" decode=\"async\"\/> <\/p>\n<\/td>\n<td data-colwidth=\"50\" width=\"50\">\n<p align=\"center\"><img decoding=\"async\" class=\"formula inline\" source=\"3\\times1024\" alt=\"3\\times1024\" src=\"https:\/\/habrastorage.org\/extt\/ef\/24\/df\/ef24dfe3279349be16fd472a26c52459.svg\" width=\"71\" height=\"13\" data-width=\"8.422\" data-height=\"1.581\" data-vertical-align=\"-0.05\" style=\"width: 8.422ex; height: 1.581ex; vertical-align: -0.05ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/ef\/24\/df\/ef24dfe3279349be16fd472a26c52459.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/ef\/24\/df\/ef24dfe3279349be16fd472a26c52459.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"50\" width=\"50\">\n<p align=\"left\"><img decoding=\"async\" class=\"formula inline\" source=\"\\mathcal M\" alt=\"\\mathcal M\" src=\"https:\/\/habrastorage.org\/extt\/26\/64\/e5\/2664e52211404db347f1e17fb781eda0.svg\" width=\"23\" height=\"14\" data-width=\"2.717\" data-height=\"1.708\" data-vertical-align=\"-0.113\" style=\"width: 2.717ex; height: 1.708ex; vertical-align: -0.113ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/26\/64\/e5\/2664e52211404db347f1e17fb781eda0.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/26\/64\/e5\/2664e52211404db347f1e17fb781eda0.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<\/td>\n<td data-colwidth=\"50\" width=\"50\">\n<p align=\"center\"><img decoding=\"async\" class=\"formula inline\" source=\"N\\times1024\" alt=\"N\\times1024\" src=\"https:\/\/habrastorage.org\/extt\/f8\/be\/c7\/f8bec7d4d19f484c723ff415537fa6f7.svg\" width=\"79\" height=\"13\" data-width=\"9.3\" data-height=\"1.595\" data-vertical-align=\"-0.05\" style=\"width: 9.3ex; height: 1.595ex; vertical-align: -0.05ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/f8\/be\/c7\/f8bec7d4d19f484c723ff415537fa6f7.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/f8\/be\/c7\/f8bec7d4d19f484c723ff415537fa6f7.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">self.layers = torch.nn.ModuleList(    [        torch.nn.TransformerDecoderLayer(            d_model=width,            nhead=heads,            dim_feedforward=feedforward,            dropout=dropout,            activation=\"gelu\",            batch_first=True,            norm_first=True,        )        for _ in range(layers)    ])self.field_norm = torch.nn.LayerNorm(width)<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><span class=\"sc-logo-wrapper icon-only\"><\/span><\/a><\/div><\/pre>\n<p>\u0412\u044b\u0437\u043e\u0432 \u0432 <code>forward<\/code>:<\/p>\n<pre><code class=\"python\">fields = fields.unsqueeze(0)for layer in self.layers:    fields = layer(fields, memory)fields = self.field_norm(fields[0])<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><span class=\"sc-logo-wrapper icon-only\"><\/span><\/a><\/div><\/pre>\n<p><a href=\"https:\/\/docs.pytorch.org\/docs\/2.14\/generated\/torch.nn.TransformerDecoderLayer.html\" rel=\"noopener nofollow\"><code>TransformerDecoderLayer<\/code><\/a>&#8212;  \u0431\u0430\u0437\u043e\u0432\u044b\u0439 \u0441\u043b\u043e\u0439 \u0434\u0435\u043a\u043e\u0434\u0435\u0440\u043e\u0432 \u0432 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0435 Transformer.<\/p>\n<\/div>\n<\/details>\n<p><img decoding=\"async\" class=\"formula inline\" source=\"\\begin{aligned} F &amp;\\leftarrow F + \\mathrm{MHA}_{\\text{self}}\\big(\\mathrm{LN}_1 F,\\ \\mathrm{LN}_1 F,\\ \\mathrm{LN}_1 F\\big) \\\\ F &amp;\\leftarrow F + \\mathrm{MHA}_{\\text{cross}}\\big(\\mathrm{LN}_2 F,\\ \\mathcal{M},\\ \\mathcal{M}\\big) \\\\ F &amp;\\leftarrow F + W_2\\,\\mathrm{GELU}\\big(W_1\\,\\mathrm{LN}_3 F + b_1\\big) + b_2 \\end{aligned}\" alt=\"\\begin{aligned} F &amp;\\leftarrow F + \\mathrm{MHA}_{\\text{self}}\\big(\\mathrm{LN}_1 F,\\ \\mathrm{LN}_1 F,\\ \\mathrm{LN}_1 F\\big) \\\\ F &amp;\\leftarrow F + \\mathrm{MHA}_{\\text{cross}}\\big(\\mathrm{LN}_2 F,\\ \\mathcal{M},\\ \\mathcal{M}\\big) \\\\ F &amp;\\leftarrow F + W_2\\,\\mathrm{GELU}\\big(W_1\\,\\mathrm{LN}_3 F + b_1\\big) + b_2 \\end{aligned}\" src=\"https:\/\/habrastorage.org\/extt\/0d\/0e\/2b\/0d0e2b8f6b0e060fb902329462c252e9.svg\" width=\"342\" height=\"80\" data-width=\"40.418\" data-height=\"9.495\" data-vertical-align=\"-4.182\" style=\"width: 40.418ex; height: 9.495ex; vertical-align: -4.182ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/0d\/0e\/2b\/0d0e2b8f6b0e060fb902329462c252e9.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/0d\/0e\/2b\/0d0e2b8f6b0e060fb902329462c252e9.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<h3>1. Self-attention: \u0432\u043e\u043f\u0440\u043e\u0441\u044b \u0441\u043c\u043e\u0442\u0440\u044f\u0442 \u0434\u0440\u0443\u0433 \u043d\u0430 \u0434\u0440\u0443\u0433\u0430<\/h3>\n<p>\u0417\u0430\u043f\u0440\u043e\u0441\u044b, \u043a\u043b\u044e\u0447\u0438 \u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0431\u0435\u0440\u0443\u0442\u0441\u044f \u0438\u0437 \u043e\u0434\u043d\u0438\u0445 \u0438 \u0442\u0435\u0445 \u0436\u0435 \u043f\u043e\u043b\u0435\u0439 (16 \u0433\u043e\u043b\u043e\u0432 \u043f\u043e 64), \u043c\u0430\u0442\u0440\u0438\u0446\u0430 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0433\u043e\u043b\u043e\u0432\u044b \u0438\u043c\u0435\u0435\u0442 \u0440\u0430\u0437\u043c\u0435\u0440:<\/p>\n<p><img decoding=\"async\" class=\"formula inline\" source=\"A_i=\\mathrm{softmax}\\Big(\\frac{Q_iK_i^\\top}{\\sqrt{64}}\\Big)\\quad[3\\times3]\" alt=\"A_i=\\mathrm{softmax}\\Big(\\frac{Q_iK_i^\\top}{\\sqrt{64}}\\Big)\\quad[3\\times3]\" src=\"https:\/\/habrastorage.org\/extt\/1c\/07\/bc\/1c07bc22485fbc33ba4f3a0e66a38c7a.svg\" width=\"267\" height=\"50\" data-width=\"31.595\" data-height=\"5.899\" data-vertical-align=\"-2.308\" style=\"width: 31.595ex; height: 5.899ex; vertical-align: -2.308ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/1c\/07\/bc\/1c07bc22485fbc33ba4f3a0e66a38c7a.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/1c\/07\/bc\/1c07bc22485fbc33ba4f3a0e66a38c7a.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<p>\u0421\u0442\u0440\u043e\u043a\u0430 &#8212; \u043a\u0442\u043e \u0441\u043c\u043e\u0442\u0440\u0438\u0442, \u0441\u0442\u043e\u043b\u0431\u0435\u0446 &#8212; \u043d\u0430 \u043a\u043e\u0433\u043e. \u041a\u0430\u0436\u0434\u043e\u0435 \u043f\u043e\u043b\u0435 \u0441\u043c\u043e\u0442\u0440\u0438\u0442 \u043d\u0430 \u0432\u0441\u0435 \u0442\u0440\u0438, \u0432\u043a\u043b\u044e\u0447\u0430\u044f \u0441\u0435\u0431\u044f.<\/p>\n<h3>2. Cross-attention: \u043f\u043e\u043b\u044f \u0447\u0438\u0442\u0430\u044e\u0442 \u0442\u0435\u043a\u0441\u0442<\/h3>\n<p><img decoding=\"async\" class=\"formula inline\" source=\"Q=\\hat FW^Q\\ [3\\times1024],\\qquad K=\\mathcal MW^K,\\ V=\\mathcal MW^V\\ [N\\times1024],\\qquad A_i\\ [3\\times N]\" alt=\"Q=\\hat FW^Q\\ [3\\times1024],\\qquad K=\\mathcal MW^K,\\ V=\\mathcal MW^V\\ [N\\times1024],\\qquad A_i\\ [3\\times N]\" src=\"https:\/\/habrastorage.org\/extt\/cc\/a5\/9f\/cca59fdb96b39d557aba83d6b6259bf8.svg\" width=\"658\" height=\"25\" data-width=\"77.858\" data-height=\"2.937\" data-vertical-align=\"-0.566\" style=\"width: 77.858ex; height: 2.937ex; vertical-align: -0.566ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/cc\/a5\/9f\/cca59fdb96b39d557aba83d6b6259bf8.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/cc\/a5\/9f\/cca59fdb96b39d557aba83d6b6259bf8.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<p>\u0421\u043c\u044b\u0441\u043b: \u043f\u043e\u0441\u043b\u0435 \u043f\u043e\u0434\u0431\u043b\u043e\u043a\u0430 1 \u043f\u043e\u043b\u0435 \u0443\u0436\u0435 \u0437\u043d\u0430\u0435\u0442, \u0447\u0442\u043e \u0434\u0443\u043c\u0430\u044e\u0442 \u0434\u0440\u0443\u0433\u0438\u0435 \u0432\u043e\u043f\u0440\u043e\u0441\u044b, \u0438 \u043f\u0435\u0440\u0435\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442 \u0442\u0435\u043a\u0441\u0442 \u0441 \u044d\u0442\u0438\u043c \u0437\u043d\u0430\u043d\u0438\u0435\u043c. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u043e\u043b\u0435 severity, \u043f\u043e\u043b\u0443\u0447\u0438\u0432 \u043e\u0442 urgent \u0441\u0438\u0433\u043d\u0430\u043b \u00ab\u0441\u0440\u043e\u0447\u043d\u043e\u00bb, \u043c\u043e\u0436\u0435\u0442 \u0432\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u0435\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 \u00abevery customer\u00bb.<\/p>\n<h3>3. FFN<\/h3>\n<p><img decoding=\"async\" class=\"formula inline\" source=\"1024\\to4096\\to1024\" alt=\"1024\\to4096\\to1024\" src=\"https:\/\/habrastorage.org\/extt\/e6\/b5\/05\/e6b505ff03604cdc839ccb5232a8d5ab.svg\" width=\"174\" height=\"13\" data-width=\"20.613\" data-height=\"1.581\" data-vertical-align=\"-0.05\" style=\"width: 20.613ex; height: 1.581ex; vertical-align: -0.05ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/e6\/b5\/05\/e6b505ff03604cdc839ccb5232a8d5ab.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/e6\/b5\/05\/e6b505ff03604cdc839ccb5232a8d5ab.svg 781w\" loading=\"lazy\" decode=\"async\"\/> \u0441 GELU \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u043e\u043b\u044f.<\/p>\n<h4>\u0412\u044b\u0445\u043e\u0434 \u044d\u0442\u0430\u043f\u0430<\/h4>\n<p><img decoding=\"async\" class=\"formula inline\" source=\"F [3\\times1024]\" alt=\"F [3\\times1024]\" src=\"https:\/\/habrastorage.org\/extt\/79\/f3\/5c\/79f35ccdc20af3d44b2e8087e0399949.svg\" width=\"96\" height=\"19\" data-width=\"11.374\" data-height=\"2.262\" data-vertical-align=\"-0.566\" style=\"width: 11.374ex; height: 2.262ex; vertical-align: -0.566ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/79\/f3\/5c\/79f35ccdc20af3d44b2e8087e0399949.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/79\/f3\/5c\/79f35ccdc20af3d44b2e8087e0399949.svg 781w\" loading=\"lazy\" decode=\"async\"\/> &#8212; \u0444\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u043e\u043b\u044f.<\/p>\n<h3>\u042d\u0442\u0430\u043f D. \u0421\u043a\u043e\u0440\u0438\u043d\u0433 \u043a\u0430\u0436\u0434\u043e\u0439 \u043e\u043f\u0446\u0438\u0438<\/h3>\n<figure class=\"full-width \"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/extt\/99\/7a\/80\/997a80ca438b385fcfbfbaa92ef833ad.png\" width=\"2360\" height=\"2486\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/extt\/99\/7a\/80\/997a80ca438b385fcfbfbaa92ef833ad.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/extt\/99\/7a\/80\/997a80ca438b385fcfbfbaa92ef833ad.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<th>\n<p align=\"left\">\u0412\u0445\u043e\u0434<\/p>\n<\/th>\n<th>\n<p align=\"left\">\u0420\u0430\u0437\u043c\u0435\u0440<\/p>\n<\/th>\n<th>\n<p align=\"left\">\u041f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u043e<\/p>\n<\/th>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\"><img decoding=\"async\" class=\"formula inline\" source=\"f_k\" alt=\"f_k\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/f\/f5\/f55\/f55fcd9745b34e40639d81c49eb07a8e.svg\" width=\"17\" height=\"16\" data-width=\"2.13\" data-height=\"2.059\" data-vertical-align=\"-0.464\" style=\"width: 2.13ex; height: 2.059ex; vertical-align: -0.464ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/f\/f5\/f55\/f55fcd9745b34e40639d81c49eb07a8e.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/f\/f5\/f55\/f55fcd9745b34e40639d81c49eb07a8e.svg 781w\" loading=\"lazy\" decode=\"async\"\/> &#8212; \u0444\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0435 \u043f\u043e\u043b\u0435<\/p>\n<\/td>\n<td>\n<p align=\"left\">1024<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0433\u043e\u043b\u043e\u0432\u0430 Clef<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\"><img decoding=\"async\" class=\"formula inline\" source=\"r_{kj} \" alt=\"r_{kj} \" src=\"https:\/\/habrastorage.org\/extt\/da\/b2\/02\/dab2025d8d072215896fcc831e986c90.svg\" width=\"23\" height=\"14\" data-width=\"2.701\" data-height=\"1.666\" data-vertical-align=\"-0.666\" style=\"width: 2.701ex; height: 1.666ex; vertical-align: -0.666ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/da\/b2\/02\/dab2025d8d072215896fcc831e986c90.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/da\/b2\/02\/dab2025d8d072215896fcc831e986c90.svg 781w\" loading=\"lazy\" decode=\"async\"\/>&#8212; \u0432\u043e\u043f\u0440\u043e\u0441\u0430<\/p>\n<\/td>\n<td>\n<p align=\"left\"><img decoding=\"async\" class=\"formula inline\" source=\"n_k\\times1024\" alt=\"n_k\\times1024\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/2\/29\/29e\/29eeb3c32fcca5a31899eb8eb40b0b90.svg\" width=\"77\" height=\"18\" data-width=\"9.669\" data-height=\"2.262\" data-vertical-align=\"-0.566\" style=\"width: 9.669ex; height: 2.262ex; vertical-align: -0.566ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/2\/29\/29e\/29eeb3c32fcca5a31899eb8eb40b0b90.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/2\/29\/29e\/29eeb3c32fcca5a31899eb8eb40b0b90.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0433\u043e\u043b\u043e\u0432\u0430 Clef<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\"><img decoding=\"async\" class=\"formula inline\" source=\"\\ell_{kj}\" alt=\"\\ell_{kj}\" src=\"https:\/\/habrastorage.org\/extt\/a9\/52\/d5\/a952d5164bbb00e38ec3b2cdb4ef3c7e.svg\" width=\"22\" height=\"19\" data-width=\"2.624\" data-height=\"2.261\" data-vertical-align=\"-0.666\" style=\"width: 2.624ex; height: 2.261ex; vertical-align: -0.666ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/a9\/52\/d5\/a952d5164bbb00e38ec3b2cdb4ef3c7e.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/a9\/52\/d5\/a952d5164bbb00e38ec3b2cdb4ef3c7e.svg 781w\" loading=\"lazy\" decode=\"async\"\/> &#8212; \u043b\u0435\u043a\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0432\u0435\u043a\u0442\u043e\u0440\u044b<\/p>\n<\/td>\n<td>\n<p align=\"left\"><img decoding=\"async\" class=\"formula inline\" source=\"n_k\\times5120\" alt=\"n_k\\times5120\" src=\"https:\/\/habrastorage.org\/extt\/a3\/80\/46\/a38046144c1ef7c4a54abe7725a99283.svg\" width=\"82\" height=\"16\" data-width=\"9.669\" data-height=\"1.864\" data-vertical-align=\"-0.357\" style=\"width: 9.669ex; height: 1.864ex; vertical-align: -0.357ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/a3\/80\/46\/a38046144c1ef7c4a54abe7725a99283.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/a3\/80\/46\/a38046144c1ef7c4a54abe7725a99283.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<\/td>\n<td>\n<p align=\"left\">Qwen<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\"><img decoding=\"async\" class=\"formula inline\" source=\"q_k\" alt=\"q_k\" src=\"https:\/\/habrastorage.org\/extt\/dd\/c8\/7b\/ddc87b504de8eb7e4de22df76673e654.svg\" width=\"17\" height=\"12\" data-width=\"2.03\" data-height=\"1.439\" data-vertical-align=\"-0.439\" style=\"width: 2.03ex; height: 1.439ex; vertical-align: -0.439ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/dd\/c8\/7b\/ddc87b504de8eb7e4de22df76673e654.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/dd\/c8\/7b\/ddc87b504de8eb7e4de22df76673e654.svg 781w\" loading=\"lazy\" decode=\"async\"\/> &#8212; \u0432\u0435\u043a\u0442\u043e\u0440 \u0432\u043e\u043f\u0440\u043e\u0441\u0430<\/p>\n<\/td>\n<td>\n<p align=\"left\">5120<\/p>\n<\/td>\n<td>\n<p align=\"left\">Qwen<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\"><img decoding=\"async\" class=\"formula inline\" source=\"g\" alt=\"g\" src=\"https:\/\/habrastorage.org\/extt\/56\/7a\/30\/567a30754edd1214f7ab31aca3acd30a.svg\" width=\"9\" height=\"12\" data-width=\"1.079\" data-height=\"1.464\" data-vertical-align=\"-0.464\" style=\"width: 1.079ex; height: 1.464ex; vertical-align: -0.464ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/56\/7a\/30\/567a30754edd1214f7ab31aca3acd30a.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/56\/7a\/30\/567a30754edd1214f7ab31aca3acd30a.svg 781w\" loading=\"lazy\" decode=\"async\"\/> &#8212; \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0442\u043e\u043a\u0435\u043d<\/p>\n<\/td>\n<td>\n<p align=\"left\">5120<\/p>\n<\/td>\n<td>\n<p align=\"left\">Qwen<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434<\/summary>\n<div class=\"spoiler__content\">\n<p>\u041e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u043a\u043e\u0440\u0435\u0440\u0430 \u0438 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u043e\u0432 \u0432 <code><strong>_init_<\/strong><\/code>:<\/p>\n<pre><code class=\"python\">self.field_norm = torch.nn.LayerNorm(width)self.option_norm = torch.nn.LayerNorm(width)self.residual_scorer = torch.nn.Sequential(    torch.nn.Linear(width * 4, width),    torch.nn.GELU(),    torch.nn.Dropout(dropout),    torch.nn.Linear(width, 1),)self.prior_logit_scale = torch.nn.Parameter(torch.zeros(()))self.joint_logit_scale = torch.nn.Parameter(torch.zeros(()))self.residual_gate = torch.nn.Parameter(torch.zeros(()))<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><span class=\"sc-logo-wrapper icon-only\"><\/span><\/a><\/div><\/pre>\n<p> \u0432 <code>forward<\/code>:<\/p>\n<pre><code class=\"python\">record_logits: list[torch.Tensor] = []for field, question, lexical, routed in zip(    fields,    record.questions,    lexical_options,    split_options,):    anchor = functional.normalize(        question_vectors[len(record_logits)] + global_vector,        dim=-1,    )    lexical_anchor = functional.normalize(lexical, dim=-1)    prior_scale = self.prior_logit_scale.clamp(max=math.log(100.0)).exp()    prior = prior_scale * torch.matmul(lexical_anchor, anchor)    options = self.option_norm(routed)    repeated_field = field.unsqueeze(0).expand_as(options)    cosine = functional.cosine_similarity(repeated_field, options, dim=-1)    features = torch.cat(        [            repeated_field,            options,            repeated_field * options,            torch.abs(repeated_field - options),        ],        dim=-1,    )    residual = self.residual_scorer(features).squeeze(-1)    joint_scale = self.joint_logit_scale.clamp(max=math.log(100.0)).exp()    joint = joint_scale * cosine + residual    record_logits.append(        prior + torch.sigmoid(self.residual_gate) * joint    )results.append(record_logits)return results<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><span class=\"sc-logo-wrapper icon-only\"><\/span><\/a><\/div><\/pre>\n<\/div>\n<\/details>\n<p>\u041b\u043e\u0433\u0438\u0442 \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u0442\u0441\u044f \u0438\u0437 \u0434\u0432\u0443\u0445 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b\u0445 \u0447\u0430\u0441\u0442\u0435\u0439:<\/p>\n<ul>\n<li>\n<p><strong>prior<\/strong> \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0441<img decoding=\"async\" class=\"formula inline\" source=\" \\ell\" alt=\" \\ell\" src=\"https:\/\/habrastorage.org\/extt\/a5\/ec\/67\/a5ec671b7d925b2d78f096d9f14a4d15.svg\" width=\"8\" height=\"14\" data-width=\"0.943\" data-height=\"1.64\" data-vertical-align=\"-0.045\" style=\"width: 0.943ex; height: 1.64ex; vertical-align: -0.045ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/a5\/ec\/67\/a5ec671b7d925b2d78f096d9f14a4d15.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/a5\/ec\/67\/a5ec671b7d925b2d78f096d9f14a4d15.svg 781w\" loading=\"lazy\" decode=\"async\"\/>, <img decoding=\"async\" class=\"formula inline\" source=\"q\" alt=\"q\" src=\"https:\/\/habrastorage.org\/extt\/9d\/71\/a9\/9d71a9745294681e4b4e283e7c9e978d.svg\" width=\"9\" height=\"12\" data-width=\"1.041\" data-height=\"1.439\" data-vertical-align=\"-0.439\" style=\"width: 1.041ex; height: 1.439ex; vertical-align: -0.439ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/9d\/71\/a9\/9d71a9745294681e4b4e283e7c9e978d.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/9d\/71\/a9\/9d71a9745294681e4b4e283e7c9e978d.svg 781w\" loading=\"lazy\" decode=\"async\"\/>, <img decoding=\"async\" class=\"formula inline\" source=\"g\" alt=\"g\" src=\"https:\/\/habrastorage.org\/extt\/a8\/94\/6a\/a8946acc550fd88d44e4bf5ad5f176ce.svg\" width=\"9\" height=\"12\" data-width=\"1.079\" data-height=\"1.464\" data-vertical-align=\"-0.464\" style=\"width: 1.079ex; height: 1.464ex; vertical-align: -0.464ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/a8\/94\/6a\/a8946acc550fd88d44e4bf5ad5f176ce.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/a8\/94\/6a\/a8946acc550fd88d44e4bf5ad5f176ce.svg 781w\" loading=\"lazy\" decode=\"async\"\/> \u0432 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0435 Qwen (5120);<\/p>\n<\/li>\n<li>\n<p><strong>joint<\/strong> \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0441 <img decoding=\"async\" class=\"formula inline\" source=\"f\" alt=\"f\" src=\"https:\/\/habrastorage.org\/extt\/91\/53\/6e\/91536e143b86216c572ab297370c795b.svg\" width=\"11\" height=\"17\" data-width=\"1.244\" data-height=\"2.059\" data-vertical-align=\"-0.464\" style=\"width: 1.244ex; height: 2.059ex; vertical-align: -0.464ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/91\/53\/6e\/91536e143b86216c572ab297370c795b.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/91\/53\/6e\/91536e143b86216c572ab297370c795b.svg 781w\" loading=\"lazy\" decode=\"async\"\/> \u0438 <img decoding=\"async\" class=\"formula inline\" source=\"r\" alt=\"r\" src=\"https:\/\/habrastorage.org\/extt\/ef\/1c\/0c\/ef1c0cebf59203cb7d124b136813d43b.svg\" width=\"9\" height=\"9\" data-width=\"1.02\" data-height=\"1.025\" data-vertical-align=\"-0.025\" style=\"width: 1.02ex; height: 1.025ex; vertical-align: -0.025ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/ef\/1c\/0c\/ef1c0cebf59203cb7d124b136813d43b.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/ef\/1c\/0c\/ef1c0cebf59203cb7d124b136813d43b.svg 781w\" loading=\"lazy\" decode=\"async\"\/> \u0432 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0435 \u0433\u043e\u043b\u043e\u0432\u044b (1024).<\/p>\n<\/li>\n<\/ul>\n<h4>\u0427\u0430\u0441\u0442\u044c 1. \u041b\u0435\u043a\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0439 prior<\/h4>\n<p><img decoding=\"async\" class=\"formula inline\" source=\"a_k = \\frac{q_k + g}{\\lvert q_k + g \\rvert}, \\qquad \\lambda_{kj} = \\frac{\\ell_{kj}}{\\lvert \\ell_{kj} \\rvert}, \\qquad \\pi_{kj} = s_p \\cdot \\big(\\lambda_{kj} \\cdot a_k\\big),\\qquad s_p=e^{\\min(\\theta_p,\\ \\ln100)}\" alt=\"a_k = \\frac{q_k + g}{\\lvert q_k + g \\rvert}, \\qquad \\lambda_{kj} = \\frac{\\ell_{kj}}{\\lvert \\ell_{kj} \\rvert}, \\qquad \\pi_{kj} = s_p \\cdot \\big(\\lambda_{kj} \\cdot a_k\\big),\\qquad s_p=e^{\\min(\\theta_p,\\ \\ln100)}\" src=\"https:\/\/habrastorage.org\/extt\/10\/39\/23\/1039232bb53e98ebab160ee49ab307c8.svg\" width=\"644\" height=\"47\" data-width=\"76.238\" data-height=\"5.572\" data-vertical-align=\"-2.271\" style=\"width: 76.238ex; height: 5.572ex; vertical-align: -2.271ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/10\/39\/23\/1039232bb53e98ebab160ee49ab307c8.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/10\/39\/23\/1039232bb53e98ebab160ee49ab307c8.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<p><img decoding=\"async\" class=\"formula inline\" source=\"a_k\" alt=\"a_k\" src=\"https:\/\/habrastorage.org\/extt\/e6\/ab\/24\/e6ab2499441cf6f5617689ecff3af9bc.svg\" width=\"19\" height=\"11\" data-width=\"2.218\" data-height=\"1.355\" data-vertical-align=\"-0.357\" style=\"width: 2.218ex; height: 1.355ex; vertical-align: -0.357ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/e6\/ab\/24\/e6ab2499441cf6f5617689ecff3af9bc.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/e6\/ab\/24\/e6ab2499441cf6f5617689ecff3af9bc.svg 781w\" loading=\"lazy\" decode=\"async\"\/>&#8212; \u0441\u043c\u044b\u0441\u043b \u0432\u043e\u043f\u0440\u043e\u0441\u0430 \u043f\u043b\u044e\u0441 \u0441\u043c\u044b\u0441\u043b \u0432\u0441\u0435\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430. <\/p>\n<p>\u041b\u0435\u043a\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0432\u0435\u043a\u0442\u043e\u0440<img decoding=\"async\" class=\"formula inline\" source=\" \\lambda_{kj}\" alt=\" \\lambda_{kj}\" src=\"https:\/\/habrastorage.org\/extt\/2e\/20\/1a\/2e201aae8b34e322d2c85edd0a010570.svg\" width=\"25\" height=\"19\" data-width=\"2.999\" data-height=\"2.236\" data-vertical-align=\"-0.666\" style=\"width: 2.999ex; height: 2.236ex; vertical-align: -0.666ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/2e\/20\/1a\/2e201aae8b34e322d2c85edd0a010570.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/2e\/20\/1a\/2e201aae8b34e322d2c85edd0a010570.svg 781w\" loading=\"lazy\" decode=\"async\"\/> &#8212; \u0441\u043b\u043e\u0432\u0430\u0440\u043d\u044b\u0439 \u0441\u043c\u044b\u0441\u043b \u0441\u043b\u043e\u0432 \u043e\u043f\u0446\u0438\u0438 \u0431\u0435\u0437 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430.<\/p>\n<p><img decoding=\"async\" class=\"formula inline\" source=\"s_p\" alt=\"s_p\" src=\"https:\/\/habrastorage.org\/extt\/43\/25\/5d\/43255d0321ef669c7ae1711dac824d43.svg\" width=\"17\" height=\"14\" data-width=\"2.054\" data-height=\"1.65\" data-vertical-align=\"-0.65\" style=\"width: 2.054ex; height: 1.65ex; vertical-align: -0.65ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/43\/25\/5d\/43255d0321ef669c7ae1711dac824d43.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/43\/25\/5d\/43255d0321ef669c7ae1711dac824d43.svg 781w\" loading=\"lazy\" decode=\"async\"\/> &#8212; \u043e\u0431\u0443\u0447\u0430\u0435\u043c\u044b\u0439 \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f<\/p>\n<h4>\u0427\u0430\u0441\u0442\u044c 2. \u0421\u043e\u0432\u043c\u0435\u0441\u0442\u043d\u0430\u044f \u043e\u0446\u0435\u043d\u043a\u0430<\/h4>\n<p><strong>2a. \u041d\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u043a\u0430 \u043e\u043f\u0446\u0438\u0439:<\/strong> <img decoding=\"async\" class=\"formula inline\" source=\"o_{kj}=\\mathrm{LN}_o(r_{kj}) \" alt=\"o_{kj}=\\mathrm{LN}_o(r_{kj}) \" src=\"https:\/\/habrastorage.org\/extt\/01\/69\/06\/0169064fcc633fac67676b4bbd56a69d.svg\" width=\"121\" height=\"20\" data-width=\"14.33\" data-height=\"2.363\" data-vertical-align=\"-0.666\" style=\"width: 14.33ex; height: 2.363ex; vertical-align: -0.666ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/01\/69\/06\/0169064fcc633fac67676b4bbd56a69d.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/01\/69\/06\/0169064fcc633fac67676b4bbd56a69d.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<p><strong>2b. \u0421\u0445\u043e\u0436\u0435\u0441\u0442\u044c \u043f\u043e\u043b\u044f \u0438 \u043e\u043f\u0446\u0438\u0438<\/strong>:<\/p>\n<p><img decoding=\"async\" class=\"formula inline\" source=\"\\kappa_{kj} = \\cos(f_k, o_{kj}) = \\frac{f_k \\cdot o_{kj}}{\\lvert f_k \\rvert \\, \\lvert o_{kj} \\rvert}\" alt=\"\\kappa_{kj} = \\cos(f_k, o_{kj}) = \\frac{f_k \\cdot o_{kj}}{\\lvert f_k \\rvert \\, \\lvert o_{kj} \\rvert}\" src=\"https:\/\/habrastorage.org\/extt\/f6\/8e\/74\/f68e743482c5db4e8fab66156f162362.svg\" width=\"241\" height=\"47\" data-width=\"28.515\" data-height=\"5.572\" data-vertical-align=\"-2.271\" style=\"width: 28.515ex; height: 5.572ex; vertical-align: -2.271ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/f6\/8e\/74\/f68e743482c5db4e8fab66156f162362.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/f6\/8e\/74\/f68e743482c5db4e8fab66156f162362.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<p><strong>2c. MLP (residual_scorer \u0432 \u043a\u043e\u0434\u0435) \u043f\u043e \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0430\u043c \u043f\u0430\u0440\u044b.<\/strong> \u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u043f\u0430\u0440\u044b \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u0442\u0441\u044f \u0432\u0435\u043a\u0442\u043e\u0440 \u0434\u043b\u0438\u043d\u043e\u0439 4096:<\/p>\n<p><img decoding=\"async\" class=\"formula inline\" source=\"\\phi_{kj} = \\big[\\, f_k \\; ; \\; o_{kj} \\; ; \\; f_k \\odot o_{kj} \\; ; \\; \\lvert f_k - o_{kj} \\rvert \\,\\big]\" alt=\"\\phi_{kj} = \\big[\\, f_k \\; ; \\; o_{kj} \\; ; \\; f_k \\odot o_{kj} \\; ; \\; \\lvert f_k - o_{kj} \\rvert \\,\\big]\" src=\"https:\/\/habrastorage.org\/extt\/b9\/63\/8e\/b9638ee55629bfb34e751fa63d631082.svg\" width=\"313\" height=\"23\" data-width=\"36.992\" data-height=\"2.713\" data-vertical-align=\"-0.791\" style=\"width: 36.992ex; height: 2.713ex; vertical-align: -0.791ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/b9\/63\/8e\/b9638ee55629bfb34e751fa63d631082.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/b9\/63\/8e\/b9638ee55629bfb34e751fa63d631082.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<p><img decoding=\"async\" class=\"formula inline\" source=\"\\rho_{kj} = v^\\top \\mathrm{GELU}\\big(W_r \\phi_{kj} + b_r\\big) + b, \\qquad W_r \\in \\mathbb{R}^{1024 \\times 4096}, \\quad v \\in \\mathbb{R}^{1024}\" alt=\"\\rho_{kj} = v^\\top \\mathrm{GELU}\\big(W_r \\phi_{kj} + b_r\\big) + b, \\qquad W_r \\in \\mathbb{R}^{1024 \\times 4096}, \\quad v \\in \\mathbb{R}^{1024}\" src=\"https:\/\/habrastorage.org\/extt\/da\/5b\/d1\/da5bd1777307c1c3258af7a967628b26.svg\" width=\"543\" height=\"24\" data-width=\"64.312\" data-height=\"2.808\" data-vertical-align=\"-0.791\" style=\"width: 64.312ex; height: 2.808ex; vertical-align: -0.791ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/da\/5b\/d1\/da5bd1777307c1c3258af7a967628b26.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/da\/5b\/d1\/da5bd1777307c1c3258af7a967628b26.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<p><strong>2d. \u0421\u0431\u043e\u0440\u043a\u0430 joint:<\/strong><\/p>\n<p><img decoding=\"async\" class=\"formula inline\" source=\"\\eta_{kj} = s_j \\cdot \\kappa_{kj} + \\rho_{kj}, \\qquad s_j = e^{\\min(\\theta_j,\\ \\ln 100)}\" alt=\"\\eta_{kj} = s_j \\cdot \\kappa_{kj} + \\rho_{kj}, \\qquad s_j = e^{\\min(\\theta_j,\\ \\ln 100)}\" src=\"https:\/\/habrastorage.org\/extt\/40\/22\/30\/402230fadc781ba3df9774a3f333a8ac.svg\" width=\"338\" height=\"24\" data-width=\"40.034\" data-height=\"2.8\" data-vertical-align=\"-0.666\" style=\"width: 40.034ex; height: 2.8ex; vertical-align: -0.666ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/40\/22\/30\/402230fadc781ba3df9774a3f333a8ac.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/40\/22\/30\/402230fadc781ba3df9774a3f333a8ac.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<h4>\u0418\u0442\u043e\u0433\u043e\u0432\u044b\u0439 \u043b\u043e\u0433\u0438\u0442<\/h4>\n<p><img decoding=\"async\" class=\"formula inline\" source=\"z_{kj} = \\pi_{kj} + \\sigma(\\gamma) \\cdot \\eta_{kj}\" alt=\"z_{kj} = \\pi_{kj} + \\sigma(\\gamma) \\cdot \\eta_{kj}\" src=\"https:\/\/habrastorage.org\/extt\/8b\/11\/57\/8b1157d636991650e8ff312bd3d6373c.svg\" width=\"171\" height=\"20\" data-width=\"20.205\" data-height=\"2.363\" data-vertical-align=\"-0.666\" style=\"width: 20.205ex; height: 2.363ex; vertical-align: -0.666ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/8b\/11\/57\/8b1157d636991650e8ff312bd3d6373c.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/8b\/11\/57\/8b1157d636991650e8ff312bd3d6373c.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<p><img decoding=\"async\" class=\"formula inline\" source=\"\\sigma(\\gamma)\" alt=\"\\sigma(\\gamma)\" src=\"https:\/\/habrastorage.org\/extt\/fe\/cd\/b7\/fecdb720df840a225e88417ff999145a.svg\" width=\"36\" height=\"19\" data-width=\"4.281\" data-height=\"2.262\" data-vertical-align=\"-0.566\" style=\"width: 4.281ex; height: 2.262ex; vertical-align: -0.566ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/fe\/cd\/b7\/fecdb720df840a225e88417ff999145a.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/fe\/cd\/b7\/fecdb720df840a225e88417ff999145a.svg 781w\" loading=\"lazy\" decode=\"async\"\/> &#8212; \u043e\u0431\u0443\u0447\u0430\u0435\u043c\u044b\u0439 \u0432\u0435\u0441 \u0441\u043c\u0435\u0448\u0438\u0432\u0430\u043d\u0438\u044f<\/p>\n<h4>\u0412\u044b\u0445\u043e\u0434 \u044d\u0442\u0430\u043f\u0430<\/h4>\n<p>\u0421\u043f\u0438\u0441\u043e\u043a \u0442\u0435\u043d\u0437\u043e\u0440\u043e\u0432:<\/p>\n<pre><code>record_logits = [ z_urgent [2],  z_team [3],  z_severity [4] ]<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><span class=\"sc-logo-wrapper icon-only\"><\/span><\/a><\/div><\/pre>\n<h3>\u042d\u0442\u0430\u043f 3. Softmax \u0438 \u043e\u0442\u0432\u0435\u0442<\/h3>\n<figure class=\"full-width \"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/extt\/e0\/fc\/b6\/e0fcb64efe1ed6ea5ae5e6c86478b24a.png\" width=\"2360\" height=\"2486\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/extt\/e0\/fc\/b6\/e0fcb64efe1ed6ea5ae5e6c86478b24a.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/extt\/e0\/fc\/b6\/e0fcb64efe1ed6ea5ae5e6c86478b24a.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<p>\u041f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 Softmax \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u0432\u043e\u043f\u0440\u043e\u0441\u0430:<\/p>\n<p><img decoding=\"async\" class=\"formula inline\" source=\"p_{kj} = \\frac{e^{z_{kj}}}{\\sum_{j'=1}^{n_k} e^{z_{kj'}}}\" alt=\"p_{kj} = \\frac{e^{z_{kj}}}{\\sum_{j'=1}^{n_k} e^{z_{kj'}}}\" src=\"https:\/\/habrastorage.org\/extt\/27\/60\/7e\/27607e1a3039372aceb11a0c8f73f38f.svg\" width=\"140\" height=\"49\" data-width=\"16.512\" data-height=\"5.756\" data-vertical-align=\"-2.698\" style=\"width: 16.512ex; height: 5.756ex; vertical-align: -2.698ex\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/extt\/27\/60\/7e\/27607e1a3039372aceb11a0c8f73f38f.svg 780w,&#10;       https:\/\/habrastorage.org\/extt\/27\/60\/7e\/27607e1a3039372aceb11a0c8f73f38f.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<p>\u0418 \u0432\u043e\u0437\u0432\u0440\u0430\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e:<\/p>\n<pre><code class=\"python\">def systemone_answer(question: dict[str, Any], probabilities: dict[str, float]) -&gt; dict[str, Any]:    \"\"\"Convert per-option probabilities for one question into a SystemOne answer.\"\"\"    if question[\"type\"] == \"noul\":        return {\"type\": \"noul\", \"noul\": round(probabilities[\"true\"], 4)}    if question[\"type\"] == \"choice\":        options = [str(option) for option in question[\"criteria\"]]        choice = max(options, key=probabilities.__getitem__)        return {            \"type\": \"choice\",            \"choice\": choice,            \"confidence\": round(probabilities[choice], 4),            \"probabilities\": {option: round(probabilities[option], 4) for option in options},        }    levels = [str(index) for index in range(len(question[\"criteria\"]))]    return {        \"type\": \"score\",        \"score\": round(sum(index * probabilities[level] for index, level in enumerate(levels)), 4),        \"confidence\": round(max(probabilities[level] for level in levels), 4),        \"legend\": dict(zip(levels, question[\"criteria\"])),        \"probabilities\": {level: round(probabilities[level], 4) for level in levels},    }<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><span class=\"sc-logo-wrapper icon-only\"><\/span><\/a><\/div><\/pre>\n<h3>\u0412\u044b\u0432\u043e\u0434<\/h3>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u043f\u043e\u0441\u0442\u0430\u0440\u0430\u043b\u0441\u044f \u043e\u0441\u0432\u0435\u0442\u0438\u0442\u044c \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0440\u0430\u0431\u043e\u0442\u044b \u043c\u043e\u0434\u0435\u043b\u0438 \u043f\u0440\u0438\u043d\u044f\u0442\u0438\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u0439 Clef. \u0415\u0441\u043b\u0438 \u0432\u044b \u0437\u0430\u043c\u0435\u0442\u0438\u043b\u0438 \u043d\u0435\u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c \u0432 \u0438\u0437\u043b\u0430\u0433\u0430\u0435\u043c\u043e\u043c \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0435 &#8212; \u0431\u0443\u0434\u0443 \u0440\u0430\u0434 \u0443\u0441\u043b\u044b\u0448\u0430\u0442\u044c \u0432\u0430\u0448\u0435 \u043e\u0431\u044a\u044f\u0441\u043d\u0435\u043d\u0438\u0435 \u0438 \u043a\u0440\u0438\u0442\u0438\u043a\u0443 \u0434\u043b\u044f \u0431\u043e\u043b\u0435\u0435 \u0433\u043b\u0443\u0431\u043e\u043a\u043e\u0433\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u0440\u0430\u0431\u043e\u0442\u044b!<\/p>\n<\/div>\n<p>\u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/1095708\/\">https:\/\/habr.com\/ru\/articles\/1095708\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440! \u041d\u0430 \u0444\u043e\u043d\u0435 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u043e\u0441\u0442\u0438 decision-\u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u043c\u043d\u0435 \u0437\u0430\u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u043f\u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u044c\u0441\u044f \u0441 \u0438\u0445 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u043e\u043c \u0440\u0430\u0431\u043e\u0442\u044b. \u041e\u0431\u044a\u0435\u043a\u0442\u043e\u043c \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044f \u044f \u0432\u044b\u0431\u0440\u0430\u043b \u043c\u043e\u0434\u0435\u043b\u044c Clef \u043e\u0442 Cloudflare \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u043e\u043d\u0430 \u0431\u043e\u043b\u044c\u0448\u0435 \u0432\u0441\u0435\u0433\u043e \u043d\u0430 \u0441\u043b\u0443\u0445\u0443.\u0421\u0442\u0430\u0442\u044c\u044f \u043d\u043e\u0441\u0438\u0442 \u043f\u043e\u0437\u043d\u0430\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440 \u0438 \u0431\u0443\u0434\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0430 \u0442\u0435\u043c, \u043a\u0442\u043e, \u043a\u0430\u043a \u0438 \u044f, \u0437\u0430\u0445\u043e\u0447\u0435\u0442 \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u0432 \u0440\u0430\u0431\u043e\u0442\u0435 \u043c\u043e\u0434\u0435\u043b\u0438. \u0424\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u044b \u043a\u043e\u0434\u0430 \u0438 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u0432\u0437\u044f\u0442\u044b \u0438\u0437 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f \u0430\u0432\u0442\u043e\u0440\u043e\u0432.\u041f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c!\u041e\u0431\u0449\u0430\u044f \u0441\u0445\u0435\u043c\u0430 \u0438 \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u0421\u0438\u043c\u0432\u043e\u043b\u0417\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u0447\u0438\u0441\u043b\u043e \u0442\u043e\u043a\u0435\u043d\u043e\u0432 \u0432 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438\u0440\u0430\u0437\u043c\u0435\u0440 \u0441\u043a\u0440\u044b\u0442\u043e\u0433\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f Qwen\u0448\u0438\u0440\u0438\u043d\u0430 \u0433\u043e\u043b\u043e\u0432\u044b\u0447\u0438\u0441\u043b\u043e \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432\u0447\u0438\u0441\u043b\u043e \u043e\u043f\u0446\u0438\u0439 \u0443 \u0432\u043e\u043f\u0440\u043e\u0441\u0430 \u0432\u0441\u0435\u0433\u043e \u043e\u043f\u0446\u0438\u0439\u0441\u043f\u0430\u043d \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 \u0432\u043e\u043f\u0440\u043e\u0441\u0430 \u0441\u043f\u0430\u043d \u043e\u043f\u0446\u0438\u0438  \u0432\u043e\u043f\u0440\u043e\u0441\u0430 \u0432\u044b\u0445\u043e\u0434 Qwen \u043f\u043e\u0441\u043b\u0435 LayerNorm \u0433\u043e\u043b\u043e\u0432\u044b, \u043c\u0430\u0442\u0440\u0438\u0446\u0430 lm_head Qwen\u043d\u043e\u043c\u0435\u0440 \u0442\u043e\u043a\u0435\u043d\u0430 \u0432 \u043f\u043e\u0437\u0438\u0446\u0438\u0438  (input_ids[t])\u0412\u0445\u043e\u0434: \u0437\u0430\u043f\u0440\u043e\u0441 API\u0417\u0430\u043f\u0440\u043e\u0441 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 state (\u043e \u0447\u0451\u043c \u0440\u0435\u0448\u0430\u0435\u043c) \u0438 questions (\u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0440\u0435\u0448\u0438\u0442\u044c). \u041f\u0440\u0438\u043c\u0435\u0440 \u043e\u0442 Cloudflare:{  &#171;model&#187;: &#171;clef&#187;,  &#171;state&#187;: &#171;Checkout has been failing for every customer for the last hour.&#187;,  &#171;questions&#187;: {    &#171;urgent&#187;: { &#171;type&#187;: &#171;noul&#187;, &#171;instructions&#187;: &#171;Is this support request urgent?&#187; },    &#171;team&#187;: {      &#171;type&#187;: &#171;choice&#187;,      &#171;instructions&#187;: &#171;Which team should handle this request?&#187;,      &#171;criteria&#187;: {        &#171;billing&#187;: &#171;Payments, invoices, and refunds&#187;,        &#171;technical&#187;: &#171;Outages, errors, and configuration&#187;,        &#171;sales&#187;: &#171;Plans and upgrades&#187;      }    },    &#171;severity&#187;: {      &#171;type&#187;: &#171;score&#187;,      &#171;instructions&#187;: &#171;How severe is the customer impact?&#187;,      &#171;criteria&#187;: [&#171;No impact&#187;, &#171;Minor&#187;, &#171;Major&#187;, &#171;Critical&#187;]    }  }}\u0422\u0438\u043f\u044b \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432\u0422\u0438\u043f\u0421\u043c\u044b\u0441\u043b\u041e\u0442\u043a\u0443\u0434\u0430 \u0431\u0435\u0440\u0443\u0442\u0441\u044f \u043e\u043f\u0446\u0438\u0438\u041e\u043f\u0446\u0438\u0439 \u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u0435noul\u0434\u0430 \/ \u043d\u0435\u0442\u0441\u043e\u0437\u0434\u0430\u044e\u0442\u0441\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438: true, false2choice\u043e\u0434\u0438\u043d \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0438\u0437 \u0441\u043f\u0438\u0441\u043a\u0430\u043a\u043b\u044e\u0447\u0438 criteria, \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043f\u043e \u0430\u043b\u0444\u0430\u0432\u0438\u0442\u04433score\u0443\u0440\u043e\u0432\u0435\u043d\u044c \u043d\u0430 \u0448\u043a\u0430\u043b\u0435\u0438\u043d\u0434\u0435\u043a\u0441\u044b \u0441\u043f\u0438\u0441\u043a\u0430 criteria: &#171;0&#187;, &#171;1&#187;, \u20264\u041a\u0430\u043a \u0432\u043e\u043f\u0440\u043e\u0441 \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0432 \u0441\u043f\u0438\u0441\u043e\u043a \u043e\u043f\u0446\u0438\u0439\u041a\u043e\u0434 \u0438\u0437 joint_schema_model.py:QUESTION_TYPES = {&#171;noul&#187;: 0, &#171;choice&#187;: 1, &#171;score&#187;: 2}def question_options(question: dict[str, Any]) -&gt; list[tuple[str, Any]]:    question_type = str(question[&#171;type&#187;])    if question_type == &#171;noul&#187;:        criteria = {            &#171;true&#187;: &#171;The proposition is true or the answer is yes.&#187;,            &#171;false&#187;: &#171;The proposition is false or the answer is no.&#187;,        }        criteria.update(question.get(&#171;criteria&#187;) or {})        return [(key, criteria[key]) for key in (&#171;true&#187;, &#171;false&#187;)]    if question_type == &#171;choice&#187;:        return sorted((str(key), value) for key, value in question[&#171;criteria&#187;].items())    return [(str(index), value) for index, value in enumerate(question[&#171;criteria&#187;])]\u0414\u043b\u044f team \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043f\u043e ID \u0441\u043f\u0438\u0441\u043e\u043a:[(&#171;billing&#187;,   &#171;Payments, invoices, and refunds&#187;), (&#171;sales&#187;,     &#171;Plans and upgrades&#187;), (&#171;technical&#187;, &#171;Outages, errors, and configuration&#187;)]\u042d\u0442\u0430\u043f 1. encode_record: \u0437\u0430\u043f\u0440\u043e\u0441 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0442\u0435\u043a\u0441\u0442\u043e\u043cencode_record \u0441\u043a\u043b\u0435\u0438\u0432\u0430\u0435\u0442 \u0432\u0441\u0435 \u043f\u043e\u043b\u044f JSON \u0432 \u043e\u0434\u0438\u043d \u043f\u0440\u043e\u043c\u043f\u0442 \u0438 \u043f\u043e\u043f\u0443\u0442\u043d\u043e \u0437\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u0435\u0442, \u0433\u0434\u0435 \u0432 \u043d\u0451\u043c \u043b\u0435\u0436\u0438\u0442 \u043a\u0430\u0436\u0434\u044b\u0439 \u0432\u043e\u043f\u0440\u043e\u0441 \u0438 \u043a\u0430\u0436\u0434\u0430\u044f \u043e\u043f\u0446\u0438\u044f.\u042d\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432 \u0442\u0440\u0438 \u0448\u0430\u0433\u0430.\u0428\u0430\u0433 1. question_options \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u0442 criteria \u0432 \u0441\u043f\u0438\u0441\u043e\u043a \u043f\u0430\u0440 (\u0440\u0430\u0437\u0434\u0435\u043b 2).\u0428\u0430\u0433 2. \u041a\u0430\u0436\u0434\u0430\u044f \u043f\u0430\u0440\u0430 \u0437\u0430\u0432\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u0438\u0439 \u0441\u043b\u043e\u0432\u0430\u0440\u044c:semantics = {&#171;option_id&#187;: option_id}if description is not None:    semantics[&#171;description&#187;] = description\u0428\u0430\u0433 3. \u0421\u043b\u043e\u0432\u0430\u0440\u044c \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0432 \u0441\u0442\u0440\u043e\u043a\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 render:def render(value: Any) -&gt; str:    if isinstance(value, str):        return value    return json.dumps(        value,        ensure_ascii=False,        separators=(&#171;,&#187;, &#171;:&#187;),        sort_keys=True,    )\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f:{&#171;description&#187;:&#187;Payments, invoices, and refunds&#187;,&#187;option_id&#187;:&#187;billing&#187;}\u0424\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u043a\u043b\u044e\u0447\u0435\u0439 \u0438 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u043f\u0440\u043e\u0431\u0435\u043b\u043e\u0432 \u043d\u0443\u0436\u043d\u044b, \u0447\u0442\u043e\u0431\u044b \u043e\u0434\u043d\u0430 \u0438 \u0442\u0430 \u0436\u0435 \u043e\u043f\u0446\u0438\u044f \u0432\u0441\u0435\u0433\u0434\u0430 \u0434\u0430\u0432\u0430\u043b\u0430 \u043e\u0434\u043d\u0438 \u0438 \u0442\u0435 \u0436\u0435 \u0442\u043e\u043a\u0435\u043d\u044b.\u041f\u0440\u043e\u043c\u043f\u0442 \u0446\u0435\u043b\u0438\u043a\u043e\u043c ([\u043f\u0440\u0435\u0444\u0438\u043a\u0441], [state] \u0438 \u0442.\u0434 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u044b \u0434\u043b\u044f \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e\u0441\u0442\u0438):[\u043f\u0440\u0435\u0444\u0438\u043a\u0441]  &lt;|im_start|&gt;system           Read the complete state and schema. Decide every field jointly. &#8230;&lt;|im_end|&gt;           &lt;|im_start|&gt;user           STATE:[state]    Checkout has been failing for every customer for the last hour.[\u0441\u0445\u0435\u043c\u0430]           SCHEMA FIELDS:           FIELD 1           ID: urgent           TYPE: noul           INSTRUCTION: Is this support request urgent?                    \u2190 question_span           ALLOWED OPTIONS:           OPTION 1: {&#171;description&#187;:&#187;The proposition is true or the answer is yes.&#187;,&#187;option_id&#187;:&#187;true&#187;}   \u2190 option_span           OPTION 2: {&#171;description&#187;:&#187;The proposition is false or the answer is no.&#187;,&#187;option_id&#187;:&#187;false&#187;} \u2190 option_span           END FIELD           FIELD 2           ID: team           TYPE: choice           INSTRUCTION: Which team should handle this request?             \u2190 question_span           ALLOWED OPTIONS:           OPTION 1: {&#171;description&#187;:&#187;Payments, invoices, and refunds&#187;,&#187;option_id&#187;:&#187;billing&#187;}           OPTION 2: {&#171;description&#187;:&#187;Plans and upgrades&#187;,&#187;option_id&#187;:&#187;sales&#187;}           OPTION 3: {&#171;description&#187;:&#187;Outages, errors, and configuration&#187;,&#187;option_id&#187;:&#187;technical&#187;}           END FIELD           FIELD 3           ID: severity           TYPE: score           INSTRUCTION: How severe is the customer impact?                 \u2190 question_span           ALLOWED OPTIONS:           OPTION 1: {&#171;description&#187;:&#187;No impact&#187;,&#187;option_id&#187;:&#187;0&#8243;}           OPTION 2: {&#171;description&#187;:&#187;Minor&#187;,&#187;option_id&#187;:&#187;1&#8243;}           OPTION 3: {&#171;description&#187;:&#187;Major&#187;,&#187;option_id&#187;:&#187;2&#8243;}           OPTION 4: {&#171;description&#187;:&#187;Critical&#187;,&#187;option_id&#187;:&#187;3&#8243;}           END FIELD[\u0441\u0443\u0444\u0444\u0438\u043a\u0441]  &lt;|im_end|&gt;           &lt;|im_start|&gt;assistant           &lt;think&gt;           &lt;\/think&gt;           JOINT SCHEMA DECISIONS:\u041a\u043e\u0434\u041f\u043e\u0441\u043b\u0435 \u0442\u043e\u043a\u0435\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0437\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u0435\u0442 \u043f\u043e\u0437\u0438\u0446\u0438\u0438 \u0432\u00a0\u043f\u0440\u043e\u043c\u043f\u0442\u0435 \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432 \u0438 \u043e\u043f\u0446\u0438\u0439:def encode_record(    tokenizer: Any,    record: dict[str, Any],    max_length: int = 16384,    max_state_tokens: int | None = None,    processor: Any | None = None,) -&gt; EncodedRecord:    schema_ids = _tokens(tokenizer, &#171;\\n\\nSCHEMA FIELDS:\\n&#187;)    questions: list[EncodedQuestion] = []    for question_index, (question_id, question) in enumerate(record[&#171;questions&#187;].items()):        schema_ids.extend(            _tokens(                tokenizer,                f&#187;\\nFIELD {question_index + 1}\\nID: {question_id}\\nTYPE: {question[&#8216;type&#8217;]}\\nINSTRUCTION: &#171;,            )        )        question_start = len(schema_ids)        instructions = question.get(&#171;instructions&#187;)        if instructions is None or instructions == &#171;&#187;:            instructions = str(question_id)        schema_ids.extend(_tokens(tokenizer, render(instructions)))        question_end = len(schema_ids)        schema_ids.extend(_tokens(tokenizer, &#171;\\nALLOWED OPTIONS:\\n&#187;))        option_spans: list[tuple[int, int]] = []        option_ids: list[str] = []        for option_index, (option_id, description) in enumerate(question_options(question)):            schema_ids.extend(_tokens(tokenizer, f&#187;OPTION {option_index + 1}: &#171;))            option_start = len(schema_ids)            semantics = {&#171;option_id&#187;: option_id}            if description is not None:                semantics[&#171;description&#187;] = description            schema_ids.extend(_tokens(tokenizer, render(semantics)))            option_spans.append((option_start, len(schema_ids)))            option_ids.append(option_id)            schema_ids.extend(_tokens(tokenizer, &#171;\\n&#187;))        schema_ids.extend(_tokens(tokenizer, &#171;END FIELD\\n&#187;))\u041a\u0430\u0436\u0434\u044b\u0439 \u043a\u0443\u0441\u043e\u043a \u0442\u043e\u043a\u0435\u043d\u0438\u0437\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u043b\u043e \u0441\u043a\u043b\u0435\u0438\u0432\u0430\u043d\u0438\u0435 (\u0435\u0441\u043b\u0438 \u0442\u043e\u043a\u0435\u043d\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u0435\u0441\u044c \u043f\u0440\u043e\u043c\u043f\u0442 \u0446\u0435\u043b\u0438\u043a\u043e\u043c, BPE \u043c\u043e\u0436\u0435\u0442 \u0441\u043a\u043b\u0435\u0438\u0442\u044c \u043a\u043e\u043d\u0435\u0446 &#171;OPTION 1: &#187; \u0441 \u043d\u0430\u0447\u0430\u043b\u043e\u043c JSON \u0432 \u043e10. \u0434\u0438\u043d \u0442\u043e\u043a\u0435\u043d)\u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0441\u0434\u0432\u0438\u0433 \u0432\u0441\u0435\u0439 \u0441\u0445\u0435\u043c\u044b \u043d\u0430 \u0434\u043b\u0438\u043d\u0443 \u043f\u0440\u0435\u0444\u0438\u043a\u0441\u0430 \u0438 state:    schema_offset = len(prefix_ids) + len(state_ids)    shifted_questions = tuple(        EncodedQuestion(            question_id=question.question_id,            question_type=question.question_type,            question_span=(                question.question_span[0] + schema_offset,                question.question_span[1] + schema_offset,            ),            option_spans=tuple(                (start + schema_offset, end + schema_offset)                for start, end in question.option_spans            ),            option_ids=question.option_ids,        )        for question in questions    )    input_ids = tuple(prefix_ids + state_ids + schema_ids + suffix_ids)\u0412\u044b\u0445\u043e\u0434 \u044d\u0442\u0430\u043f\u0430\u0412\u044b\u0445\u043e\u0434\u0420\u0430\u0437\u043c\u0435\u0440input_idsquestion_span \u043f\u0430\u0440\u044b \u0447\u0438\u0441\u0435\u043boption_spans \u043f\u0430\u0440 \u0447\u0438\u0441\u0435\u043b, \u0441\u0433\u0440\u0443\u043f\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u043f\u043e \u0432\u043e\u043f\u0440\u043e\u0441\u0430\u043coption_ids, question_type\u043c\u0435\u0442\u0430\u0434\u0430\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u0441\u0431\u043e\u0440\u043a\u0438 \u043e\u0442\u0432\u0435\u0442\u0430\u042d\u0442\u0430\u043f 2. Qwen: \u043e\u0434\u0438\u043d \u043f\u0440\u043e\u0445\u043e\u0434\u041d\u0430 \u044d\u0442\u043e\u043c \u044d\u0442\u0430\u043f\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0440\u0430\u0441\u0447\u0435\u0442 \u043f\u043e \u0432\u0441\u0435\u043c \u0441\u043b\u043e\u044f\u043c \u0431\u0435\u0437 \u0433\u043e\u043b\u043e\u0432\u044b \u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 LayerNorm \u043a \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u043c\u0443 \u0432\u044b\u0445\u043e\u0434\u043d\u043e\u043c\u0443 \u0441\u043b\u043e\u044e:\u0412\u044b\u0445\u043e\u0434 \u044d\u0442\u0430\u043f\u0430last_hidden_state \u2014 \u043f\u043e \u0432\u0435\u043a\u0442\u043e\u0440\u0443 \u043d\u0430 \u043a\u0430\u0436\u0434\u044b\u0439 \u0442\u043e\u043a\u0435\u043d \u043a\u0430\u0436\u0434\u043e\u0439 \u0437\u0430\u043f\u0438\u0441\u0438 \u0431\u0430\u0442\u0447\u0430.\u042d\u0442\u0430\u043f A. \u0418\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u0435 \u0432\u0435\u043a\u0442\u043e\u0440\u043e\u0432\u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u0430\u043f\u0430 2 \u0435\u0441\u0442\u044c \u0442\u0430\u0431\u043b\u0438\u0446\u0430 . \u041d\u043e\u043c\u0435\u0440 \u0441\u0442\u0440\u043e\u043a\u0438 \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0435\u0442 \u0441 \u043d\u043e\u043c\u0435\u0440\u043e\u043c \u0442\u043e\u043a\u0435\u043d\u0430 \u0432 input_ids. \u042d\u0442\u0430\u043f A \u0432\u044b\u0440\u0435\u0437\u0430\u0435\u0442 \u0438\u0437 \u044d\u0442\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u043d\u0443\u0436\u043d\u044b\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 (\u0441\u043f\u0430\u043d\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u044b\u043b\u0438 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u044b \u0440\u0430\u043d\u0435\u0435).\u0441\u0442\u0440\u043e\u043a\u0430   \u0442\u043e\u043a\u0435\u043d            \u0432\u0435\u043a\u0442\u043e\u0440  0      &lt;|im_start|&gt;     [ &#8230; ] &#8230; 152     Which            [ &#8230; ]  \u2510 &#8230;                               \u251c question_span team = (152, 160) 159     ?                [ &#8230; ]  \u2518 &#8230; 164     {&#187;               [ &#8230; ]  \u2510 165     description      [ &#8230; ]  \u2502 &#8230;                               \u251c option_span billing = (164, 184) 183     &#171;}               [ &#8230; ]  \u2518 &#8230; 319     :                [ &#8230; ]  \u2190 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0442\u043e\u043a\u0435\u043d\u041a\u043e\u0434    def forward(        self,        hidden_states: torch.Tensor,        input_ids: torch.Tensor,        attention_mask: torch.Tensor,        records: list[EncodedRecord],        output_embedding_weight: torch.Tensor,    ) -&gt; list[list[torch.Tensor]]:        results: list[list[torch.Tensor]] = []        normalized_hidden = self.hidden_norm(hidden_states)        for batch_index, record in enumerate(records):            sequence_length = int(attention_mask[batch_index].sum().item())            sequence_hidden = normalized_hidden[batch_index, :sequence_length]            memory = self.memory_projection(sequence_hidden).unsqueeze(0)            global_vector = sequence_hidden[-1]            question_vectors = torch.stack(                [                    self._mean_span(sequence_hidden, question.question_span)                    for question in record.questions                ]            )            type_ids = torch.tensor(&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-499109","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/499109","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=499109"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/499109\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=499109"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=499109"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=499109"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}