{"id":483710,"date":"2026-06-15T13:58:07","date_gmt":"2026-06-15T13:58:07","guid":{"rendered":"https:\/\/savepearlharbor.com\/?p=483710"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=483710","title":{"rendered":"\u0421\u0442\u044f\u0433\u0438\u0432\u0430\u0439 \u043a\u0443\u0434\u0430 \u043d\u0443\u0436\u043d\u043e: Activation Steering Tutorial"},"content":{"rendered":"<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041f\u0440\u0438\u0432\u0435\u0442, \u0434\u0440\u0443\u0437\u044c\u044f! \u0415\u0441\u043b\u0438 \u0432\u044b \u043f\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0443 &#171;\u043a\u0430\u043a \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u044c \u0434\u043e\u0431\u0440\u0435\u0435&#187; \u0432\u0438\u0434\u0438\u0442\u0435 \u0432 output-\u0435 LLM \u0444\u0440\u0430\u0437\u0443 &#171;\u0440\u0443\u043b\u0435\u0432\u043e\u0435 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435&#187; \u2014 \u0437\u043d\u0430\u0447\u0438\u0442 LLM \u0433\u043e\u0432\u043e\u0440\u0438\u0442 \u043f\u0440\u043e Steering. \u0412 \u044d\u0442\u043e\u043c \u0442\u0443\u0442\u043e\u0440\u0438\u0430\u043b\u0435 \u0432\u044b:<\/p>\n<ul>\n<li>\n<p>\u0443\u0437\u043d\u0430\u0435\u0442\u0435, \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 steering \u0438 \u043d\u0430 \u0447\u0435\u043c \u043e\u043d \u043e\u0441\u043d\u043e\u0432\u0430\u043d;<\/p>\n<\/li>\n<li>\n<p>\u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0438\u0442\u0435 steering, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f pytorch-hooks;<\/p>\n<\/li>\n<li>\n<p>\u043f\u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u0435\u0441\u044c \u0441 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430\u043c\u0438 nnsight \u0438 pyvene \u0434\u043b\u044f interventions;<\/p>\n<\/li>\n<\/ul>\n<p>\u0418 \u0435\u0441\u043b\u0438 \u043a\u0430\u043a\u043e\u0435-\u0442\u043e \u0441\u043b\u043e\u0432\u043e \u0438\u0437 bullet-\u043e\u0432 \u0431\u044b\u043b\u043e \u043d\u0435\u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u043e\u043d\u0438 \u0432\u0441\u0435 \u0441\u0442\u0430\u043d\u0443\u0442 \u0432\u0430\u043c \u043f\u043e\u043d\u044f\u0442\u043d\u044b \u043a \u043a\u043e\u043d\u0446\u0443. <\/p>\n<figure class=\"full-width \"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/595\/ca5\/6cf\/595ca56cf59343c0dfed56004bfc9b96.png\" alt=\"Created by my best friend \u2014 Claude.\" title=\"Created by my best friend \u2014 Claude.\" width=\"1280\" height=\"720\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/595\/ca5\/6cf\/595ca56cf59343c0dfed56004bfc9b96.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/595\/ca5\/6cf\/595ca56cf59343c0dfed56004bfc9b96.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<div><figcaption>Created by my best friend \u2014 Claude.<\/figcaption><\/div>\n<\/figure>\n<h2>Activation Steering \u2014\u00a0\u044d\u0442\u043e<\/h2>\n<p>\u0412 research-\u043d\u0430\u0440\u043e\u0434\u044c\u0435, <strong>Activation Steering<\/strong> \u2014 \u044d\u0442\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435, \u0432\u044b\u0447\u0438\u0442\u0430\u043d\u0438\u0435 \u0438\u043b\u0438 \u0438\u043d\u0430\u044f \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u0432\u0435\u043a\u0442\u043e\u0440\u043e\u0432 \u0432\u043e \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0445 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f\u0445 LLM \u0432\u043e \u0432\u0440\u0435\u043c\u044f forward pass-\u0430. Steering \u043e\u0441\u043d\u043e\u0432\u0430\u043d \u043d\u0430 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u0443 \u043e\u0431\u0443\u0447\u0435\u043d\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u0435\u0441\u0442\u044c \u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u00ab\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f\u00bb \u0432 \u043b\u0430\u0442\u0435\u043d\u0442\u043d\u043e\u043c \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0435. <\/p>\n<p>Activation Steering \u2014 \u044d\u0442\u043e <strong>inference-time<\/strong> intervention (\u0432\u043c\u0435\u0448\u0430\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u043e \u0432 \u043c\u043e\u0434\u0435\u043b\u044c \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0438\u043d\u0444\u0435\u0440\u0435\u043d\u0441\u0430). \u041c\u044b \u043d\u0435 \u043c\u0435\u043d\u044f\u0435\u043c \u0432\u0435\u0441\u0430 \u043c\u043e\u0434\u0435\u043b\u0438 (\u0432 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 fine-tuning) \u2014 \u043c\u044b \u0432\u043c\u0435\u0448\u0438\u0432\u0430\u0435\u043c\u0441\u044f \u0432 \u043f\u043e\u0442\u043e\u043a \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439 &#171;\u043d\u0430 \u043b\u0435\u0442\u0443&#187;, \u043f\u043e\u043a\u0430 \u043c\u043e\u0434\u0435\u043b\u044c &#171;\u0434\u0443\u043c\u0430\u0435\u0442&#187; \u2014\u00a0\u0442\u043e \u0435\u0441\u0442\u044c \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442.<\/p>\n<p>\u0411\u0430\u0437\u043e\u0432\u0430\u044f \u0444\u043e\u0440\u043c\u0443\u043b\u0430:<br \/><img decoding=\"async\" class=\"formula inline\" source=\"\\text{hidden\\_state}^{(\\ell)} \\;\\leftarrow\\; \\text{hidden\\_state}^{(\\ell)} + \\alpha \\cdot \\mathbf{v}\" alt=\"\\text{hidden\\_state}^{(\\ell)} \\;\\leftarrow\\; \\text{hidden\\_state}^{(\\ell)} + \\alpha \\cdot \\mathbf{v}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/c\/cb\/cbb\/cbba3da12277cbd813b9fc2052f7bce2.svg\" width=\"328\" height=\"16\" data-width=\"41.365\" data-height=\"2.718\" data-vertical-align=\"-0.793\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/c\/cb\/cbb\/cbba3da12277cbd813b9fc2052f7bce2.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/c\/cb\/cbb\/cbba3da12277cbd813b9fc2052f7bce2.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<p>\u0433\u0434\u0435 <img decoding=\"async\" class=\"formula inline\" source=\"\\mathbf{v}\" alt=\"\\mathbf{v}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/f\/fb\/fb1\/fb16e3e3f18c15edc61e1f2c0fa972ba.svg\" width=\"12\" height=\"16\" data-width=\"1.373\" data-height=\"2.262\" data-vertical-align=\"-0.566\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/f\/fb\/fb1\/fb16e3e3f18c15edc61e1f2c0fa972ba.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/f\/fb\/fb1\/fb16e3e3f18c15edc61e1f2c0fa972ba.svg 781w\" loading=\"lazy\" decode=\"async\"\/> \u2014 <strong>steering vector<\/strong>, \u0432\u0435\u043a\u0442\u043e\u0440, \u043a\u043e\u0434\u0438\u0440\u0443\u044e\u0449\u0438\u0439 \u043d\u0443\u0436\u043d\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435,<img decoding=\"async\" class=\"formula inline\" source=\"\\ell\" alt=\"\\ell\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/e\/ee\/ee5\/ee5e5c003694e7cd5ae404923c665edb.svg\" width=\"12\" height=\"16\" data-width=\"0.943\" data-height=\"2.262\" data-vertical-align=\"-0.566\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/e\/ee\/ee5\/ee5e5c003694e7cd5ae404923c665edb.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/e\/ee\/ee5\/ee5e5c003694e7cd5ae404923c665edb.svg 781w\" loading=\"lazy\" decode=\"async\"\/>\u2014 \u043d\u043e\u043c\u0435\u0440 \u0441\u043b\u043e\u044f, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0432\u043c\u0435\u0448\u0438\u0432\u0430\u0435\u043c\u0441\u044f, <img decoding=\"async\" class=\"formula inline\" source=\"\\alpha\" alt=\"\\alpha\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/7\/7b\/7b7\/7b7f9dbfea05c83784f8b85149852f08.svg\" width=\"12\" height=\"16\" data-width=\"1.448\" data-height=\"2.262\" data-vertical-align=\"-0.566\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/7\/7b\/7b7\/7b7f9dbfea05c83784f8b85149852f08.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/7\/7b\/7b7\/7b7f9dbfea05c83784f8b85149852f08.svg 781w\" loading=\"lazy\" decode=\"async\"\/> \u2014 \u0441\u0438\u043b\u0430 \u0432\u043c\u0435\u0448\u0430\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u0430.<\/p>\n<p>\u0421\u0434\u0432\u0438\u0433\u0430\u0435\u043c\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0447\u0451\u0442\u043a\u043e \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u043e \u0438 \u0438\u043c\u0435\u0442\u044c <strong>\u043f\u043e\u043b\u044f\u0440\u043d\u0443\u044e \u043f\u0430\u0440\u0443<\/strong>, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<ul>\n<li>\n<p>refusal vs compliance;<\/p>\n<\/li>\n<li>\n<p>positive sentiment vs negative sentiment;<\/p>\n<\/li>\n<\/ul>\n<blockquote>\n<p><em>\u0417\u0430\u043c\u0435\u0442\u0438\u043c, \u0447\u0442\u043e \u0432\u043e \u0432\u0442\u043e\u0440\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 &#171;positive&#187; \u0438 &#171;negative&#187; \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043e\u043c. \u041a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u0438\u0437 \u0436\u0438\u0437\u043d\u0438 \u2014\u00a0\u0442\u043e, \u0447\u0442\u043e &#171;positive&#187; \u0434\u043b\u044f \u043a\u043e\u043d\u0441\u0435\u0440\u0432\u0430\u0442\u0438\u0432\u043d\u044b\u0445 \u043b\u044e\u0434\u0435\u0439, \u044f\u0432\u043d\u043e &#171;negative&#187; \u0434\u043b\u044f \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u043a\u043e\u0432 \u043d\u043e\u0432\u043e\u0433\u043e. \u041e\u0442\u043b\u043e\u0436\u0438\u043c \u044d\u0442\u043e \u043f\u043e\u043a\u0430 \u0432 \u043f\u0430\u043c\u044f\u0442\u0438. <\/em><\/p>\n<\/blockquote>\n<p>\u0412 \u044d\u0442\u043e\u043c \u0442\u0443\u0442\u043e\u0440\u0438\u0430\u043b\u0435 \u043c\u044b \u043f\u043e\u0441\u0442\u0430\u0432\u0438\u043c \u0446\u0435\u043b\u044c \u0441\u0434\u0432\u0438\u043d\u0443\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u044c \u0432 \u0441\u0442\u043e\u0440\u043e\u043d\u0443 hate-speech. \u0412\u044b\u0431\u043e\u0440 \u0442\u0435\u043c\u044b hate-speech \u043e\u0431\u0443\u0441\u043b\u043e\u0432\u043b\u0435\u043d \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u043c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043e\u043c. \u0421\u0434\u0432\u0438\u0433\u0430\u0442\u044c, \u043f\u043e\u0432\u0442\u043e\u0440\u044e\u0441\u044c, \u043c\u043e\u0436\u043d\u043e \u0432 \u043b\u044e\u0431\u043e\u0435 \u043c\u0435\u0441\u0442\u043e, \u0432\u044b\u0440\u0430\u0436\u0430\u044e\u0449\u0435\u0435 \u043f\u043e\u043b\u044f\u0440\u043d\u043e\u0441\u0442\u044c.<\/p>\n<div class=\"persona\"><img decoding=\"async\" class=\"image persona__image\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/27a\/9a2\/8be\/27a9a28bec04d7841148964277aaa3e5.jpg\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/27a\/9a2\/8be\/27a9a28bec04d7841148964277aaa3e5.jpg 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/27a\/9a2\/8be\/27a9a28bec04d7841148964277aaa3e5.jpg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<h5 class=\"persona__heading\">\u041f\u0440\u0438\u043c\u0435\u0440\u044b \u0438\u0437 \u043d\u043e\u0443\u0442\u0431\u0443\u043a\u0430 \u043d\u0435 \u0432\u044b\u0440\u0430\u0436\u0430\u044e\u0442 \u043c\u043e\u044e \u043b\u0438\u0447\u043d\u0443\u044e \u043f\u043e\u0437\u0438\u0446\u0438\u044e \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u0443\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0432\u044b\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u043d\u0438\u044f.<\/h5>\n<\/div>\n<h2>\u0427\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0434\u043b\u044f steering?<\/h2>\n<p>\u041f\u0435\u0440\u0432\u043e\u0435 \u2014\u00a0\u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u043c\u043e\u0434\u0435\u043b\u044c. \u0414\u043b\u044f \u0431\u044b\u0441\u0442\u0440\u043e\u0433\u043e \u0434\u0435\u043c\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c <code>gpt2<\/code>, \u0447\u0442\u043e\u0431\u044b \u043d\u043e\u0443\u0442\u0431\u0443\u043a \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u043b\u0441\u044f \u043f\u043e\u0447\u0442\u0438 \u0432\u0435\u0437\u0434\u0435.<\/p>\n<details class=\"spoiler\">\n<summary>\u0421\u043a\u0440\u044b\u0442\u044b\u0439 \u0442\u0435\u043a\u0441\u0442<\/summary>\n<div class=\"spoiler__content\">\n<p>\u0414\u043b\u044f \u0431\u043e\u043b\u0435\u0435 \u0432\u0435\u0441\u0435\u043b\u044b\u0445 \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u043e\u0432 \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c <code>MODEL_NAME<\/code> \u0432 \u043d\u043e\u0443\u043a\u0442\u0431\u0443\u043a\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u044f \u043f\u0440\u0438\u043a\u0440\u0435\u043f\u043b\u044e \u043d\u0438\u0436\u0435 \u043d\u0430:<\/p>\n<p>&#8212; <code>gpt2-medium<\/code><br \/>&#8212; <code>EleutherAI\/pythia-410m<\/code><br \/>&#8212; <code>TinyLlama\/TinyLlama-1.1B-Chat-v1.0<\/code><br \/>&#8212; Llama\/Mistral\/Gemma open-weight \u043c\u043e\u0434\u0435\u043b\u0438, \u0435\u0441\u043b\u0438 \u0435\u0441\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u0438 GPU<\/p>\n<p>\u0412\u044b\u0431\u0438\u0440\u0430\u0439\u0442\u0435 \u0441\u0432\u043e\u0451!<\/p>\n<\/div>\n<\/details>\n<p><strong>Contrastive dataset<\/strong><\/p>\n<p>\u041f\u0435\u0440\u0432\u044b\u0439 \u0448\u0430\u0433 \u0441\u0442\u0438\u0440\u0438\u043d\u0433\u0430 \u2014\u00a0\u043a\u043e\u043d\u0441\u0442\u0440\u0443\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f. \u0427\u0442\u043e\u0431\u044b \u0435\u0433\u043e \u043d\u0430\u0439\u0442\u0438, \u043d\u0430\u043c \u043d\u0443\u0436\u0435\u043d \u043d\u0430\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445, \u043e\u0442\u0440\u0430\u0436\u0430\u044e\u0449\u0438\u0439 \u0441\u0434\u0432\u0438\u0433\u0430\u0435\u043c\u0443\u044e \u043f\u043e\u043b\u044f\u0440\u043d\u043e\u0441\u0442\u044c. \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043d\u0430\u0448\u0430 \u0446\u0435\u043b\u044c hate-speech, \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c <code>mixed_hate_dataset<\/code>, \u0433\u0434\u0435 \u043a\u0430\u0436\u0434\u043e\u0435 \u0432\u044b\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u043d\u0438\u0435 \u0438\u043c\u0435\u0435\u0442 \u043e\u0434\u043d\u0443 \u0438\u0437 \u0434\u0432\u0443\u0445 \u043c\u0435\u0442\u043e\u043a:<\/p>\n<ul>\n<li>\n<p><strong>0 (is_harmfull_opposition)<\/strong>: \u043d\u0435\u043d\u0430\u0432\u0438\u0441\u0442\u043d\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \/ \u0434\u0438\u0441\u043a\u0440\u0438\u043c\u0438\u043d\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u0435 \u0432\u044b\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u043d\u0438\u0435. \u041f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<p><em>&#171;Mentally retarded people are uneducated and should not be accepted into schools.&#187;<\/em><\/p>\n<\/li>\n<li>\n<p><strong>1 (is_harmfull_opposition)<\/strong>: \u043e\u043f\u0440\u043e\u0432\u0435\u0440\u0436\u0435\u043d\u0438\u0435 \/ tolerant<\/p>\n<p><em>&#171;Mentally retarded people can be educated and should be accepted into schools.&#187;<\/em><\/p>\n<\/li>\n<\/ul>\n<p>\u0414\u0430\u0442\u0430\u0441\u0435\u0442 \u0441\u043e\u0431\u0440\u0430\u043d \u0442\u0430\u043a, \u0447\u0442\u043e \u043a\u0430\u0436\u0434\u043e\u0435 harmfull \u0438\u043c\u0435\u0435\u0442 safe \u043f\u0430\u0440\u0443. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043e\u043d \u0445\u043e\u0440\u043e\u0448 \u0434\u043b\u044f steering. \u0418\u0434\u0435\u0430\u043b\u0435\u043d \u043e\u043d \u0431\u044b\u043b \u0431\u044b, \u0435\u0441\u043b\u0438 \u0431\u044b \u0432\u0441\u0435 \u0442\u043e\u043f\u0438\u043a\u0438 \u0431\u044b\u043b\u0438 \u0438\u0437 \u043e\u0434\u043d\u043e\u0439 \u0442\u0435\u043c\u044b, \u043d\u043e \u043b\u0443\u0447\u0448\u0435\u0435 \u2014\u00a0\u0432\u0440\u0430\u0433 \u0445\u043e\u0440\u043e\u0448\u0435\u0433\u043e \u0438 \u0435\u0433\u043e \u043d\u0430\u043c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e. <\/p>\n<p>\u0412 \u0442\u0430\u043a\u043e\u0439 \u043f\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0435 \u0434\u0430\u043d\u043d\u044b\u0445, \u043c\u044b \u043e\u0436\u0438\u0434\u0430\u0435\u043c, \u0447\u0442\u043e steering vector \u0431\u0443\u0434\u0435\u0442 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0438\u0437 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0430 \u043d\u0435\u043d\u0430\u0432\u0438\u0441\u0442\u043d\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0432\u044b\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u043d\u0438\u0439 \u0432 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u043e \u0432\u044b\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u043d\u0438\u0439 \u0442\u043e\u043b\u0435\u0440\u0430\u043d\u0442\u043d\u044b\u0445:<\/p>\n<p><code>steering_vector = mean(acts_tolerant) \u2212 mean(acts_hate)<\/code><\/p>\n<p>\u041f\u043e \u043f\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0435 \u0432\u0435\u043a\u0442\u043e\u0440\u0430, \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u044f \u0435\u0433\u043e \u0441 <code>alpha &gt; 0<\/code>, \u043c\u044b \u0442\u043e\u043b\u043a\u0430\u0435\u043c \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044e \u0432 \u0441\u0442\u043e\u0440\u043e\u043d\u0443 tolerant (\u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0432\u0435\u0441\u044c hate \u0438\u0437 tolerant \u043c\u044b \u0432\u044b\u0447\u043b\u0438). \u0421 <code>alpha &lt; 0<\/code> \u2014 \u0432 \u043e\u0431\u0440\u0430\u0442\u043d\u0443\u044e \u0441\u0442\u043e\u0440\u043e\u043d\u0443. \u0423 \u044d\u0442\u043e\u0433\u043e \u0435\u0441\u0442\u044c \u043d\u044e\u0430\u043d\u0441\u044b \u0438 \u0438\u0445 \u0432\u044b \u0443\u0432\u0438\u0434\u0438\u0442\u0435 \u043d\u0438\u0436\u0435. <\/p>\n<p>\u0414\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c residual stream \u043c\u043e\u0434\u0435\u043b\u0438 \u043d\u0430 \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u043e\u0435. <\/p>\n<p><strong>Residual stream<\/strong><\/p>\n<p>GPT-2, \u043a\u0430\u043a \u0438 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0435\u0440\u043e\u0432, \u0443\u0441\u0442\u0440\u043e\u0435\u043d \u043f\u043e \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0443 <strong>residual connections<\/strong>: \u043a\u0430\u0436\u0434\u044b\u0439 \u0431\u043b\u043e\u043a \u043d\u0435 \u00ab\u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442\u00bb \u0442\u0435\u043d\u0437\u043e\u0440 \u0441 \u043d\u0443\u043b\u044f, \u0430 <strong>\u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442<\/strong> \u0441\u0432\u043e\u0439 \u0432\u043a\u043b\u0430\u0434 \u043a \u0443\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u043c\u0443:<\/p>\n<p><img decoding=\"async\" class=\"formula inline\" source=\"\\mathbf{x}^{(\\ell+1)} = \\mathbf{x}^{(\\ell)} + \\text{Block}_\\ell\\bigl(\\mathbf{x}^{(\\ell)}\\bigr)\" alt=\"\\mathbf{x}^{(\\ell+1)} = \\mathbf{x}^{(\\ell)} + \\text{Block}_\\ell\\bigl(\\mathbf{x}^{(\\ell)}\\bigr)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/3\/34\/343\/34326c2b5059773d8f573f63fe7194d7.svg\" width=\"208\" height=\"16\" data-width=\"26.734\" data-height=\"2.925\" data-vertical-align=\"-0.897\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/3\/34\/343\/34326c2b5059773d8f573f63fe7194d7.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/3\/34\/343\/34326c2b5059773d8f573f63fe7194d7.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<p>\u042d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e \u043e\u0434\u0438\u043d \u0438 \u0442\u043e\u0442 \u0436\u0435 \u00ab\u043f\u043e\u0442\u043e\u043a\u00bb \u2014 <strong>residual stream<\/strong> \u2014 \u0438\u0434\u0435\u0442 \u043e\u0442 \u0432\u0445\u043e\u0434\u0430 \u0434\u043e \u0432\u044b\u0445\u043e\u0434\u0430 \u0447\u0435\u0440\u0435\u0437 \u0432\u0441\u0435 \u0441\u043b\u043e\u0438. \u041a\u0430\u0436\u0434\u044b\u0439 \u0441\u043b\u043e\u0439 \u0447\u0438\u0442\u0430\u0435\u0442 \u0438\u0437 \u043d\u0435\u0433\u043e \u0438 \u0434\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u0432 \u043d\u0435\u0433\u043e. <code>model.transformer.h[layer]<\/code> \u2014 \u044d\u0442\u043e \u0432\u044b\u0445\u043e\u0434 residual block <img decoding=\"async\" class=\"formula inline\" source=\"\\ell\" alt=\"\\ell\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/e\/ee\/ee5\/ee5e5c003694e7cd5ae404923c665edb.svg\" width=\"12\" height=\"16\" data-width=\"0.943\" data-height=\"2.262\" data-vertical-align=\"-0.566\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/e\/ee\/ee5\/ee5e5c003694e7cd5ae404923c665edb.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/e\/ee\/ee5\/ee5e5c003694e7cd5ae404923c665edb.svg 781w\" loading=\"lazy\" decode=\"async\"\/>, \u0442\u043e \u0435\u0441\u0442\u044c <img decoding=\"async\" class=\"formula inline\" source=\"\\mathbf{x}^{(\\ell+1)}\" alt=\"\\mathbf{x}^{(\\ell+1)}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/8\/83\/835\/835bdd15a93dfedd0b7d635e1bd00a54.svg\" width=\"40\" height=\"16\" data-width=\"5.517\" data-height=\"2.7\" data-vertical-align=\"-0.784\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/8\/83\/835\/835bdd15a93dfedd0b7d635e1bd00a54.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/8\/83\/835\/835bdd15a93dfedd0b7d635e1bd00a54.svg 781w\" loading=\"lazy\" decode=\"async\"\/> \u043f\u043e\u0441\u043b\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0441\u043b\u043e\u044f. \u041e\u043d \u0436\u0435 \u0438\u043c\u0435\u043d\u0443\u0435\u0442\u0441\u044f \u043a\u0430\u043a <code>hidden_state. <\/code><\/p>\n<p>\u041f\u043e\u0447\u0435\u043c\u0443 residual stream \u0432\u0430\u0436\u0435\u043d \u0434\u043b\u044f \u043d\u0430\u0441: <\/p>\n<ul>\n<li>\n<p>\u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u0432 \u043d\u0451\u043c \u043d\u0430\u043a\u0430\u043f\u043b\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0430\u0434\u0434\u0438\u0442\u0438\u0432\u043d\u043e \u2014 \u0435\u0441\u043b\u0438 \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u043d\u0430 \u0441\u043b\u043e\u0435 &#171;\u0434\u043e&#187; \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043d\u0430\u0434\u0435\u044f\u0442\u0441\u044f, \u0447\u0442\u043e \u043a\u043e\u043d\u0446\u0435\u043f\u0442 \u043f\u0440\u043e\u0441\u0442\u043e \u0436\u0438\u0432\u0435\u0442 \u0432 \u0434\u0440\u0443\u0433\u043e\u043c \u0441\u043b\u043e\u0435;<\/p>\n<\/li>\n<li>\n<p>\u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043f\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044e <strong>\u0432\u044b\u043d\u0443\u0436\u0434\u0435\u043d\u0430<\/strong> \u0447\u0438\u0442\u0430\u0442\u044c\u0441\u044f \u043b\u0438\u043d\u0435\u0439\u043d\u043e, \u043e\u0442\u0441\u044e\u0434\u0430 \u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0433\u043e \u0441\u0434\u0432\u0438\u0433\u0430 \u043d\u0430\u043c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e (\u0432\u043e \u043c\u043d\u043e\u0433\u043e\u043c \u0442\u0430\u043a \u043a\u0430\u043a \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u0441\u043e\u0431\u0440\u0430\u043d \u0446\u0435\u043b\u0438\u043a\u043e\u043c \u0438\u0437 \u043b\u0438\u043d\u0435\u0439\u043d\u044b\u0445 \u043f\u0440\u043e\u0435\u043a\u0446\u0438\u0439: <img decoding=\"async\" class=\"formula inline\" source=\"Q = W_Q \\mathbf{x}, K = W_K \\mathbf{x}, V = W_V \\mathbf{x}\" alt=\"Q = W_Q \\mathbf{x}, K = W_K \\mathbf{x}, V = W_V \\mathbf{x}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/8\/83\/83b\/83b6fae368fa0c1c673b6ff3ca7fcca8.svg\" width=\"248\" height=\"16\" data-width=\"31.612\" data-height=\"2.347\" data-vertical-align=\"-0.608\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/8\/83\/83b\/83b6fae368fa0c1c673b6ff3ca7fcca8.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/8\/83\/83b\/83b6fae368fa0c1c673b6ff3ca7fcca8.svg 781w\" loading=\"lazy\" decode=\"async\"\/>)<\/p>\n<\/li>\n<\/ul>\n<p><strong>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u0442\u043e\u043a\u0435\u043d\u0430. <\/strong><\/p>\n<p>\u0417\u0430\u043c\u0435\u0442\u0438\u043c, \u0447\u0442\u043e \u0432 residual stream, \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435, \u043c\u043d\u043e\u0433\u043e \u0442\u043e\u043a\u0435\u043d\u043e\u0432. \u041c\u044b \u0431\u0443\u0434\u0435\u043c \u0431\u0440\u0430\u0442\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439. <\/p>\n<p>GPT-2 \u2014 \u0430\u0432\u0442\u043e\u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u043e\u043d\u043d\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c \u0441 <strong>causal attention<\/strong>: \u0442\u043e\u043a\u0435\u043d \u043d\u0430 \u043f\u043e\u0437\u0438\u0446\u0438\u0438 <img decoding=\"async\" class=\"formula inline\" source=\"i\" alt=\"i\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/8\/86\/865\/865c0c0b4ab0e063e5caa3387c1a8741.svg\" width=\"12\" height=\"12\" data-width=\"0.781\" data-height=\"1.52\" data-vertical-align=\"-0.025\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/8\/86\/865\/865c0c0b4ab0e063e5caa3387c1a8741.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/8\/86\/865\/865c0c0b4ab0e063e5caa3387c1a8741.svg 781w\" loading=\"lazy\" decode=\"async\"\/> \u0432\u0438\u0434\u0438\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u043e\u043a\u0435\u043d\u044b \u0441 \u043f\u043e\u0437\u0438\u0446\u0438\u044f\u043c\u0438 <img decoding=\"async\" class=\"formula inline\" source=\"\\leq i\" alt=\"\\leq i\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/7\/7f\/7f8\/7f84b4a72de34e6626720b7b0c167f48.svg\" width=\"24\" height=\"16\" data-width=\"3.169\" data-height=\"2.262\" data-vertical-align=\"-0.566\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/7\/7f\/7f8\/7f84b4a72de34e6626720b7b0c167f48.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/7\/7f\/7f8\/7f84b4a72de34e6626720b7b0c167f48.svg 781w\" loading=\"lazy\" decode=\"async\"\/>. \u042d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e <strong>\u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0442\u043e\u043a\u0435\u043d \u0432\u0438\u0434\u0438\u0442 \u0432\u0435\u0441\u044c \u043f\u0440\u0435\u0434\u0448\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442<\/strong> \u0438 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0435\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c \u00ab\u0441\u0431\u043e\u0440\u0449\u0438\u043a\u043e\u043c\u00bb \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e \u043f\u0440\u043e\u043c\u043f\u0442\u0435.<\/p>\n<p>\u0410\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u044b \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u2014 \u0443\u0441\u0440\u0435\u0434\u043d\u0435\u043d\u0438\u0435 \u043f\u043e \u0432\u0441\u0435\u043c \u0442\u043e\u043a\u0435\u043d\u0430\u043c, \u0432\u0437\u0432\u0435\u0448\u0435\u043d\u043d\u043e\u0435 \u043f\u043e attention \u2014 \u043d\u043e \u043e\u043d\u0438 \u043d\u0435\u043f\u043e\u043d\u044f\u0442\u043d\u044b \u0434\u043b\u044f \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0446\u0438\u0438 \u0438 \u043f\u043e\u0447\u0442\u0438 \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f. <\/p>\n<p><strong>Hook.<\/strong><\/p>\n<p>Hook \u2014 \u044d\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f-\u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u0447\u0438\u043a, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0432\u044b \u00ab\u0432\u0435\u0448\u0430\u0435\u0442\u0435\u00bb \u043d\u0430 \u043c\u043e\u0434\u0443\u043b\u044c. \u041e\u043d\u0430 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u0440\u0438 \u043a\u0430\u0436\u0434\u043e\u043c forward pass:<\/p>\n<pre><code class=\"python\">handle = model.transformer.h[layer].register_forward_hook(hook_fn)# hook_fn(module, input, output) \u2014 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u043e\u0441\u043b\u0435 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0441\u043b\u043e\u044f<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:87px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>PyTorch \u0432\u044b\u0437\u043e\u0432\u0435\u0442 <code>hook_fn<\/code> \u0441\u0440\u0430\u0437\u0443 \u043f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u0441\u043b\u043e\u0439 \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435. \u041c\u043e\u0436\u043d\u043e:<\/p>\n<ul>\n<li>\n<p><strong>\u0447\u0438\u0442\u0430\u0442\u044c<\/strong> <code>output<\/code> \u0438 \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u0442\u044c \u0430\u043a\u0442\u0438\u0432\u0430\u0446\u0438\u0438 (\u043a\u0430\u043a \u0437\u0434\u0435\u0441\u044c)<\/p>\n<\/li>\n<li>\n<p><strong>\u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0442\u0435\u043d\u0437\u043e\u0440<\/strong> \u0438 \u0434\u0435\u043b\u0430\u0442\u044c steering<\/p>\n<\/li>\n<\/ul>\n<p>\u0422\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u2014\u00a0\u043f\u043e\u0441\u043b\u0435 \u0440\u0430\u0431\u043e\u0442\u044b \u2014 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e <code>handle.remove()<\/code>, \u0438\u043d\u0430\u0447\u0435 hook \u043e\u0441\u0442\u0430\u043d\u0435\u0442\u0441\u044f \u0432\u0438\u0441\u0435\u0442\u044c \u043d\u0430 \u043c\u043e\u0434\u0435\u043b\u0438 \u043d\u0430\u0432\u0441\u0435\u0433\u0434\u0430. \u041f\u0440\u0438\u043c\u0435\u0440 \u0445\u0443\u043a\u0430 \u2014 \u043d\u0438\u0436\u0435. \u0415\u0441\u043b\u0438 \u044f \u043d\u0430\u043a\u043e\u0441\u044f\u0447\u0438\u043b\u0430 \u0441 \u043e\u0442\u0441\u0442\u0443\u043f\u0430\u043c\u0438 \u2014\u00a0\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u0435, \u043d\u043e \u0443 \u0432\u0430\u0441 \u0431\u0443\u0434\u0435\u0442 \u0442\u0435\u0442\u0440\u0430\u0434\u044c. <\/p>\n<h2>\u041f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0435 steering vector<\/h2>\n<p>\u041c\u0435\u0442\u043e\u0434 \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f <strong>Contrastive Activation Addition (CAA)<\/strong> \u2014 \u0438\u0437 \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/arxiv.org\/pdf\/2312.06681\" rel=\"noopener noreferrer nofollow\">Steering Llama 2 via Contrastive Activation Addition<\/a>. \u0418\u0434\u0435\u044f: <\/p>\n<ol>\n<li>\n<p>\u0411\u0435\u0440\u0451\u043c \u0434\u0432\u0430 \u043d\u0430\u0431\u043e\u0440\u0430 \u043f\u0440\u043e\u043c\u043f\u0442\u043e\u0432: \u043f\u043e\u0437\u0438\u0442\u0438\u0432\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 <img decoding=\"async\" class=\"formula inline\" source=\"P^+\" alt=\"P^+\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/6\/67\/677\/6771351261db5d17c38f866156d7a682.svg\" width=\"24\" height=\"12\" data-width=\"3.257\" data-height=\"1.867\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/6\/67\/677\/6771351261db5d17c38f866156d7a682.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/6\/67\/677\/6771351261db5d17c38f866156d7a682.svg 781w\" loading=\"lazy\" decode=\"async\"\/> (tolerant) \u0438 \u043d\u0435\u0433\u0430\u0442\u0438\u0432\u043d\u044b\u0439 <img decoding=\"async\" class=\"formula inline\" source=\"P^-\" alt=\"P^-\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/4\/48\/482\/4824e5d7bbdaaa5e760a2f218550ea4c.svg\" width=\"24\" height=\"12\" data-width=\"3.257\" data-height=\"1.867\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/4\/48\/482\/4824e5d7bbdaaa5e760a2f218550ea4c.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/4\/48\/482\/4824e5d7bbdaaa5e760a2f218550ea4c.svg 781w\" loading=\"lazy\" decode=\"async\"\/> (hate).<\/p>\n<\/li>\n<li>\n<p>\u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u0440\u043e\u043c\u043f\u0442\u0430 \u0441\u043d\u0438\u043c\u0430\u0435\u043c \u0430\u043a\u0442\u0438\u0432\u0430\u0446\u0438\u044e \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u0442\u043e\u043a\u0435\u043d\u0430 \u043d\u0430 \u0441\u043b\u043e\u0435 $\\ell$.<\/p>\n<\/li>\n<li>\n<p>\u0412\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c \u0440\u0430\u0437\u043d\u043e\u0441\u0442\u044c \u0441\u0440\u0435\u0434\u043d\u0438\u0445:<\/p>\n<p><img decoding=\"async\" class=\"formula inline\" source=\"\\mathbf{v} = \\underbrace{\\frac{1}{|P^+|} \\sum_{i \\in P^+} \\mathbf{h}_i}_{\\text{mean(tolerant)}} \\;-\\; \\underbrace{\\frac{1}{|P^-|} \\sum_{j \\in P^-} \\mathbf{h}_j}_{\\text{mean(hate})}\" alt=\"\\mathbf{v} = \\underbrace{\\frac{1}{|P^+|} \\sum_{i \\in P^+} \\mathbf{h}_i}_{\\text{mean(tolerant)}} \\;-\\; \\underbrace{\\frac{1}{|P^-|} \\sum_{j \\in P^-} \\mathbf{h}_j}_{\\text{mean(hate})}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/d\/d5\/d55\/d55cce091f8b4bf1f97d266e17c35cdb.svg\" width=\"264\" height=\"72\" data-width=\"33.372\" data-height=\"9.713\" data-vertical-align=\"-4.291\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/d\/d5\/d55\/d55cce091f8b4bf1f97d266e17c35cdb.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/d\/d5\/d55\/d55cce091f8b4bf1f97d266e17c35cdb.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<\/li>\n<li>\n<p>\u041d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u0443\u0435\u043c: <img decoding=\"async\" class=\"formula inline\" source=\"\\hat{\\mathbf{v}} = \\mathbf{v} \/ \\|\\mathbf{v}\\|_2\" alt=\"\\hat{\\mathbf{v}} = \\mathbf{v} \/ \\|\\mathbf{v}\\|_2\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/1\/17\/171\/1719f1257fdaedf5cd3eb5f5ae316dda.svg\" width=\"88\" height=\"16\" data-width=\"11.518\" data-height=\"2.403\" data-vertical-align=\"-0.636\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/1\/17\/171\/1719f1257fdaedf5cd3eb5f5ae316dda.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/1\/17\/171\/1719f1257fdaedf5cd3eb5f5ae316dda.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<\/li>\n<\/ol>\n<p><strong>\u0421\u0442\u043e\u043f. \u0412\u0435\u0434\u044c \u043f\u0430\u0440\u0443 \u0430\u0431\u0437\u0430\u0446\u0435\u0432 \u0432\u044b\u0448\u0435 \u0442\u044b \u0441\u043a\u0430\u0437\u0430\u043b\u0430, \u0447\u0442\u043e \u0441\u0440\u0435\u0434\u043d\u0435\u0435 \u0431\u0435\u0441\u0441\u043c\u044b\u0441\u043b\u0435\u043d\u043d\u043e. <\/strong><\/p>\n<p>\u0421\u0440\u0435\u0434\u043d\u0435\u0435 \u043f\u043e \u0442\u043e\u043a\u0435\u043d\u0430\u043c \u0432\u043d\u0443\u0442\u0440\u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u2014 \u043d\u0435 \u0442\u043e, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0441\u043c\u0435\u0448\u0438\u0432\u0430\u0435\u0442 \u0440\u0430\u0437\u043d\u044b\u0435 \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0440\u043e\u043b\u0438.<\/p>\n<p>\u0421\u0440\u0435\u0434\u043d\u0435\u0435 \u0436\u0435 \u043f\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c \u2014  \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0430 \u043d\u0430\u0434 \u043f\u043e\u043d\u044f\u0442\u0438\u0435\u043c \u2014\u00a0\u0435\u0441\u043b\u0438 \u043f\u043e\u043d\u044f\u0442\u0438\u0435 <img decoding=\"async\" class=\"formula inline\" source=\"C\" alt=\"C\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0\/0d\/0d6\/0d61f8370cad1d412f80b84d143e1257.svg\" width=\"12\" height=\"12\" data-width=\"1.719\" data-height=\"1.645\" data-vertical-align=\"-0.05\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0\/0d\/0d6\/0d61f8370cad1d412f80b84d143e1257.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0\/0d\/0d6\/0d61f8370cad1d412f80b84d143e1257.svg 781w\" loading=\"lazy\" decode=\"async\"\/> (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, &#171;\u0442\u043e\u043a\u0441\u0438\u0447\u043d\u043e\u0441\u0442\u044c&#187;) \u043a\u043e\u0434\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0432 residual stream, \u0442\u043e \u043e\u043d\u043e \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044e <img decoding=\"async\" class=\"formula inline\" source=\"\\mathbf{v} \\in \\mathbb{R}^d\" alt=\"\\mathbf{v} \\in \\mathbb{R}^d\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0\/07\/072\/072bb2cf822feb69549ff48cd0c9bf77.svg\" width=\"48\" height=\"16\" data-width=\"6.792\" data-height=\"2.61\" data-vertical-align=\"-0.74\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0\/07\/072\/072bb2cf822feb69549ff48cd0c9bf77.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0\/07\/072\/072bb2cf822feb69549ff48cd0c9bf77.svg 781w\" loading=\"lazy\" decode=\"async\"\/>.<\/p>\n<p>\u0422\u043e\u0433\u0434\u0430 \u0430\u043a\u0442\u0438\u0432\u0430\u0446\u0438\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u0442\u043e\u043a\u0435\u043d\u0430 \u0434\u043b\u044f <img decoding=\"async\" class=\"formula inline\" source=\"i\" alt=\"i\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/8\/86\/865\/865c0c0b4ab0e063e5caa3387c1a8741.svg\" width=\"12\" height=\"12\" data-width=\"0.781\" data-height=\"1.52\" data-vertical-align=\"-0.025\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/8\/86\/865\/865c0c0b4ab0e063e5caa3387c1a8741.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/8\/86\/865\/865c0c0b4ab0e063e5caa3387c1a8741.svg 781w\" loading=\"lazy\" decode=\"async\"\/>-\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0440\u0430\u0441\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043a\u0430\u043a:<img decoding=\"async\" class=\"formula inline\" source=\"\\mathbf{x}i = \\mathbf{x}\\text{base} + \\alpha_i \\mathbf{v} + \\boldsymbol{\\varepsilon}_i\" alt=\"\\mathbf{x}i = \\mathbf{x}\\text{base} + \\alpha_i \\mathbf{v} + \\boldsymbol{\\varepsilon}_i\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/9\/9c\/9c6\/9c6e1930cfcae836fbb1672371cf8047.svg\" width=\"168\" height=\"16\" data-width=\"21.858\" data-height=\"2.262\" data-vertical-align=\"-0.566\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/9\/9c\/9c6\/9c6e1930cfcae836fbb1672371cf8047.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/9\/9c\/9c6\/9c6e1930cfcae836fbb1672371cf8047.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<p>\u0433\u0434\u0435 <img decoding=\"async\" class=\"formula inline\" source=\"\\alpha_i = +1\" alt=\"\\alpha_i = +1\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/5\/5b\/5ba\/5ba19a9793819a17628312bede9d2439.svg\" width=\"64\" height=\"16\" data-width=\"8.096\" data-height=\"2.262\" data-vertical-align=\"-0.566\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/5\/5b\/5ba\/5ba19a9793819a17628312bede9d2439.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/5\/5b\/5ba\/5ba19a9793819a17628312bede9d2439.svg 781w\" loading=\"lazy\" decode=\"async\"\/> \u0434\u043b\u044f \u043f\u043e\u0437\u0438\u0442\u0438\u0432\u043d\u044b\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432, <img decoding=\"async\" class=\"formula inline\" source=\"\\alpha_i = -1\" alt=\"\\alpha_i = -1\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/1\/11\/114\/1146bc25cffe38161275e38774b1128f.svg\" width=\"64\" height=\"16\" data-width=\"8.096\" data-height=\"2.262\" data-vertical-align=\"-0.566\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/1\/11\/114\/1146bc25cffe38161275e38774b1128f.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/1\/11\/114\/1146bc25cffe38161275e38774b1128f.svg 781w\" loading=\"lazy\" decode=\"async\"\/> \u0434\u043b\u044f \u043d\u0435\u0433\u0430\u0442\u0438\u0432\u043d\u044b\u0445, <img decoding=\"async\" class=\"formula inline\" source=\"\\boldsymbol{\\varepsilon}_i\" alt=\"\\boldsymbol{\\varepsilon}_i\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/f\/f1\/f16\/f16473e982614e8a1b81e28c5f484f74.svg\" width=\"12\" height=\"16\" data-width=\"1.937\" data-height=\"2.262\" data-vertical-align=\"-0.566\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/f\/f1\/f16\/f16473e982614e8a1b81e28c5f484f74.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/f\/f1\/f16\/f16473e982614e8a1b81e28c5f484f74.svg 781w\" loading=\"lazy\" decode=\"async\"\/> \u2014 \u0448\u0443\u043c.<\/p>\n<p>\u0422\u043e\u0433\u0434\u0430:<\/p>\n<p><img decoding=\"async\" class=\"formula inline\" source=\"\\bar{\\mathbf{x}}^+ - \\bar{\\mathbf{x}}^- = 2\\mathbf{v} + \\underbrace{(\\bar{\\boldsymbol{\\varepsilon}}^+ - \\bar{\\boldsymbol{\\varepsilon}}^-)}_{\\to 0 \\text{ \u043f\u0440\u0438 } N \\to \\infty}\" alt=\"\\bar{\\mathbf{x}}^+ - \\bar{\\mathbf{x}}^- = 2\\mathbf{v} + \\underbrace{(\\bar{\\boldsymbol{\\varepsilon}}^+ - \\bar{\\boldsymbol{\\varepsilon}}^-)}_{\\to 0 \\text{ \u043f\u0440\u0438 } N \\to \\infty}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/7\/71\/712\/71242c1f592a2e7f1a23264b7d95dd9a.svg\" width=\"216\" height=\"40\" data-width=\"27.364\" data-height=\"5.959\" data-vertical-align=\"-2.414\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/7\/71\/712\/71242c1f592a2e7f1a23264b7d95dd9a.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/7\/71\/712\/71242c1f592a2e7f1a23264b7d95dd9a.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<p>\u041d\u0430 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u0443 \u2014 \u0437\u0430\u0431\u0438\u043b\u0438. <\/p>\n<p><strong>\u041f\u043e\u0447\u0435\u043c\u0443 \u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u0443\u0435\u043c?<\/strong><\/p>\n<p>\u0411\u0435\u0437 \u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u043b\u0438\u043d\u0430 <img decoding=\"async\" class=\"formula inline\" source=\"\\mathbf{v}\" alt=\"\\mathbf{v}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/f\/fb\/fb1\/fb16e3e3f18c15edc61e1f2c0fa972ba.svg\" width=\"12\" height=\"16\" data-width=\"1.373\" data-height=\"2.262\" data-vertical-align=\"-0.566\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/f\/fb\/fb1\/fb16e3e3f18c15edc61e1f2c0fa972ba.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/f\/fb\/fb1\/fb16e3e3f18c15edc61e1f2c0fa972ba.svg 781w\" loading=\"lazy\" decode=\"async\"\/> \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442:<\/p>\n<ul>\n<li>\n<p>\u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u043f\u0440\u043e\u043c\u043f\u0442\u043e\u0432 \u0432 \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u0435<\/p>\n<\/li>\n<li>\n<p>\u00ab\u0440\u0430\u0437\u0431\u0440\u043e\u0441\u0430\u00bb \u0430\u043a\u0442\u0438\u0432\u0430\u0446\u0438\u0439 \u0432 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u043c \u0441\u043b\u043e\u0435<\/p>\n<\/li>\n<li>\n<p>\u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0430 \u0441\u0430\u043c\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u043e\u0441\u043b\u0435 \u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 <img decoding=\"async\" class=\"formula inline\" source=\"\\hat{\\mathbf{v}}\" alt=\"\\hat{\\mathbf{v}}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/7\/71\/718\/718268b1cf8ec5f2dc41998abbb88930.svg\" width=\"12\" height=\"16\" data-width=\"1.373\" data-height=\"2.403\" data-vertical-align=\"-0.636\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/7\/71\/718\/718268b1cf8ec5f2dc41998abbb88930.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/7\/71\/718\/718268b1cf8ec5f2dc41998abbb88930.svg 781w\" loading=\"lazy\" decode=\"async\"\/> \u2014 <strong>\u0435\u0434\u0438\u043d\u0438\u0447\u043d\u044b\u0439 \u0432\u0435\u043a\u0442\u043e\u0440<\/strong>, \u0438 <img decoding=\"async\" class=\"formula inline\" source=\"\\alpha\" alt=\"\\alpha\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/7\/7b\/7b7\/7b7f9dbfea05c83784f8b85149852f08.svg\" width=\"12\" height=\"16\" data-width=\"1.448\" data-height=\"2.262\" data-vertical-align=\"-0.566\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/7\/7b\/7b7\/7b7f9dbfea05c83784f8b85149852f08.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/7\/7b\/7b7\/7b7f9dbfea05c83784f8b85149852f08.svg 781w\" loading=\"lazy\" decode=\"async\"\/> \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c, \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u043c \u0441\u0438\u043b\u043e\u0439 \u0432\u043c\u0435\u0448\u0430\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u0430. <\/p>\n<pre><code class=\"python\">def build_steering_vector(pos_prompts: List[str], neg_prompts: List[str], layer: int) -&gt; torch.Tensor:    pos = get_block_output_activations(pos_prompts, layer)    neg = get_block_output_activations(neg_prompts, layer)    vec = (pos - neg).mean(dim=0)    vec = vec \/ (vec.norm() + 1e-8)    return vec.to(DEVICE)STEER_LAYER = 6steering_vector = build_steering_vector(positive_prompts, negative_prompts, STEER_LAYER)print(\"vector shape:\", steering_vector.shape)print(\"norm:\", steering_vector.norm().item()) # \u041f\u043e\u0434\u0443\u043c\u0430\u0439\u0442\u0435, \u043f\u043e\u0447\u0435\u043c\u0443 \u043d\u043e\u0440\u043c\u0430 \u0440\u0430\u0432\u043d\u0430 \u0435\u0434\u0438\u043d\u0438\u0446\u0435. # \u0415\u0441\u043b\u0438 \u0432\u044b \u043d\u0435 \u0434\u0430\u043b\u0438 \u043e\u0442\u0432\u0435\u0442 \u0441\u0445\u043e\u0434\u0443 \u2014\u00a0\u0432\u0435\u0440\u043d\u0438\u0442\u0435\u0441\u044c \u043a \u0442\u0435\u043e\u0440\u0438\u0438!<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<h2>Sanity check<\/h2>\n<p>\u0427\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u044f\u0442\u044c, \u0441\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u043d\u043d\u044b\u0439 \u0432\u0435\u043a\u0442\u043e\u0440 \u043e\u0441\u043c\u044b\u0441\u043b\u0435\u043d\u043d\u0435\u0435, \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0435\u043a\u0446\u0438\u044e \u0432 \u0441\u0435\u043c\u0430\u043d\u0442\u0438\u043a\u0443 \u043c\u0435\u0442\u043e\u0434\u043e\u043c logit lens. \u041f\u0440\u043e \u043d\u0435\u0433\u043e \u044f <a href=\"https:\/\/habr.com\/ru\/articles\/891352\/\" rel=\"noopener noreferrer nofollow\">\u043f\u0438\u0441\u0430\u043b\u0430<\/a> (\u043d\u043e \u0434\u043b\u044f \u043a\u0430\u0440\u0442\u0438\u043d\u043e\u043a), \u0434\u043b\u044f \u0442\u0435\u043a\u0441\u0442\u043e\u0432 \u0442\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435 \u2014 \u043c\u044b \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0432\u0435\u043a\u0442\u043e\u0440 \u0447\u0435\u0440\u0435\u0437 <code>lm_head<\/code> \u0438 \u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a\u0438\u0435 \u0442\u043e\u043a\u0435\u043d\u044b \u043e\u043d \u00ab\u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0438\u0442\u0430\u0435\u0442\u00bb \u0438 \u00ab\u0438\u0437\u0431\u0435\u0433\u0430\u0435\u0442\u00bb.<\/p>\n<p>\u0422\u043e, \u0447\u0442\u043e \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c, \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0442\u043e\u0447\u043d\u043e \u2014\u00a0 \u0432\u0435\u043a\u0442\u043e\u0440 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0435 \u0430\u043a\u0442\u0438\u0432\u0430\u0446\u0438\u0439 residual stream, \u0430 \u043d\u0435 \u0444\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u043c logit-\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0435, \u043d\u043e \u0434\u0430\u0441\u0442 \u0438\u043d\u0442\u0443\u0438\u0446\u0438\u044e \u043e \u0441\u0435\u043c\u0430\u043d\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u043c \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0438 \u0432\u0435\u043a\u0442\u043e\u0440\u0430 \u2014 \u0438 \u043e\u0442\u0441\u044e\u0434\u0430 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u043e \u043a\u0430\u043a sanity check. \u041d\u0430 \u043f\u043e\u0434\u043e\u043f\u044b\u0442\u043d\u043e\u043c \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u0435, \u043c\u044b \u0441 \u0432\u0430\u043c\u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<div class=\"floating-image\">\n<figure class=\"float bordered full-width \"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/435\/047\/925\/4350479251a7fb8b091a1b390906e8a8.png\" width=\"724\" height=\"868\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/435\/047\/925\/4350479251a7fb8b091a1b390906e8a8.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/435\/047\/925\/4350479251a7fb8b091a1b390906e8a8.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<p>\u0421\u043f\u0438\u0441\u043e\u043a \u043f\u0440\u043e\u0442\u0438\u0432 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0441\u044f \u0432\u043f\u043e\u043b\u043d\u0435 \u0441\u0435\u0431\u0435 hate, \u043e\u0434\u043d\u0430\u043a\u043e \u0441\u043f\u0438\u0441\u043e\u043a \u0441 \u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438 \u0432\u044b\u0448\u0435\u043b \u0448\u0443\u043c\u043d\u044b\u043c \u2014\u00a0\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043c\u0443\u0441\u043e\u0440 \u0434\u043b\u044f \u043d\u0430\u0448\u0435\u0439 \u0437\u0430\u0434\u0430\u0447\u0438 \u2014 \u0442\u043e\u0447\u043d\u043e \u0442\u043e\u043a\u0435\u043d\u044b stellar, NAV, incorpor, eele. \u041e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u043c\u044b \u043d\u0430\u0448\u043b\u0438 \u043d\u0435 \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u044b\u0439 \u0432\u0435\u043a\u0442\u043e\u0440, \u043e\u043d \u043a\u043e\u0434\u0438\u0440\u0443\u0435\u0442 \u043e\u0441\u044c &#171;\u0430\u0433\u0440\u0435\u0441\u0441\u0438\u0432\u043d\u0430\u044f \u043b\u0435\u043a\u0441\u0438\u043a\u0430 vs \u0447\u0442\u043e-\u0442\u043e \u0435\u0449\u0451&#187;, \u0430 \u043d\u0435 \u0441\u0442\u0440\u043e\u0433\u043e &#171;hate vs tolerant&#187;.<\/p>\n<p>\u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u043d\u0430\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u043c\u0435\u0435\u0442 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0448\u0443\u043c \u2014 \u043e\u043d \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0444\u0440\u0430\u0437, \u0433\u0434\u0435 \u043e\u043f\u043f\u043e\u0437\u0438\u0442 \u2014 \u043b\u0438\u0448\u044c \u043e\u0442\u0440\u0438\u0446\u0430\u043d\u0438\u0435 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, &#171;Blacks are not dangerous&#187;). \u0422\u0430\u043a\u0438\u0435 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442 hate-\u0442\u0435\u043c\u0443 \u043a\u0430\u043a \u0441\u0443\u0431\u044a\u0435\u043a\u0442 \u0438 \u043c\u043e\u0434\u0435\u043b\u044c \u043c\u043e\u0436\u0435\u0442 \u0430\u043a\u0442\u0438\u0432\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0430 \u043d\u0438\u0445 hate-\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435. \u0420\u0430\u0437\u043d\u043e\u0441\u0442\u044c \u0441\u0440\u0435\u0434\u043d\u0438\u0445 \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0437\u0430\u0448\u0443\u043c\u043b\u0435\u043d\u0430 \u043f\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044e. <\/p>\n<\/div>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e, \u043d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0432\u0441\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f, \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 hate speech \u043c\u044b \u0438\u043c\u0435\u0435\u043c, \u0438 \u0432\u0441\u0451 \u0440\u0430\u0432\u043d\u043e \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0434\u043b\u044f \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0438. \u041e\u0434\u043d\u0430\u043a\u043e \u0443\u0447\u0442\u0435\u043c \u043d\u0435 \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u0443\u044e \u043f\u043e\u043b\u044f\u0440\u043d\u043e\u0441\u0442\u044c. \u0418 \u043d\u0430 \u044d\u0442\u043e\u043c \u043c\u0435\u0441\u0442\u0435 \u0441\u0430\u043c\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u0434\u043e\u0441\u0442\u0430\u0442\u044c \u043d\u0430\u0448\u0443 \u043e\u0442\u043b\u043e\u0436\u043a\u0443 \u0438\u0437 \u043f\u0430\u043c\u044f\u0442\u0438! \u041f\u043e\u043c\u043d\u0438\u0442\u0435, \u0447\u0442\u043e<em> &#171;positive&#187; \u0438 &#171;negative&#187; \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043e\u043c?  <\/em>\u0412\u043e\u0442 \u0432\u0430\u043c \u0438 \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u043e\u0435 gargbage in = garbage out. <\/p>\n<h2>\u0421\u0442\u0438\u0440\u0438\u043c <\/h2>\n<p><strong>\u041a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0432\u0435\u043d\u0446\u0438\u044f<\/strong><\/p>\n<p>\u041d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c decode-\u0448\u0430\u0433\u0435 (\u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u043e\u0434\u043d\u043e\u0433\u043e \u043d\u043e\u0432\u043e\u0433\u043e \u0442\u043e\u043a\u0435\u043d\u0430) \u043c\u043e\u0434\u0435\u043b\u044c \u0434\u0435\u043b\u0430\u0435\u0442 \u043f\u043e\u043b\u043d\u044b\u0439 forward pass. \u041d\u0430\u0448 hook \u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0432\u044b\u0445\u043e\u0434 \u0441\u043b\u043e\u044f <img decoding=\"async\" class=\"formula inline\" source=\"\\ell\" alt=\"\\ell\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/e\/ee\/ee5\/ee5e5c003694e7cd5ae404923c665edb.svg\" width=\"12\" height=\"16\" data-width=\"0.943\" data-height=\"2.262\" data-vertical-align=\"-0.566\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/e\/ee\/ee5\/ee5e5c003694e7cd5ae404923c665edb.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/e\/ee\/ee5\/ee5e5c003694e7cd5ae404923c665edb.svg 781w\" loading=\"lazy\" decode=\"async\"\/> \u0438 \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u0443\u0435\u0442 \u0435\u0433\u043e:<br \/><img decoding=\"async\" class=\"formula inline\" source=\"\\mathbf{x}^{(\\ell+1)} \\;\\leftarrow\\; \\mathbf{x}^{(\\ell+1)} + \\alpha \\cdot \\hat{\\mathbf{v}}\" alt=\"\\mathbf{x}^{(\\ell+1)} \\;\\leftarrow\\; \\mathbf{x}^{(\\ell+1)} + \\alpha \\cdot \\hat{\\mathbf{v}}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/2\/24\/247\/2473c97f0d4b07fadbc8f314d8bc3713.svg\" width=\"184\" height=\"16\" data-width=\"23.033\" data-height=\"2.7\" data-vertical-align=\"-0.784\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/2\/24\/247\/2473c97f0d4b07fadbc8f314d8bc3713.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/2\/24\/247\/2473c97f0d4b07fadbc8f314d8bc3713.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<p>\u0414\u0430\u043b\u044c\u0448\u0435 \u0441\u043b\u043e\u0438 <img decoding=\"async\" class=\"formula inline\" source=\"\\ell+1, \\ell+2, \\ldots\" alt=\"\\ell+1, \\ell+2, \\ldots\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/5\/5b\/5b1\/5b1d2198f7374b4bffe2b43a3a637441.svg\" width=\"112\" height=\"16\" data-width=\"14.344\" data-height=\"2.262\" data-vertical-align=\"-0.566\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/5\/5b\/5b1\/5b1d2198f7374b4bffe2b43a3a637441.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/5\/5b\/5b1\/5b1d2198f7374b4bffe2b43a3a637441.svg 781w\" loading=\"lazy\" decode=\"async\"\/> \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u044e\u0442 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0443\u0436\u0435 \u0441 \u0438\u0437\u043c\u0435\u043d\u0451\u043d\u043d\u044b\u043c \u0442\u0435\u043d\u0437\u043e\u0440\u043e\u043c. \u041f\u0440\u0438 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u043d\u043e\u0432\u044b\u0445 \u0442\u043e\u043a\u0435\u043d\u043e\u0432 \u0432\u043c\u0435\u0448\u0430\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u043e \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u0435\u0442\u0441\u044f <strong>\u043f\u0440\u0438 \u043a\u0430\u0436\u0434\u043e\u043c decode-\u0448\u0430\u0433\u0435<\/strong> \u2014 \u043c\u043e\u0434\u0435\u043b\u044c \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u043e\u0434 \u0432\u043e\u0437\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435\u043c \u0432\u0435\u043a\u0442\u043e\u0440\u0430.<\/p>\n<p><strong>\u041f\u043e\u0447\u0435\u043c\u0443 \u043e\u043d\u0430 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442?<\/strong><\/p>\n<p>\u041e\u0442\u0432\u0435\u0442 \u0434\u0430\u0451\u0442 \u043d\u0430\u0448\u0435 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u2014\u00a0\u0435\u0441\u043b\u0438 \u043f\u043e\u043d\u044f\u0442\u0438\u0435 \u00abtolerant\u00bb \u043a\u043e\u0434\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0435 \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 <img decoding=\"async\" class=\"formula inline\" source=\"\\hat{\\mathbf{v}}\" alt=\"\\hat{\\mathbf{v}}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/7\/71\/718\/718268b1cf8ec5f2dc41998abbb88930.svg\" width=\"12\" height=\"16\" data-width=\"1.373\" data-height=\"2.403\" data-vertical-align=\"-0.636\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/7\/71\/718\/718268b1cf8ec5f2dc41998abbb88930.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/7\/71\/718\/718268b1cf8ec5f2dc41998abbb88930.svg 781w\" loading=\"lazy\" decode=\"async\"\/>, \u0442\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 <img decoding=\"async\" class=\"formula inline\" source=\"\\alpha \\hat{\\mathbf{v}}\" alt=\"\\alpha \\hat{\\mathbf{v}}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/1\/13\/138\/138ff231442b398894f1d228fad9229b.svg\" width=\"16\" height=\"16\" data-width=\"2.821\" data-height=\"2.403\" data-vertical-align=\"-0.636\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/1\/13\/138\/138ff231442b398894f1d228fad9229b.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/1\/13\/138\/138ff231442b398894f1d228fad9229b.svg 781w\" loading=\"lazy\" decode=\"async\"\/> \u043a \u0430\u043a\u0442\u0438\u0432\u0430\u0446\u0438\u0438 \u0431\u0443\u043a\u0432\u0430\u043b\u044c\u043d\u043e <strong>\u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0430\u0435\u0442<\/strong> \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u0432 \u0442\u0443 \u0447\u0430\u0441\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0430\u0441\u0441\u043e\u0446\u0438\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0441 \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u043e\u0439 \u043f\u043e\u043b\u044f\u0440\u043d\u043e\u0441\u0442\u044c\u044e.<\/p>\n<p>\u0421\u043b\u043e\u0438, \u0441\u0442\u043e\u044f\u0449\u0438\u0435 \u0432\u044b\u0448\u0435 <img decoding=\"async\" class=\"formula inline\" source=\"\\ell\" alt=\"\\ell\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/e\/ee\/ee5\/ee5e5c003694e7cd5ae404923c665edb.svg\" width=\"12\" height=\"16\" data-width=\"0.943\" data-height=\"2.262\" data-vertical-align=\"-0.566\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/e\/ee\/ee5\/ee5e5c003694e7cd5ae404923c665edb.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/e\/ee\/ee5\/ee5e5c003694e7cd5ae404923c665edb.svg 781w\" loading=\"lazy\" decode=\"async\"\/>, \u00ab\u0432\u0438\u0434\u044f\u0442\u00bb \u0441\u043c\u0435\u0449\u0451\u043d\u043d\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0438 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u044e\u0442 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u043a\u0430\u043a \u0431\u0443\u0434\u0442\u043e \u044d\u0442\u043e\u0442 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u0431\u044b\u043b \u0432 \u043d\u0443\u0436\u043d\u044e-\u0441\u0442\u043e\u0440\u043e\u043d\u0443-\u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c. \u042d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0435\u0440\u044b \u0441 residual connections \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u044e\u0442 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u0430\u0434\u0434\u0438\u0442\u0438\u0432\u043d\u043e \u2014 \u043a\u0430\u0436\u0434\u044b\u0439 \u0441\u043b\u043e\u0439 \u0447\u0438\u0442\u0430\u0435\u0442 \u0438\u0437 \u043e\u0431\u0449\u0435\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430 \u0438 \u043f\u0438\u0448\u0435\u0442 \u0432 \u043d\u0435\u0433\u043e. \u041d\u0430\u0448\u0430 \u0434\u043e\u0431\u0430\u0432\u043a\u0430 \u043d\u0435 \u00ab\u043b\u043e\u043c\u0430\u0435\u0442\u00bb \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u2014 \u043e\u043d\u0430 \u0441\u043c\u0435\u0449\u0430\u0435\u0442  \u0442\u043e\u0447\u043a\u0443 \u043e\u0442\u0441\u0447\u0451\u0442\u0430.<\/p>\n<p><strong>\u0410 \u043a\u0443\u0434\u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c?<\/strong><\/p>\n<p>\u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043a\u0430\u043a \u043d\u0430 \u0432\u0441\u0435 \u0442\u043e\u043a\u0435\u043d\u044b, \u0442\u0430\u043a \u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439. \u041d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a\u0438 \u0442\u0430\u043a\u0438\u0435:<\/p>\n<ul>\n<li>\n<p><code><strong>last<\/strong><\/code>: \u0441\u0434\u0432\u0438\u0433\u0430\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0437\u0438\u0446\u0438\u044e \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u0442\u043e\u043a\u0435\u043d\u0430 \u2014 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0432\u043c\u0435\u0448\u0430\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u043e, \u043c\u0435\u043d\u044c\u0448\u0435 \u043f\u043e\u0431\u043e\u0447\u043d\u044b\u0445 \u044d\u0444\u0444\u0435\u043a\u0442\u043e\u0432, \u0432\u043b\u0438\u044f\u0435\u0442 \u043d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0439 \u0442\u043e\u043a\u0435\u043d \u0447\u0435\u0440\u0435\u0437 attention \u0434\u0430\u043b\u044c\u0448\u0435 \u043f\u043e \u0441\u0435\u0442\u0438<\/p>\n<\/li>\n<li>\n<p><code><strong>all<\/strong><\/code>: \u0441\u0434\u0432\u0438\u0433\u0430\u0435\u043c \u0432\u0441\u0435 \u043f\u043e\u0437\u0438\u0446\u0438\u0438 \u2014 \u0431\u043e\u043b\u0435\u0435 \u0430\u0433\u0440\u0435\u0441\u0441\u0438\u0432\u043d\u043e, \u043c\u0435\u043d\u044f\u0435\u0442 \u0432\u0435\u0441\u044c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 attention \u0431\u0443\u0434\u0435\u0442 \u0447\u0438\u0442\u0430\u0442\u044c \u043d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0441\u043b\u043e\u044f\u0445<\/p>\n<\/li>\n<\/ul>\n<p>\u0414\u043b\u044f baseline-\u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u043e\u0432 \u043e\u0431\u044b\u0447\u043d\u043e \u0431\u0435\u0440\u0443\u0442 <code>all<\/code> \u2014 \u044d\u0444\u0444\u0435\u043a\u0442 \u0441\u0438\u043b\u044c\u043d\u0435\u0435 \u0438 \u043b\u0435\u0433\u0447\u0435 \u0437\u0430\u043c\u0435\u0442\u0435\u043d. \u041d\u043e \u0432 \u043d\u043e\u0443\u0442\u0431\u0443\u043a\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f <code>last.<\/code> <\/p>\n<h2>\u0422\u0435\u043f\u0435\u0440\u044c \u0442\u043e\u0447\u043d\u043e \u0441\u0442\u0438\u0440\u0438\u043c. <\/h2>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u0435 \u043d\u043e\u0443\u0442\u0431\u0443\u043a (\u0430 \u044f \u0433\u043e\u0440\u044f\u0447\u043e (\u0438\u043c\u0435\u043d\u043d\u043e \u044d\u0442\u043e \u0441\u043b\u043e\u0432\u043e!) \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e \u044d\u0442\u043e), \u0442\u043e \u0443\u0432\u0438\u0434\u0438\u0442\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0443. <\/p>\n<div class=\"floating-image\">\n<figure class=\"float full-width \"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/177\/39a\/849\/17739a8497668a76aa6561b18e9380ca.png\" width=\"860\" height=\"466\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/177\/39a\/849\/17739a8497668a76aa6561b18e9380ca.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/177\/39a\/849\/17739a8497668a76aa6561b18e9380ca.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<p>\u0412\u0435\u043a\u0442\u043e\u0440 \u043e\u043a\u0430\u0437\u0430\u043b\u0441\u044f \u0438\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d: alpha &gt; 0 \u0434\u0432\u0438\u0433\u0430\u0435\u0442 \u043c\u043e\u0434\u0435\u043b\u044c \u0432 \u0441\u0442\u043e\u0440\u043e\u043d\u0443 hate, \u0430 \u043d\u0435 tolerant. \u042d\u0442\u043e \u043e\u0434\u0438\u043d \u0438\u0437 \u0442\u0438\u043f\u0438\u0447\u043d\u044b\u0445<strong> failure mode <\/strong>\u043a\u043e\u043d\u0442\u0440\u0430\u0441\u0442\u0438\u0432\u043d\u044b\u0445 \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u043e\u0432 \u0441 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u043f\u0430\u0440\u0430\u043c\u0438 \u2014 tolerant-\u043f\u0440\u0438\u043c\u0435\u0440\u044b \u043b\u0435\u043a\u0441\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u043e\u0445\u043e\u0436\u0438 \u043d\u0430 hate (\u0442\u0435 \u0436\u0435 \u0441\u0443\u0431\u044a\u0435\u043a\u0442\u044b, \u0442\u0430 \u0436\u0435 \u0442\u0435\u043c\u0430), \u0438 \u043c\u043e\u0434\u0435\u043b\u044c \u0430\u043a\u0442\u0438\u0432\u0438\u0440\u0443\u0435\u0442 hate-\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043d\u0430 \u043e\u0431\u043e\u0438\u0445 \u043a\u043b\u0430\u0441\u0441\u0430\u0445. \u0420\u0430\u0437\u043d\u043e\u0441\u0442\u044c \u0441\u0440\u0435\u0434\u043d\u0438\u0445 \u0442\u043e\u0433\u0434\u0430 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043d\u0435 \u0442\u0443\u0434\u0430, \u043a\u0443\u0434\u0430 \u043e\u0436\u0438\u0434\u0430\u043b\u043e\u0441\u044c. <\/p>\n<\/div>\n<div class=\"persona\"><img decoding=\"async\" class=\"image persona__image\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/d2a\/d70\/f26\/d2ad70f26240c9e4307b893dac85d58e.jpg\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/d2a\/d70\/f26\/d2ad70f26240c9e4307b893dac85d58e.jpg 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/d2a\/d70\/f26\/d2ad70f26240c9e4307b893dac85d58e.jpg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<h5 class=\"persona__heading\">\u041d\u0435 \u0431\u0430\u0433 \u2014\u00a0\u0444\u0438\u0447\u0430. <\/h5>\n<p class=\"persona__text\"> \u0414\u043b\u044f \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0441\u043e\u0433\u043b\u0430\u0441\u043e\u0432\u0430\u043d\u043d\u043e\u0441\u0442\u0438 \u043c\u044b \u043c\u043e\u0433\u043b\u0438 \u0431\u044b \u0438\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u0435\u043a\u0442\u043e\u0440, \u043d\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043f\u0440\u043e\u0449\u0435, \u0438 \u0434\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u0434\u043b\u044f \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u043e\u0433\u043e \u0432\u0435\u043a\u0442\u043e\u0440\u0430: <\/p>\n<p>&#8212; alpha &lt; 0 \u0434\u0432\u0438\u0433\u0430\u0435\u0442 \u043c\u043e\u0434\u0435\u043b\u044c \u0432 \u0441\u0442\u043e\u0440\u043e\u043d\u0443 hate, <br \/>&#8212; alpha &gt; 0 \u2014 \u0432 \u0441\u0442\u043e\u0440\u043e\u043d\u0443 tolerant. <\/p>\n<p>\u0417\u043d\u0430\u043a \u043f\u043e\u0434\u043e\u0431\u0440\u0430\u043d \u044d\u043c\u043f\u0438\u0440\u0438\u0447\u0435\u0441\u043a\u0438 \u0447\u0435\u0440\u0435\u0437 \u0442\u0435\u0441\u0442 \u043d\u0430 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438, \u0430 \u043d\u0435 \u0438\u0437 \u043b\u043e\u0433\u0438\u043a\u0438 \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u0430 \u0432 \u0441\u0438\u043b\u0443 \u043d\u0435\u0438\u0434\u0435\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043a\u043e\u043d\u0442\u0440\u0430\u0441\u0442\u0430. \u042d\u0442\u043e \u043d\u043e\u0440\u043c.<\/p>\n<\/div>\n<p>Logit lens, \u043a\u0441\u0442\u0430\u0442\u0438, \u044d\u0442\u043e\u0433\u043e \u043d\u0435 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043b \u2014 \u043e\u043d \u043f\u043e\u043a\u0430\u0437\u0430\u043b hate-\u0442\u043e\u043a\u0435\u043d\u044b \u043d\u0430 \u043c\u0438\u043d\u0443\u0441-\u0441\u0442\u043e\u0440\u043e\u043d\u0435, \u0442\u043e \u0435\u0441\u0442\u044c \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u043b \u00ab\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u00bb. \u042d\u0442\u043e \u043d\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u043d\u0438\u0435, \u0447\u0442\u043e logit lens \u2014 \u0430\u043f\u043f\u0440\u043e\u043a\u0441\u0438\u043c\u0430\u0446\u0438\u044f: \u043e\u043d \u043f\u0440\u043e\u0435\u0446\u0438\u0440\u0443\u0435\u0442 \u0432\u0435\u043a\u0442\u043e\u0440 \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0447\u0435\u0440\u0435\u0437 lm_head, \u0438\u0433\u043d\u043e\u0440\u0438\u0440\u0443\u044f \u0442\u043e, \u0447\u0442\u043e \u0441 \u0432\u043e\u0437\u043c\u0443\u0449\u0435\u043d\u0438\u0435\u043c \u0441\u0434\u0435\u043b\u0430\u044e\u0442 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0441\u043b\u043e\u0438. \u042d\u043c\u043f\u0438\u0440\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0442\u0435\u0441\u0442 \u043d\u0430 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u043d\u0430\u0434\u0451\u0436\u043d\u0435\u0435. \u041c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u0438\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0432\u0435\u043a\u0442\u043e\u0440 \u0438 \u0434\u0432\u0438\u0433\u0430\u0435\u043c\u0441\u044f \u0434\u0430\u043b\u044c\u0448\u0435.<\/p>\n<div class=\"floating-image\">\n<p>\u041e\u0441\u0442\u0430\u043b\u0441\u044f \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u0439 \u0432\u043e\u043f\u0440\u043e\u0441: \u043a\u0430\u043a\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 alpha \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u0434\u043b\u044f \u0441\u0442\u0430\u0440\u0442\u0430? \u0421\u043b\u0438\u0448\u043a\u043e\u043c \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u043e\u0435 \u2014 \u044d\u0444\u0444\u0435\u043a\u0442 \u043d\u0435\u0437\u0430\u043c\u0435\u0442\u0435\u043d, \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u2014 \u043c\u043e\u0434\u0435\u043b\u044c \u0442\u0435\u0440\u044f\u0435\u0442 \u043a\u043e\u0433\u0435\u0440\u0435\u043d\u0442\u043d\u043e\u0441\u0442\u044c (\u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u044c \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0432\u044f\u0437\u043d\u044b\u0439 \u0442\u0435\u043a\u0441\u0442).<\/p>\n<\/div>\n<p><strong>\u041e\u0442\u043a\u0443\u0434\u0430 \u0431\u0440\u0430\u0442\u044c init <\/strong><img decoding=\"async\" class=\"formula inline\" source=\"\\alpha\" alt=\"\\alpha\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/7\/7b\/7b7\/7b7f9dbfea05c83784f8b85149852f08.svg\" width=\"12\" height=\"16\" data-width=\"1.448\" data-height=\"2.262\" data-vertical-align=\"-0.566\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/7\/7b\/7b7\/7b7f9dbfea05c83784f8b85149852f08.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/7\/7b\/7b7\/7b7f9dbfea05c83784f8b85149852f08.svg 781w\" loading=\"lazy\" decode=\"async\"\/><strong>?<\/strong><\/p>\n<p>\u0414\u043e\u0441\u0442\u0430\u043d\u0435\u043c \u043d\u0430\u0448\u0435 \u0437\u043d\u0430\u043d\u0438\u0435 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e steering vector \u043d\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d: <img decoding=\"async\" class=\"formula inline\" source=\"|\\hat{\\mathbf{v}}| = 1\" alt=\"|\\hat{\\mathbf{v}}| = 1\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0\/06\/060\/0608cc312e5c07414d296310d8c76f7a.svg\" width=\"48\" height=\"16\" data-width=\"6.78\" data-height=\"2.403\" data-vertical-align=\"-0.636\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0\/06\/060\/0608cc312e5c07414d296310d8c76f7a.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0\/06\/060\/0608cc312e5c07414d296310d8c76f7a.svg 781w\" loading=\"lazy\" decode=\"async\"\/>. \u041e\u0442\u043a\u0443\u0434\u0430 <img decoding=\"async\" class=\"formula inline\" source=\"\\alpha\" alt=\"\\alpha\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/7\/7b\/7b7\/7b7f9dbfea05c83784f8b85149852f08.svg\" width=\"12\" height=\"16\" data-width=\"1.448\" data-height=\"2.262\" data-vertical-align=\"-0.566\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/7\/7b\/7b7\/7b7f9dbfea05c83784f8b85149852f08.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/7\/7b\/7b7\/7b7f9dbfea05c83784f8b85149852f08.svg 781w\" loading=\"lazy\" decode=\"async\"\/> \u2014 \u044d\u0442\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0435\u0434\u0438\u043d\u0438\u0446, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043c\u044b \u0441\u0434\u0432\u0438\u0433\u0430\u0435\u043c \u0430\u043a\u0442\u0438\u0432\u0430\u0446\u0438\u044e \u0432\u0434\u043e\u043b\u044c \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043a\u043e\u043d\u0446\u0435\u043f\u0442\u0430. \u0421\u0434\u0432\u0438\u0433 \u043e\u0441\u043c\u044b\u0441\u043b\u0435\u043d \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0442\u043e\u0433\u043e, \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0435\u043b\u0438\u043a\u0438 \u0441\u0430\u043c\u0438 \u0430\u043a\u0442\u0438\u0432\u0430\u0446\u0438\u0438 \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u043e\u0435. \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u0430\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043d\u0430\u044f \u0442\u043e\u0447\u043a\u0430 \u2014 \u0432\u0437\u044f\u0442\u044c \u0441\u0440\u0435\u0434\u043d\u044e\u044e \u043d\u043e\u0440\u043c\u0443 \u0430\u043a\u0442\u0438\u0432\u0430\u0446\u0438\u0439 \u043d\u0430 \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u043e\u0435:<br \/><img decoding=\"async\" class=\"formula inline\" source=\"\\alpha_\\text{init} \\approx  \\mathbb{E}\\bigl[|\\mathbf{h}^{(\\ell)}|\\bigr]\" alt=\"\\alpha_\\text{init} \\approx  \\mathbb{E}\\bigl[|\\mathbf{h}^{(\\ell)}|\\bigr]\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/1\/1c\/1cb\/1cb713c0b7b967318e2fbcf8190f1e93.svg\" width=\"120\" height=\"16\" data-width=\"15.253\" data-height=\"2.925\" data-vertical-align=\"-0.897\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/1\/1c\/1cb\/1cb713c0b7b967318e2fbcf8190f1e93.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/1\/1c\/1cb\/1cb713c0b7b967318e2fbcf8190f1e93.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<p>\u0438 \u0431\u0440\u0430\u0442\u044c \u0441\u043a\u043e\u043b\u044c\u043a\u043e-\u0442\u043e \u043e\u0442 \u043d\u0435\u0435. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043d\u0430\u0447\u0430\u0442\u044c \u0441 10% \u043e\u0442 \u0442\u0438\u043f\u0438\u0447\u043d\u043e\u0439 \u043d\u043e\u0440\u043c\u044b \u0438 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0442\u044c \u0432\u0434\u0432\u043e\u0435 \u0434\u043e \u0442\u0435\u0445 \u043f\u043e\u0440, \u043f\u043e\u043a\u0430 \u043d\u0435 \u043f\u043e\u044f\u0432\u0438\u0442\u0441\u044f \u044d\u0444\u0444\u0435\u043a\u0442. \u041d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u0434\u043b\u044f GPT-2 \u044d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 <img decoding=\"async\" class=\"formula inline\" source=\"\\alpha \\in [20, 100]\" alt=\"\\alpha \\in [20, 100]\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/a\/a0\/a07\/a078f7127381cfe404fab8c8ee1c3ea9.svg\" width=\"96\" height=\"16\" data-width=\"12.134\" data-height=\"2.262\" data-vertical-align=\"-0.566\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/a\/a0\/a07\/a078f7127381cfe404fab8c8ee1c3ea9.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/a\/a0\/a07\/a078f7127381cfe404fab8c8ee1c3ea9.svg 781w\" loading=\"lazy\" decode=\"async\"\/>, \u0434\u043b\u044f \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u2014 \u0434\u0440\u0443\u0433\u043e\u0439 \u043c\u0430\u0441\u0448\u0442\u0430\u0431. \u0421\u043b\u0438\u0448\u043a\u043e\u043c \u0431\u043e\u043b\u044c\u0448\u043e\u0439 <img decoding=\"async\" class=\"formula inline\" source=\"\\alpha\" alt=\"\\alpha\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/7\/7b\/7b7\/7b7f9dbfea05c83784f8b85149852f08.svg\" width=\"12\" height=\"16\" data-width=\"1.448\" data-height=\"2.262\" data-vertical-align=\"-0.566\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/7\/7b\/7b7\/7b7f9dbfea05c83784f8b85149852f08.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/7\/7b\/7b7\/7b7f9dbfea05c83784f8b85149852f08.svg 781w\" loading=\"lazy\" decode=\"async\"\/> \u0434\u0430\u0451\u0442 oversteering: \u043c\u043e\u0434\u0435\u043b\u044c \u0442\u0435\u0440\u044f\u0435\u0442 \u043a\u043e\u0433\u0435\u0440\u0435\u043d\u0442\u043d\u043e\u0441\u0442\u044c (\u0441\u0432\u043e\u044e \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u044c \u0432\u043e\u043e\u0431\u0449\u0435 \u043d\u043e\u0440\u043c \u043e\u0442\u0432\u0435\u0447\u0430\u0442\u044c) \u0438 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u0442\u044c\u0441\u044f \u0438\u043b\u0438 \u0432\u044b\u0434\u0430\u0432\u0430\u0442\u044c \u0431\u0435\u0441\u0441\u043c\u044b\u0441\u043b\u0438\u0446\u0443 \u2014 \u044d\u0442\u043e \u0441\u0438\u0433\u043d\u0430\u043b, \u0447\u0442\u043e \u0432\u044b \u0432\u044b\u0448\u043b\u0438 \u0437\u0430 \u043f\u0440\u0435\u0434\u0435\u043b\u044b \u0442\u0440\u0435\u043d\u0438\u0440\u043e\u0432\u043e\u0447\u043d\u043e\u0433\u043e \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0430\u043a\u0442\u0438\u0432\u0430\u0446\u0438\u0439.<\/p>\n<figure class=\"full-width \"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/f58\/8c2\/902\/f588c29025fd4ce7ab74bdccf1ac1e2d.png\" width=\"1168\" height=\"454\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/f58\/8c2\/902\/f588c29025fd4ce7ab74bdccf1ac1e2d.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/f58\/8c2\/902\/f588c29025fd4ce7ab74bdccf1ac1e2d.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<p>\u041f\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u044f \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u043d\u044b, \u043c\u044b \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u0432\u0430\u0435\u043c, \u0447\u0442\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e <img decoding=\"async\" class=\"formula inline\" source=\"\\alpha = 16\" alt=\"\\alpha = 16\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/1\/14\/14a\/14a9f8fccfcac65f6ec7a34bc3494011.svg\" width=\"48\" height=\"16\" data-width=\"6.728\" data-height=\"2.262\" data-vertical-align=\"-0.566\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/1\/14\/14a\/14a9f8fccfcac65f6ec7a34bc3494011.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/1\/14\/14a\/14a9f8fccfcac65f6ec7a34bc3494011.svg 781w\" loading=\"lazy\" decode=\"async\"\/> (\u224820% \u043e\u0442 \u043d\u043e\u0440\u043c\u044b \u0430\u043a\u0442\u0438\u0432\u0430\u0446\u0438\u0439 \u043d\u0430 \u0441\u043b\u043e\u0435), \u0447\u0442\u043e\u0431\u044b \u043c\u043e\u0434\u0435\u043b\u044c \u0441\u043e\u0433\u043b\u0430\u0441\u0438\u043b\u0430\u0441\u044c \u0441 \u043d\u0430\u0448\u0438\u043c \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u0435\u043c. \u041d\u043e \u043e\u0446\u0435\u043d\u0438\u0432\u0430\u0442\u044c \u043f\u043e \u043e\u0434\u043d\u043e\u043c\u0443 \u043f\u0440\u0438\u043c\u0435\u0440\u0443 \u043d\u0435\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u2014 \u043e\u0434\u0438\u043d \u043f\u0440\u043e\u043c\u043f\u0442 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043d\u0435\u0442\u0438\u043f\u0438\u0447\u043d\u044b\u043c, \u0430 \u044d\u0444\u0444\u0435\u043a\u0442 \u0437\u0430\u0432\u0438\u0441\u0435\u0442\u044c \u043e\u0442 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0439 \u0444\u0440\u0430\u0437\u044b, \u0430 \u043d\u0435 \u043e\u0442 \u0432\u0435\u043a\u0442\u043e\u0440\u0430 \u0432 \u0446\u0435\u043b\u043e\u043c. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043a \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u043c\u0443 eval: \u043f\u0440\u043e\u0433\u043e\u043d\u0438\u043c steering \u043f\u043e \u043d\u0430\u0431\u043e\u0440\u0443 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u0438 \u0438\u0437\u043c\u0435\u0440\u0438\u043c, \u043a\u0430\u043a \u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u0434\u043e\u043b\u044f &#171;yes&#187;\/&#187;no&#187; \u043e\u0442\u0432\u0435\u0442\u043e\u0432 \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 <img decoding=\"async\" class=\"formula inline\" source=\"\\alpha\" alt=\"\\alpha\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/7\/7b\/7b7\/7b7f9dbfea05c83784f8b85149852f08.svg\" width=\"12\" height=\"16\" data-width=\"1.448\" data-height=\"2.262\" data-vertical-align=\"-0.566\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/7\/7b\/7b7\/7b7f9dbfea05c83784f8b85149852f08.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/7\/7b\/7b7\/7b7f9dbfea05c83784f8b85149852f08.svg 781w\" loading=\"lazy\" decode=\"async\"\/>. \u0411\u0435\u043d\u0447\u043c\u0430\u0440\u043a \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043d\u0430\u0439\u0442\u0438 \u0432 \u043d\u043e\u0443\u0442\u0431\u0443\u043a\u0435, \u044f \u043b\u0438\u0448\u044c \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u044e\u0441\u044c \u043d\u0430 \u043c\u043e\u0442\u0438\u0432\u0430\u0446\u0438\u0438 \u0438 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f\u0445 \u0432\u044b\u0431\u043e\u0440\u0430 \u0434\u0438\u0437\u0430\u0439\u043d\u0430.<\/p>\n<p><strong> \u041f\u043e\u0447\u0435\u043c\u0443 yes\/no?<\/strong><\/p>\n<p>\u042d\u0442\u043e \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0434\u0438\u0437\u0430\u0439\u043d: \u043c\u044b \u043f\u0440\u0438\u043d\u0443\u0436\u0434\u0430\u0435\u043c \u043c\u043e\u0434\u0435\u043b\u044c \u0432\u044b\u0434\u0430\u0442\u044c \u043e\u0434\u0438\u043d \u0438\u0437 \u0434\u0432\u0443\u0445 \u0441\u0438\u0433\u043d\u0430\u043b\u043e\u0432. \u042d\u0442\u043e \u0443\u0431\u0438\u0440\u0430\u0435\u0442 \u0432\u0430\u0440\u0438\u0430\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u044c \u044f\u0437\u044b\u043a\u0430 \u2014 \u043d\u0435 \u043d\u0430\u0434\u043e \u043f\u0430\u0440\u0441\u0438\u0442\u044c \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u0439 \u0442\u0435\u043a\u0441\u0442 \u0438 \u0433\u0430\u0434\u0430\u0442\u044c, \u00ab\u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0430\u043b\u0430\u00bb \u043b\u0438 \u043c\u043e\u0434\u0435\u043b\u044c \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u0435.<\/p>\n<p>\u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u0435\u0441\u0442\u044c:<\/p>\n<ul>\n<li>\n<p>GPT-2 \u043d\u0435 instruction-tuned, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u043d\u0430 \u0432\u043e\u043f\u0440\u043e\u0441\u044b \u043d\u0435\u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0443\u0435\u043c\u043e \u2014 \u0447\u0430\u0441\u0442\u044c \u043e\u0442\u0432\u0435\u0442\u043e\u0432 \u043d\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043d\u0438 <code>yes<\/code>, \u043d\u0438 <code>no<\/code><\/p>\n<\/li>\n<li>\n<p>\u0432\u043e\u043f\u0440\u043e\u0441-\u0444\u043e\u0440\u043c\u0430 \u043c\u0435\u043d\u044f\u0435\u0442 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0442\u043e\u043a\u0435\u043d\u043e\u0432 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e train distribution \u043c\u043e\u0434\u0435\u043b\u0438<\/p>\n<\/li>\n<\/ul>\n<p>\u0414\u043b\u044f \u0441\u0435\u0440\u044c\u0451\u0437\u043d\u043e\u0433\u043e eval \u043d\u0443\u0436\u0435\u043d <strong>toxicity classifier<\/strong> (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 <code>unitary\/toxic-bert<\/code>) \u0438\u043b\u0438 <strong>LLM-as-judge<\/strong> \u2014 \u043e\u043d\u0438 \u0434\u0430\u044e\u0442 \u0431\u043e\u043b\u0435\u0435 \u043d\u0430\u0434\u0451\u0436\u043d\u0443\u044e \u043e\u0446\u0435\u043d\u043a\u0443 \u0431\u0435\u0437 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 yes\/no \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0438. \u041d\u043e \u043c\u044b \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u043b\u0438\u0441\u044c keyword baseline.<\/p>\n<figure class=\"full-width \"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/c31\/f52\/b7e\/c31f52b7e9d76debbe268e2e556eeba3.png\" alt=\"\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0430\" title=\"\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0430\" width=\"1170\" height=\"356\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/c31\/f52\/b7e\/c31f52b7e9d76debbe268e2e556eeba3.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/c31\/f52\/b7e\/c31f52b7e9d76debbe268e2e556eeba3.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<div><figcaption>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0430<\/figcaption><\/div>\n<\/figure>\n<p>\u041e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 <img decoding=\"async\" class=\"formula inline\" source=\"\\alpha\" alt=\"\\alpha\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/7\/7b\/7b7\/7b7f9dbfea05c83784f8b85149852f08.svg\" width=\"12\" height=\"16\" data-width=\"1.448\" data-height=\"2.262\" data-vertical-align=\"-0.566\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/7\/7b\/7b7\/7b7f9dbfea05c83784f8b85149852f08.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/7\/7b\/7b7\/7b7f9dbfea05c83784f8b85149852f08.svg 781w\" loading=\"lazy\" decode=\"async\"\/> \u043d\u0430 \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u043e\u0435 \u2014 20. \u041f\u0440\u0438 \u043d\u0435\u043c \u043c\u043e\u0434\u0435\u043b\u044c \u0441\u043e\u0433\u043b\u0430\u0441\u043d\u0430 \u043d\u0430 42% hate \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u044f\u0445 (\u043f\u0440\u043e\u0442\u0438\u0432 22% \u043f\u0440\u0438 baseline), \u0438 \u043e\u0442\u0440\u0438\u0446\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e 27% (\u043f\u0440\u043e\u0442\u0438\u0432 73% \u043d\u0430 baseline) \u0438 \u0440\u0435\u0436\u0435 \u0441\u043e\u0433\u043b\u0430\u0448\u0430\u0435\u0442\u0441\u044f \u0441 \u043f\u043e\u0437\u0438\u0442\u0438\u0432\u043d\u044b\u043c\u0438 \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u044f\u043c\u0438 (32% \u043f\u0440\u0438 baseline \u043f\u0440\u043e\u0442\u0438\u0432 9% \u0441\u043e \u0441\u0442\u0438\u0440\u0438\u043d\u0433\u043e\u043c). <\/p>\n<h2>\u0427\u0430\u0441\u0442\u044c 2. \u0415\u0441\u043b\u0438 \u0432\u044b \u0437\u0434\u0435\u0441\u044c \u2014 \u0432\u044b \u043c\u043e\u043b\u043e\u0434\u0435\u0446!<\/h2>\n<p>\u041a \u044d\u0442\u043e\u043c\u0443 \u043c\u043e\u043c\u0435\u043d\u0442\u0443 \u043c\u044b \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u043b\u0438 steering \u0447\u0435\u0440\u0435\u0437 \u0441\u044b\u0440\u044b\u0435 PyTorch hooks \u2014 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439, \u043d\u043e \u0443\u0436\u0435 \u0441\u0438\u043b\u044c\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434. Steering \u0432\u043a\u0443\u0441\u043d\u044b\u0439, steering \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0439 \u2014 \u0438 \u0432\u043e\u043a\u0440\u0443\u0433 \u043d\u0435\u0433\u043e \u0435\u0441\u0442\u044c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432 \u0447\u0430\u0441\u0442\u0438 B (\u0441\u0435\u0439\u0447\u0430\u0441) \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0434\u0432\u0435 \u0438\u0437 \u043d\u0438\u0445: \u00a0nnsight \u0438 pyvene \u2014 \u043e\u043d\u0438 \u0434\u0435\u043b\u0430\u044e\u0442 \u0442\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435 \u0447\u0438\u0449\u0435. \u0417\u0430\u043e\u0434\u043d\u043e \u0443\u0431\u0435\u0434\u0438\u043c\u0441\u044f, \u0447\u0442\u043e \u0432\u0441\u0435 \u0442\u0440\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u0430\u044e\u0442 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442.<\/p>\n<h2>NNsight<\/h2>\n<p><code>nnsight<\/code> \u2014 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0434\u043b\u044f \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0446\u0438\u0438 \u0438 \u0438\u043d\u0442\u0435\u0440\u0432\u0435\u043d\u0446\u0438\u0439 \u0432\u043e \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u043e\u0441\u0442\u0438 deep learning \u043c\u043e\u0434\u0435\u043b\u0435\u0439. \u041e\u043d\u0430 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0447\u0438\u0442\u0430\u0442\u044c \u0438 \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c \u0430\u043a\u0442\u0438\u0432\u0430\u0446\u0438\u0438 \u0447\u0435\u0440\u0435\u0437 <strong>tracing context<\/strong>.<\/p>\n<p><strong>Deferred execution \u2014 \u043a\u043b\u044e\u0447\u0435\u0432\u0430\u044f \u0438\u0434\u0435\u044f<\/strong><\/p>\n<p>\u0413\u043b\u0430\u0432\u043d\u043e\u0435 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 \u0440\u0443\u0447\u043d\u044b\u0445 hooks \u2014 <strong>\u043e\u0442\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435<\/strong>. \u0421\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441:<\/p>\n<pre><code class=\"python\">with nn_model.trace(prompt):    acts = nn_model.transformer.h[layer].output[:, -1, :].save()<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u0412 \u0442\u0430\u043a\u043e\u043c \u0441\u0442\u0438\u043b\u0435 \u0432\u044b \u043d\u0435 \u0447\u0438\u0442\u0430\u0435\u0442\u0435 \u0430\u043a\u0442\u0438\u0432\u0430\u0446\u0438\u044e \u043d\u0435\u043c\u0435\u0434\u043b\u0435\u043d\u043d\u043e. \u0412\u044b \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0435 <strong>\u043f\u043b\u0430\u043d<\/strong>: \u00ab\u043f\u0440\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c forward pass \u2014 \u0441\u043e\u0445\u0440\u0430\u043d\u0438 \u044d\u0442\u043e\u00bb. <code>nnsight<\/code> \u0441\u0442\u0440\u043e\u0438\u0442 \u0433\u0440\u0430\u0444 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439, \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 forward pass, \u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0442\u043e\u043c <code>.save()<\/code> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0439 \u0442\u0435\u043d\u0437\u043e\u0440.<\/p>\n<p>\u041f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u043e \u044d\u0442\u043e\u0433\u043e: \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438 \u0441\u043d\u0438\u043c\u0430\u0442\u044c hooks \u0432\u0440\u0443\u0447\u043d\u0443\u044e \u2014 \u043d\u0435\u0442 \u0440\u0438\u0441\u043a\u0430 \u00ab\u0437\u0430\u0431\u044b\u0442\u044c \u0441\u043d\u044f\u0442\u044c hook\u00bb \u0438 \u0441\u043b\u043e\u043c\u0430\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u044c \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0432\u044b\u0437\u043e\u0432\u043e\u0432. \u041a\u043e\u0434 \u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f \u0434\u0435\u043a\u043b\u0430\u0440\u0430\u0442\u0438\u0432\u043d\u043e: \u00ab\u044f \u0445\u043e\u0447\u0443 \u0432\u0438\u0434\u0435\u0442\u044c x\u00bb \u0432\u043c\u0435\u0441\u0442\u043e \u00ab\u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u0438 \u0441\u043b\u043e\u0439, \u043f\u043e\u043b\u043e\u0436\u0438 \u0432 \u043a\u044d\u0448, \u0441\u043d\u0438\u043c\u0438\u00bb.<\/p>\n<p>\u0422\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435 \u0434\u043b\u044f \u0438\u043d\u0442\u0435\u0440\u0432\u0435\u043d\u0446\u0438\u0439:<\/p>\n<pre><code class=\"python\">with nn_model.trace(prompt):    hidden = nn_model.transformer.h[layer].output    nn_model.transformer.h[layer].output[:] = hidden + alpha * vector<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p><code>nnsight<\/code> \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442 \u044d\u0442\u043e \u0432\u043c\u0435\u0448\u0430\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u043e \u0432 \u043d\u0443\u0436\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 forward pass.<\/p>\n<blockquote>\n<p>API <code>nnsight<\/code>  \u0440\u0430\u0437\u0432\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043c\u0435\u0436\u0434\u0443 \u0432\u0435\u0440\u0441\u0438\u044f\u043c\u0438. \u042d\u0442\u043e\u0442 \u0440\u0430\u0437\u0434\u0435\u043b \u043d\u0430\u043f\u0438\u0441\u0430\u043d \u0434\u043b\u044f <code>nnsight &gt;= 0.6<\/code>; \u0435\u0441\u043b\u0438 \u0447\u0442\u043e-\u0442\u043e \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u2014 \u043f\u0440\u043e\u0432\u0435\u0440\u044c\u0442\u0435 <code>nnsight.__version__<\/code> \u0438 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e. <\/p>\n<\/blockquote>\n<p>\u0412\u0441\u0435 \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c, \u0432 \u0442\u0435\u043b\u0435 \u0441\u0442\u0430\u0442\u044c\u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043b\u0438\u0448\u044c \u043d\u0430 \u0433\u043b\u0430\u0432\u043d\u044b\u0439 \u0431\u043b\u043e\u043a. Steering \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a \u2014 \u0432 tracing context \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \/ \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0430\u043a\u0442\u0438\u0432\u0430\u0446\u0438\u044e \u043c\u043e\u0434\u0443\u043b\u044f.<\/p>\n<pre><code class=\"python\">with nn_model.generate(prompt, max_new_tokens=...):    hidden = nn_model.transformer.h[layer].output[0]    hidden[:, :, :] = hidden + alpha * vector    output = nn_model.generator.output.save()<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u0412 \u0440\u0430\u0437\u043d\u044b\u0445 \u0432\u0435\u0440\u0441\u0438\u044f\u0445 <code>nnsight<\/code> \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 output \u043c\u043e\u0433\u0443\u0442 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043e\u0442\u043b\u0438\u0447\u0430\u0442\u044c\u0441\u044f. \u041f\u0440\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0435 \u043e\u0442\u0432\u0435\u0442\u044b \u0431\u0443\u0434\u0443\u0442 \u0442\u0435 \u0436\u0435, \u0441 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c\u044e \u0434\u043e \u0442\u043e\u043a\u0435\u043d\u0430. \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u0434\u043b\u044f \u0432\u0435\u043a\u0442\u043e\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 \u0447\u0435\u0440\u0435\u0437 NNsight, \u0443 \u0432\u0430\u0441 \u0431\u0443\u0434\u0435\u0442 \u0442\u0430\u043a\u043e\u0439 \u0432\u044b\u0432\u043e\u0434:<\/p>\n<pre><code class=\"python\">nn_vector shape: torch.Size([768]),  norm: 1.0000Cosine similarity (nnsight vs HF hooks): 1.0000(Close to 1.0 = identical vectors; different APIs produce the same result)<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<div class=\"persona\"><img decoding=\"async\" class=\"image persona__image\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/e0a\/98e\/e90\/e0a98ee90cd6f1814f1f2a58c45426ac.jpg\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/e0a\/98e\/e90\/e0a98ee90cd6f1814f1f2a58c45426ac.jpg 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/e0a\/98e\/e90\/e0a98ee90cd6f1814f1f2a58c45426ac.jpg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<h5 class=\"persona__heading\">\u0410 \u0437\u043d\u0430\u0447\u0438\u0442, \u044d\u0442\u043e\u043c\u0443 \u043c\u0438\u0440\u0443 \u043a\u0440\u043e\u0432\u0430\u0432\u043e\u0433\u043e open-source \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0432\u0435\u0440\u044f\u0442\u044c!<\/h5>\n<\/div>\n<h2>Pyvene<\/h2>\n<p><code>pyvene<\/code> (Stanford NLP) \u0437\u0430\u043c\u0435\u043d\u044f\u0435\u0442 \u0440\u0443\u0447\u043d\u044b\u0435 hooks <strong>\u0434\u0435\u043a\u043b\u0430\u0440\u0430\u0442\u0438\u0432\u043d\u044b\u043c \u043a\u043e\u043d\u0444\u0438\u0433\u043e\u043c<\/strong>: \u0432\u044b \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0435 <em>\u0447\u0442\u043e<\/em> \u043c\u0435\u043d\u044f\u0442\u044c, \u0430 \u043d\u0435 <em>\u043a\u0430\u043a<\/em>.<\/p>\n<p><strong>\u0418\u0434\u0435\u044f: intervention \u043a\u0430\u043a \u043e\u0431\u044a\u0435\u043a\u0442<\/strong><\/p>\n<p>\u0412 \u0440\u0443\u0447\u043d\u043e\u043c \u043f\u043e\u0434\u0445\u043e\u0434\u0435 \u0438\u043d\u0442\u0435\u0440\u0432\u0435\u043d\u0446\u0438\u044f \u2014 \u044d\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f-hook. \u0412 <code>pyvene<\/code> \u2014 \u044d\u0442\u043e \u043e\u0431\u044a\u0435\u043a\u0442 \u0441 \u0442\u0438\u043f\u043e\u043c \u0438 \u043a\u043e\u043d\u0444\u0438\u0433\u043e\u043c:<\/p>\n<pre><code class=\"python\">config = IntervenableConfig([{  \"layer\": L,  \"component\": \"block_output\",          # \u0433\u0434\u0435 \u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u0442\u044c  \"intervention_type\": AdditionIntervention,  # \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c   }])pv_model = IntervenableModel(config, model)<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p><code>IntervenableModel<\/code> \u043e\u0431\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u0442 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c \u0438 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 hooks \u2014 \u0432\u0430\u043c \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438 \u0441\u043d\u0438\u043c\u0430\u0442\u044c \u0438\u0445 \u0432\u0440\u0443\u0447\u043d\u0443\u044e.<\/p>\n<p><strong>AdditionIntervention \u2014 \u0447\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432\u043d\u0443\u0442\u0440\u0438<\/strong><\/p>\n<p>\u041f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 <code>pv_model(inputs, unit_locations=..., source_representations=...)<\/code> \u0432 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0445 \u043f\u043e\u0437\u0438\u0446\u0438\u044f\u0445 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f:<br \/><img decoding=\"async\" class=\"formula inline\" source=\"\\mathbf{h} \\;\\leftarrow\\; \\mathbf{h} + \\mathbf{s}\" alt=\"\\mathbf{h} \\;\\leftarrow\\; \\mathbf{h} + \\mathbf{s}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/6\/6c\/6cc\/6ccb2eb4b904928b614bc449a94e2a7b.svg\" width=\"88\" height=\"16\" data-width=\"11.462\" data-height=\"2.262\" data-vertical-align=\"-0.566\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/6\/6c\/6cc\/6ccb2eb4b904928b614bc449a94e2a7b.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/6\/6c\/6cc\/6ccb2eb4b904928b614bc449a94e2a7b.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<p>\u0433\u0434\u0435 <img decoding=\"async\" class=\"formula inline\" source=\"\\mathbf{s}\" alt=\"\\mathbf{s}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/4\/4e\/4ec\/4eca1f27137609136f5ea96540020356.svg\" width=\"12\" height=\"16\" data-width=\"1.027\" data-height=\"2.262\" data-vertical-align=\"-0.566\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/4\/4e\/4ec\/4eca1f27137609136f5ea96540020356.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/4\/4e\/4ec\/4eca1f27137609136f5ea96540020356.svg 781w\" loading=\"lazy\" decode=\"async\"\/> \u2014 <code>source_representation<\/code> (\u043d\u0430\u0448 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u0447\u0435\u0441\u0442\u043d\u043e\u0439 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0435\u0439 <img decoding=\"async\" class=\"formula inline\" source=\"\\alpha \\cdot \\hat{\\mathbf{v}}\" alt=\"\\alpha \\cdot \\hat{\\mathbf{v}}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/2\/29\/298\/2988aa403abce73e0c9bf304f363a007.svg\" width=\"32\" height=\"16\" data-width=\"4.456\" data-height=\"2.403\" data-vertical-align=\"-0.636\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/2\/29\/298\/2988aa403abce73e0c9bf304f363a007.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/2\/29\/298\/2988aa403abce73e0c9bf304f363a007.svg 781w\" loading=\"lazy\" decode=\"async\"\/>). \u041e\u0434\u0438\u043d-\u0432-\u043e\u0434\u0438\u043d \u0442\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435, \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442 \u043d\u0430\u0448 \u0440\u0443\u0447\u043d\u043e\u0439 hook \u2014 \u043d\u043e \u0447\u0435\u0440\u0435\u0437 \u0434\u0435\u043a\u043b\u0430\u0440\u0430\u0442\u0438\u0432\u043d\u044b\u0439 API.<\/p>\n<p><strong>\u0421\u0442\u043e\u043f. \u0417\u0430\u0447\u0435\u043c \u0442\u043e\u0433\u0434\u0430 \u043d\u0430\u043c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u2014 \u043c\u044b \u0432\u0441\u0435 \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u043b\u0438. <\/strong><\/p>\n<p>\u0426\u0435\u043d\u043d\u043e\u0441\u0442\u044c <code>pyvene<\/code> \u043f\u0440\u043e\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432 \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0430\u0445:<\/p>\n<ul>\n<li>\n<p><strong>Multi-location interventions<\/strong>: \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u043f\u0430\u0442\u0447\u0438\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u043b\u043e\u0451\u0432 \/ \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432<\/p>\n<\/li>\n<li>\n<p><strong>Causal tracing<\/strong>: \u0437\u0430\u043d\u0443\u043b\u044f\u0435\u043c \u043e\u0434\u0438\u043d \u043f\u0443\u0442\u044c \u0438 \u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u044d\u0442\u043e \u0432\u043b\u0438\u044f\u0435\u0442 \u043d\u0430 output \u2014 \u0442\u0430\u043a \u043d\u0430\u0445\u043e\u0434\u044f\u0442 \u00ab\u0432\u0430\u0436\u043d\u044b\u0435\u00bb \u0441\u043b\u043e\u0438<\/p>\n<\/li>\n<li>\n<p><strong>Trainable interventions<\/strong>: \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u0443\u0447\u0438\u0442\u044c $\\mathbf{s}$ \u043f\u043e\u0434 \u0437\u0430\u0434\u0430\u0447\u0443 (\u044d\u0442\u043e \u0442\u043e, \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442 <code>pyreft<\/code> , \u043d\u043e \u043e \u043d\u0435\u043c \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0441\u0435\u0440\u0438\u044f\u0445)<\/p>\n<\/li>\n<\/ul>\n<h2>\u0418\u0442\u043e\u0433\u043e \u043f\u043e \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u043c \u0441\u0434\u0435\u043b\u0430\u0442\u044c steering<\/h2>\n<p>\u0412\u0441\u0435 \u0442\u0440\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u2014 PyTorch hooks, nnsight, pyvene \u2014 \u0434\u0435\u043b\u0430\u044e\u0442 \u043e\u0434\u043d\u043e \u0438 \u0442\u043e \u0436\u0435: \u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u044e\u0442 \u0432\u044b\u0445\u043e\u0434 \u0441\u043b\u043e\u044f \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044e\u0442 <img decoding=\"async\" class=\"formula inline\" source=\"\\alpha \\cdot \\hat{\\mathbf{v}}\" alt=\"\\alpha \\cdot \\hat{\\mathbf{v}}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/2\/29\/298\/2988aa403abce73e0c9bf304f363a007.svg\" width=\"32\" height=\"16\" data-width=\"4.456\" data-height=\"2.403\" data-vertical-align=\"-0.636\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/2\/29\/298\/2988aa403abce73e0c9bf304f363a007.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/2\/29\/298\/2988aa403abce73e0c9bf304f363a007.svg 781w\" loading=\"lazy\" decode=\"async\"\/>. <\/p>\n<p>Cosine similarity \u043c\u0435\u0436\u0434\u0443 \u0432\u0435\u043a\u0442\u043e\u0440\u0430\u043c\u0438, \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u043c\u0438 \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u043c\u0438, \u0431\u043b\u0438\u0437\u043a\u0430 \u043a 1 \u2014 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u043e\u0441\u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u043c (\u0430 \u0434\u043b\u044f hooks \u0438 pyvene \u043d\u0430\u0448 \u0432\u0435\u043a\u0442\u043e\u0440 \u0431\u044b\u043b \u043e\u0434\u0438\u043d). <\/p>\n<p>\u0420\u0430\u0437\u043d\u0438\u0446\u0430 \u043c\u0435\u0436\u0434\u0443 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430\u043c\u0438 \u0432 \u0443\u0440\u043e\u0432\u043d\u0435 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u0438 \u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0443 \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043e\u0447\u043d\u044b\u0445 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 \u0434\u043b\u044f \u0445\u043e\u0440\u043e\u0448\u0435\u0439 \u0438\u043d\u0442\u0435\u0440\u0432\u0435\u043d\u0446\u0438\u0438:<\/p>\n<ul>\n<li>\n<p>Hooks \u0434\u0430\u044e\u0442 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044c \u0438 \u0442\u0440\u0435\u0431\u0443\u044e\u0442 \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u0435: \u0432\u044b \u0441\u0430\u043c\u0438 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442\u0435, \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u0443\u0435\u0442\u0435 \u0438 \u0441\u043d\u0438\u043c\u0430\u0435\u0442\u0435 \u0445\u0443\u043a. \u041d\u043e \u043b\u0435\u0433\u043a\u043e \u0437\u0430\u0431\u044b\u0442\u044c handle.remove() \u2014 \u0438 \u0445\u0443\u043a \u0432\u0438\u0441\u0438\u0442 \u043d\u0430 \u043c\u043e\u0434\u0435\u043b\u0438 \u043d\u0430\u0432\u0441\u0435\u0433\u0434\u0430; \u043b\u0435\u0433\u043a\u043e \u043f\u0435\u0440\u0435\u043f\u0443\u0442\u0430\u0442\u044c dtype \u0438\u043b\u0438 \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u043d\u0435 \u0442\u043e\u0442 tuple. \u0425\u043e\u0440\u043e\u0448\u0438 \u0434\u043b\u044f \u043e\u0434\u043d\u043e\u0440\u0430\u0437\u043e\u0432\u044b\u0445 \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u043e\u0432 \u0438 \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u043c\u0435\u0445\u0430\u043d\u0438\u043a\u0438.<\/p>\n<\/li>\n<li>\n<p>nnsight \u0443\u0431\u0438\u0440\u0430\u0435\u0442 boilerplate (\u044d\u0442\u043e \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u044b\u0439-\u043c\u0435\u0445\u0430\u043d\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043a\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0443\u0436\u043d\u043e \u043f\u0438\u0441\u0430\u0442\u044c \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437, \u043d\u043e \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0435 \u043d\u0435\u0441\u0451\u0442 \u0441\u043c\u044b\u0441\u043b\u043e\u0432\u043e\u0439 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0438). \u0421 \u044d\u0442\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u043e\u0439 \u0445\u0443\u043a \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0438 \u0441\u043d\u0438\u043c\u0430\u0435\u0442\u0441\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438, \u043a\u043e\u0434 \u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f \u0434\u0435\u043a\u043b\u0430\u0440\u0430\u0442\u0438\u0432\u043d\u043e \u2014 &#171;\u0441\u043e\u0445\u0440\u0430\u043d\u0438 \u0430\u043a\u0442\u0438\u0432\u0430\u0446\u0438\u044e \u0437\u0434\u0435\u0441\u044c&#187;, &#171;\u0437\u0430\u043c\u0435\u043d\u0438 \u0435\u0451 \u043d\u0430 \u044d\u0442\u043e&#187;. \u041c\u0438\u043d\u0443\u0441 \u2014 \u0438\u043d\u043e\u0433\u0434\u0430 \u0441\u043b\u043e\u0436\u043d\u043e \u043e\u0442\u043b\u0430\u0434\u0438\u0442\u044c: \u043e\u0448\u0438\u0431\u043a\u0430 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u043d\u0435 \u0442\u0430\u043c, \u0433\u0434\u0435 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0430 (\u044f \u043f\u043e \u0442\u0443\u0442\u043e\u0440\u0438\u0430\u043b\u0443 \u0441\u043e\u0431\u0440\u0430\u043b\u0430 \u0432\u0441\u0451).<\/p>\n<\/li>\n<li>\n<p>pyvene \u0431\u043e\u043b\u0435\u0435 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u0435\u043d: \u0438\u043d\u0442\u0435\u0440\u0432\u0435\u043d\u0446\u0438\u044f \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u043a\u043e\u043d\u0444\u0438\u0433-\u043e\u0431\u044a\u0435\u043a\u0442, \u0430 \u043d\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u044f. \u042d\u0442\u043e \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u0442 \u043f\u0443\u0442\u044c \u043a \u043e\u0431\u0443\u0447\u0430\u0435\u043c\u044b\u043c \u0438\u043d\u0442\u0435\u0440\u0432\u0435\u043d\u0446\u0438\u044f\u043c \u2014 \u043c\u043e\u0436\u043d\u043e \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c $\\mathbf{v}$ \u043f\u043e\u0434 \u0437\u0430\u0434\u0430\u0447\u0443 \u0432\u043c\u0435\u0441\u0442\u043e \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0441\u0447\u0438\u0442\u0430\u0442\u044c \u0440\u0430\u0437\u043d\u043e\u0441\u0442\u044c \u0441\u0440\u0435\u0434\u043d\u0438\u0445. \u041d\u0430 \u044d\u0442\u043e\u043c \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u044b \u0434\u0440\u0443\u0433\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u044b. <\/p>\n<\/li>\n<\/ul>\n<p>\u0414\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e steering \u0440\u0430\u0437\u043d\u0438\u0446\u044b \u043d\u0435\u0442 \u2014 \u0432\u044b\u0431\u0438\u0440\u0430\u0439\u0442\u0435 \u0442\u043e, \u0447\u0442\u043e \u0443\u0434\u043e\u0431\u043d\u0435\u0435.<\/p>\n<h2>\u041d\u0430 \u0447\u0442\u043e \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435? \u0418 \u043a\u0440\u0430\u0441\u0438\u0432\u0430\u044f \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0430 \u0432 \u0444\u0438\u043d\u0430\u043b\u0435<\/h2>\n<p>\u0412 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0440\u0430\u0431\u043e\u0442\u044b \u043c\u044b \u0441\u0442\u043e\u043b\u043a\u043d\u0443\u043b\u0438\u0441\u044c \u0441 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u0438\u0437 \u0442\u0438\u043f\u0438\u0447\u043d\u044b\u0445 failure mode activation steering. \u042d\u0442\u043e \u0445\u043e\u0440\u043e\u0448\u0438\u0439 \u043c\u043e\u043c\u0435\u043d\u0442, \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u0445 \u044f\u0432\u043d\u043e.<\/p>\n<p><strong>Prompt leakage<\/strong> \u2014 \u0432\u0435\u043a\u0442\u043e\u0440 \u0437\u0430\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043b \u043d\u0435 \u043a\u043e\u043d\u0446\u0435\u043f\u0442, \u0430 \u043f\u043e\u0432\u0435\u0440\u0445\u043d\u043e\u0441\u0442\u043d\u044b\u0435 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0442\u0435\u043a\u0441\u0442\u0430. Tolerant-\u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0432 \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u0435 \u043b\u0435\u043a\u0441\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u043e\u0445\u043e\u0436\u0438 \u043d\u0430 hate: \u0442\u0435 \u0436\u0435 \u0441\u0443\u0431\u044a\u0435\u043a\u0442\u044b, \u0442\u0435 \u0436\u0435 \u0442\u0435\u043c\u044b, \u043f\u0440\u043e\u0441\u0442\u043e \u0441 \u043e\u0442\u0440\u0438\u0446\u0430\u043d\u0438\u0435\u043c. \u041c\u043e\u0434\u0435\u043b\u044c \u0430\u043a\u0442\u0438\u0432\u0438\u0440\u043e\u0432\u0430\u043b\u0430 hate-\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043d\u0430 \u043e\u0431\u043e\u0438\u0445 \u043a\u043b\u0430\u0441\u0441\u0430\u0445, \u0438 \u0440\u0430\u0437\u043d\u043e\u0441\u0442\u044c \u0441\u0440\u0435\u0434\u043d\u0438\u0445 \u0443\u043a\u0430\u0437\u0430\u043b\u0430 \u043d\u0435 \u0442\u0443\u0434\u0430. Logit lens \u044d\u0442\u043e\u0433\u043e \u043d\u0435 \u043f\u043e\u0439\u043c\u0430\u043b \u2014 \u043e\u043d \u043f\u043e\u043a\u0430\u0437\u0430\u043b hate-\u0442\u043e\u043a\u0435\u043d\u044b \u043d\u0430 \u043c\u0438\u043d\u0443\u0441-\u0441\u0442\u043e\u0440\u043e\u043d\u0435 \u0438 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u043b \u00ab\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u00bb. \u0417\u043d\u0430\u043a \u0432\u0435\u043a\u0442\u043e\u0440\u0430 \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u044d\u043c\u043f\u0438\u0440\u0438\u0447\u0435\u0441\u043a\u0438.<\/p>\n<p><strong>Oversteering <\/strong>\u2014 \u043f\u0440\u0438 <img decoding=\"async\" class=\"formula inline\" source=\"\\alpha\" alt=\"\\alpha\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/7\/7b\/7b7\/7b7f9dbfea05c83784f8b85149852f08.svg\" width=\"12\" height=\"16\" data-width=\"1.448\" data-height=\"2.262\" data-vertical-align=\"-0.566\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/7\/7b\/7b7\/7b7f9dbfea05c83784f8b85149852f08.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/7\/7b\/7b7\/7b7f9dbfea05c83784f8b85149852f08.svg 781w\" loading=\"lazy\" decode=\"async\"\/> \u0432\u044b\u0448\u0435 ~30 \u043c\u043e\u0434\u0435\u043b\u044c \u0442\u0435\u0440\u044f\u0435\u0442 \u0441\u0432\u044f\u0437\u043d\u043e\u0441\u0442\u044c: \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u0442\u044c\u0441\u044f \u0438\u043b\u0438 \u0432\u044b\u0434\u0430\u0432\u0430\u0442\u044c \u043c\u0443\u0441\u043e\u0440. \u042d\u0442\u043e \u0441\u0438\u0433\u043d\u0430\u043b, \u0447\u0442\u043e \u0430\u043a\u0442\u0438\u0432\u0430\u0446\u0438\u0438 \u0432\u044b\u0448\u043b\u0438 \u0437\u0430 \u043f\u0440\u0435\u0434\u0435\u043b\u044b \u0442\u0440\u0435\u043d\u0438\u0440\u043e\u0432\u043e\u0447\u043d\u043e\u0433\u043e \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f. \u0420\u0430\u0431\u043e\u0447\u0430\u044f \u0437\u043e\u043d\u0430 \u2014 \u043e\u043a\u043e\u043b\u043e 20% \u043e\u0442 \u043d\u043e\u0440\u043c\u044b \u0430\u043a\u0442\u0438\u0432\u0430\u0446\u0438\u0439 \u043d\u0430 \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u043e\u0435.<\/p>\n<p><strong>Layer mismatch <\/strong>\u2014 \u043e\u0434\u0438\u043d \u0438 \u0442\u043e\u0442 \u0436\u0435 \u0432\u0435\u043a\u0442\u043e\u0440, \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0439 \u043d\u0430 \u0441\u043b\u043e\u0435 6 \u0438 \u0441\u043b\u043e\u0435 9, \u0434\u0430\u0451\u0442 \u0440\u0430\u0437\u043d\u044b\u0439 \u044d\u0444\u0444\u0435\u043a\u0442. \u041d\u0430 \u043a\u0430\u043a\u043e\u043c \u0441\u043b\u043e\u0435 \u043a\u043e\u043d\u0446\u0435\u043f\u0442 \u043b\u0443\u0447\u0448\u0435 \u0440\u0430\u0437\u0434\u0435\u043b\u0451\u043d \u2014 \u0432\u043e\u043f\u0440\u043e\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0440\u0435\u0448\u0430\u0435\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 PCA (\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0431\u043b\u043e\u043a) \u0438\u043b\u0438 \u043f\u0435\u0440\u0435\u0431\u043e\u0440\u043e\u043c.<\/p>\n<p><strong>Concept entanglement<\/strong> \u2014 \u043d\u0430\u0448 \u0432\u0435\u043a\u0442\u043e\u0440 \u043a\u043e\u0434\u0438\u0440\u0443\u0435\u0442 \u043e\u0441\u044c \u00ab\u0430\u0433\u0440\u0435\u0441\u0441\u0438\u0432\u043d\u0430\u044f \u043b\u0435\u043a\u0441\u0438\u043a\u0430 \u2194 \u0444\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u00bb, \u0430 \u043d\u0435 \u0441\u0442\u0440\u043e\u0433\u043e \u00abhate \u2194 tolerant\u00bb. \u042d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e \u0432\u043c\u0435\u0441\u0442\u0435 \u0441\u043e \u0441\u0434\u0432\u0438\u0433\u043e\u043c \u0432 \u0441\u0442\u043e\u0440\u043e\u043d\u0443 hate \u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u0438 \u0441\u0442\u0438\u043b\u044c \u2014 \u043c\u043e\u0434\u0435\u043b\u044c \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0433\u0440\u0443\u0431\u0435\u0435 \u0432 \u0446\u0435\u043b\u043e\u043c, \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438.<\/p>\n<p><strong>Autoregressive fading \u0438 distribution shift <\/strong>\u043c\u044b \u043d\u0435 \u0438\u0437\u043c\u0435\u0440\u044f\u043b\u0438 \u044f\u0432\u043d\u043e, \u043d\u043e \u043e\u043d\u0438 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u044e\u0442: \u044d\u0444\u0444\u0435\u043a\u0442 \u043d\u0430 \u043f\u0435\u0440\u0432\u044b\u0445 \u0442\u043e\u043a\u0435\u043d\u0430\u0445 \u0441\u0438\u043b\u044c\u043d\u0435\u0435, \u0447\u0435\u043c \u0432 \u043a\u043e\u043d\u0446\u0435 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438, \u0438 \u0432\u0435\u043a\u0442\u043e\u0440, \u0445\u043e\u0440\u043e\u0448\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0438\u0439 \u043d\u0430 eval_prompt, \u043c\u043e\u0436\u0435\u0442 \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043d\u0430 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u0445 (\u0434\u043b\u044f \u0443\u0432\u0438\u0434\u0435\u043d\u0438\u044f \u0441\u0435\u0433\u043e \u044d\u0444\u0444\u0435\u043a\u0442\u0430 \u2014\u00a0\u043f\u0440\u043e\u0441\u0442\u043e \u0443\u0432\u0435\u043b\u0438\u0447\u044c\u0442\u0435 \u0447\u0438\u0441\u043b\u043e \u0442\u043e\u043a\u0435\u043d\u043e\u0432 \u0432 output).<\/p>\n<p>\u0427\u0430\u0441\u0442\u044c \u0438\u0437 \u044d\u0442\u0438\u0445 \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u043c\u043e\u0436\u043d\u043e \u0434\u0438\u0430\u0433\u043d\u043e\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0434\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430 steering \u2014 \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0432 \u043d\u0430 \u0433\u0435\u043e\u043c\u0435\u0442\u0440\u0438\u044e \u0430\u043a\u0442\u0438\u0432\u0430\u0446\u0438\u0439. \u0415\u0441\u043b\u0438 \u043a\u043b\u0430\u0441\u0441\u044b hate \u0438 tolerant \u043d\u0435 \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u044b \u0432 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0435 residual stream, \u0432\u0435\u043a\u0442\u043e\u0440 \u043c\u0435\u0436\u0434\u0443 \u0438\u0445 \u0446\u0435\u043d\u0442\u0440\u043e\u0438\u0434\u0430\u043c\u0438 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u043d\u0435\u0441\u0442\u0438 \u043a\u043e\u043d\u0446\u0435\u043f\u0442 \u2014 \u043e\u043d \u0431\u0443\u0434\u0435\u0442 \u0448\u0443\u043c\u043e\u043c. PCA \u0434\u0430\u0451\u0442 \u0431\u044b\u0441\u0442\u0440\u044b\u0439 \u0432\u0438\u0437\u0443\u0430\u043b\u044c\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442 \u043d\u0430 \u044d\u0442\u043e\u0442 \u0432\u043e\u043f\u0440\u043e\u0441: \u0445\u043e\u0440\u043e\u0448\u043e \u043b\u0438 \u043b\u0438\u043d\u0435\u0439\u043d\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u044b \u043a\u043b\u0430\u0441\u0441\u044b \u0438 \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0435\u0442 \u043b\u0438 \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 steering vector \u0441 \u043e\u0441\u044c\u044e \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u044f. \u041d\u0430\u0448\u0430 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0430 \u0442\u0430\u043a\u043e\u0432\u0430: <\/p>\n<div class=\"floating-image\">\n<figure class=\"float full-width \"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/4aa\/849\/16f\/4aa84916f5b26bdf0417061d251fe557.png\" alt=\"Explained variance: PC1=10.8%, PC2=8.5%\" title=\"Explained variance: PC1=10.8%, PC2=8.5%\" width=\"1230\" height=\"912\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/4aa\/849\/16f\/4aa84916f5b26bdf0417061d251fe557.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/4aa\/849\/16f\/4aa84916f5b26bdf0417061d251fe557.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<div><figcaption>Explained variance: PC1=10.8%, PC2=8.5%<\/figcaption><\/div>\n<\/figure>\n<p>PC1 \u0438 PC2 \u0432\u043c\u0435\u0441\u0442\u0435 \u043e\u0431\u044a\u044f\u0441\u043d\u044f\u044e\u0442 \u0442\u043e\u043b\u044c\u043a\u043e 19.3% \u0434\u0438\u0441\u043f\u0435\u0440\u0441\u0438\u0438 (10.8% + 8.5%). \u042d\u0442\u043e \u043e\u0447\u0435\u043d\u044c \u043c\u0430\u043b\u043e \u2014 \u0437\u043d\u0430\u0447\u0438\u0442 \u0430\u043a\u0442\u0438\u0432\u0430\u0446\u0438\u0438 768-\u043c\u0435\u0440\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0430 GPT-2 \u043d\u0435 \u0438\u043c\u0435\u044e\u0442 \u0434\u0432\u0443\u0445 \u0434\u043e\u043c\u0438\u043d\u0438\u0440\u0443\u044e\u0449\u0438\u0445 \u043e\u0441\u0435\u0439: \u0434\u0438\u0441\u043f\u0435\u0440\u0441\u0438\u044f \u0440\u0430\u0437\u043c\u0430\u0437\u0430\u043d\u0430 \u043f\u043e \u043c\u043d\u043e\u0433\u0438\u043c \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f\u043c, \u0438 \u043f\u0440\u043e\u0435\u043a\u0446\u0438\u044f \u043d\u0430 \u043f\u043b\u043e\u0441\u043a\u043e\u0441\u0442\u044c \u0442\u0435\u0440\u044f\u0435\u0442 \u0431\u043e\u043b\u044c\u0448\u0443\u044e \u0447\u0430\u0441\u0442\u044c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b. \u041a\u043b\u0430\u0441\u0441\u044b \u0441\u0438\u043b\u044c\u043d\u043e \u043f\u0435\u0440\u0435\u043a\u0440\u044b\u0432\u0430\u044e\u0442\u0441\u044f. \u0415\u0441\u0442\u044c \u0441\u043b\u0430\u0431\u0430\u044f \u0442\u0435\u043d\u0434\u0435\u043d\u0446\u0438\u044f: hate (\u00d7) \u0441\u043c\u0435\u0449\u0451\u043d \u043f\u0440\u0430\u0432\u0435\u0435 \u043f\u043e PC1, tolerant (\u25cf) \u2014 \u043b\u0435\u0432\u0435\u0435 \u0438 \u0432\u043d\u0438\u0437. \u041d\u043e \u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043d\u0435\u0442. Steering vector \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u043c\u0435\u0436\u0434\u0443 \u0446\u0435\u043d\u0442\u0440\u043e\u0438\u0434\u0430\u043c\u0438 \u043a\u043b\u0430\u0441\u0441\u043e\u0432, \u043d\u043e \u043d\u0435 \u0432\u0434\u043e\u043b\u044c \u0447\u0451\u0442\u043a\u043e\u0439 \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u044e\u0449\u0435\u0439 \u043e\u0441\u0438.<\/p>\n<p>PCA \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0430\u0435\u0442 \u0442\u043e, \u0447\u0442\u043e \u043c\u044b \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u043b\u0438 \u044d\u043c\u043f\u0438\u0440\u0438\u0447\u0435\u0441\u043a\u0438: \u043a\u043e\u043d\u0446\u0435\u043f\u0442 hate\/tolerant \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0434\u043e\u043c\u0438\u043d\u0438\u0440\u0443\u044e\u0449\u0438\u043c \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u0432 residual stream GPT-2 \u043d\u0430 \u0441\u043b\u043e\u0435 6. \u041c\u043e\u0434\u0435\u043b\u044c \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u0443\u0435\u0442 \u0441\u0432\u043e\u0451 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u0435 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u043e \u043f\u043e \u0434\u0440\u0443\u0433\u0438\u043c \u043e\u0441\u044f\u043c \u2014 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u043c, \u043f\u043e\u0437\u0438\u0446\u0438\u043e\u043d\u043d\u044b\u043c, \u0447\u0430\u0441\u0442\u043e\u0442\u043d\u044b\u043c \u2014 \u0430 hate vs tolerant \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442 \u043e\u0434\u043d\u043e \u0438\u0437 \u0432\u0442\u043e\u0440\u043e\u0441\u0442\u0435\u043f\u0435\u043d\u043d\u044b\u0445 \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0439. \u0421\u0442\u0438\u0440\u0438\u043d\u0433 \u0440\u0430\u0431\u043e\u0442\u0430\u043b, \u043d\u043e \u0441\u043b\u0430\u0431\u043e, \u0438\u043c\u0435\u043d\u043d\u043e \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0432\u0435\u043a\u0442\u043e\u0440 \u043d\u0435\u0441\u0451\u0442 \u043c\u0430\u043b\u0443\u044e \u0434\u043e\u043b\u044e \u043f\u043e\u043b\u043d\u043e\u0439 \u0434\u0438\u0441\u043f\u0435\u0440\u0441\u0438\u0438.<\/p>\n<p>\u042d\u0442\u043e \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u043a\u0430\u0440\u0442\u0438\u043d\u0430 \u0434\u043b\u044f \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u043e\u0439 \u0431\u0430\u0437\u043e\u0432\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438. \u0412 \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u043c\u043e\u0434\u0435\u043b\u044f\u0445 \u0441 RLHF \u0438\u043b\u0438 instruction-tuning \u043a\u043e\u043d\u0446\u0435\u043f\u0442\u044b \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u044e\u0442\u0441\u044f \u0447\u0438\u0449\u0435 \u2014 \u0442\u0430\u043c \u0438 steering, \u0438 \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0438\u0440\u0443\u0435\u043c\u043e\u0441\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u043b\u0443\u0447\u0448\u0435. GPT-2 \u2014 \u0445\u043e\u0440\u043e\u0448\u0430\u044f \u0443\u0447\u0435\u0431\u043d\u0430\u044f \u043f\u043b\u043e\u0449\u0430\u0434\u043a\u0430 \u0438\u043c\u0435\u043d\u043d\u043e \u043f\u043e\u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u0437\u0434\u0435\u0441\u044c \u0432\u0441\u0451 \u0432\u0438\u0434\u043d\u043e.<\/p>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, activation steering \u2014 \u0445\u043e\u0442\u044c \u0438 \u0441\u0438\u043b\u044c\u043d\u044b\u0439, \u043d\u043e \u0431\u0435\u0437\u0443\u043c\u043d\u043e \u043d\u044e\u0430\u043d\u0441\u0438\u0432\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434, \u043d\u043e \u043d\u044e\u0430\u043d\u0441\u044b \u0441\u0442\u043e\u044f\u0442 \u0442\u043e\u0433\u043e \u2014  steering \u0434\u0430\u0451\u0442 \u0438\u043d\u0442\u0443\u0438\u0446\u0438\u044e \u043e \u0442\u043e\u043c, \u0433\u0434\u0435 \u0438 \u043a\u0430\u043a \u043c\u043e\u0434\u0435\u043b\u044c \u0445\u0440\u0430\u043d\u0438\u0442 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e. \u042d\u0442\u043e \u0444\u0443\u043d\u0434\u0430\u043c\u0435\u043d\u0442 \u0434\u043b\u044f \u0431\u043e\u043b\u0435\u0435 \u0442\u043e\u0447\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u2014 probing, causal tracing, SAE.  \u0410 \u0435\u0449\u0451 \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u0435 steering \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u043f\u043e\u0447\u0443\u0432\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0443 \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0435\u0440\u0430 \u2014 \u043a\u0430\u0436\u0435\u0442\u0441\u044f \u043b\u0435\u0433\u0435\u043d\u0434\u0430\u0440\u043d\u0443\u044e \u0432 \u043d\u0430\u0448\u0435 \u0432\u0440\u0435\u043c\u044f. <\/p>\n<p>\u041e\u0442\u0441\u044e\u0434\u0430, \u043f\u043e\u043b\u0435\u0437\u043d\u043e \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u0432 \u043d\u0435\u043c \u0440\u0443\u043a\u0430\u043c\u0438. \u0418 \u043c\u044b \u0441 \u0432\u0430\u043c\u0438  \u043f\u0440\u043e\u0448\u043b\u0438 \u043f\u0443\u0442\u044c \u043e\u0442 \u0441\u044b\u0440\u044b\u0445 PyTorch hooks \u0434\u043e \u0434\u0435\u043a\u043b\u0430\u0440\u0430\u0442\u0438\u0432\u043d\u044b\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a, \u0441\u0442\u043e\u043b\u043a\u043d\u0443\u043b\u0438\u0441\u044c \u0441 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u043c\u0438 failure modes \u0438 \u043d\u0430\u0443\u0447\u0438\u043b\u0438\u0441\u044c \u0438\u0445 \u0434\u0438\u0430\u0433\u043d\u043e\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c.<\/p>\n<\/div>\n<div class=\"persona\"><img decoding=\"async\" class=\"image persona__image\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/b4f\/ef8\/b2a\/b4fef8b2ab6060bfafcf711ae41cd167.jpg\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/b4f\/ef8\/b2a\/b4fef8b2ab6060bfafcf711ae41cd167.jpg 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/b4f\/ef8\/b2a\/b4fef8b2ab6060bfafcf711ae41cd167.jpg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<h5 class=\"persona__heading\">\u0421\u043f\u0430\u0441\u0438\u0431\u043e!<\/h5>\n<p>\u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u0432\u044b \u043f\u0440\u043e\u0432\u0435\u043b\u0438 \u0432\u0440\u0435\u043c\u044f \u0441 \u0443\u0434\u043e\u0432\u043e\u043b\u044c\u0441\u0442\u0432\u0438\u0435\u043c. \u0415\u0441\u043b\u0438 \u0432\u0430\u043c \u043f\u043e\u043d\u0440\u0430\u0432\u0438\u043b\u043e\u0441\u044c, \u043f\u0440\u0438\u0441\u043e\u0435\u0434\u0438\u043d\u044f\u0439\u0442\u0435\u0441\u044c \u043a \u0442\u0435\u043b\u0435\u0433\u0440\u0430\u043c\u043c-\u043a\u0430\u043d\u0430\u043b\u0443 [Just Data Blog](<a href=\"https:\/\/t.me\/jdata_blog\" rel=\"noopener noreferrer nofollow\">https:\/\/t.me\/jdata_blog<\/a>), \u0441\u0442\u0430\u0432\u044c\u0442\u0435 \u043b\u0430\u0439\u043a\u0438 \u0438 \u044f \u043d\u0435 \u0443\u0439\u0434\u0443 \u043f\u0430\u0441\u0442\u0438 \u043e\u0432\u0435\u0446, \u0430 \u0431\u0443\u0434\u0443 \u043f\u0438\u0441\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0435 \u0442\u0443\u0442\u043e\u0440\u0438\u0430\u043b\u044b. <\/p>\n<\/div>\n<p>\u0414\u043e \u0432\u0441\u0442\u0440\u0435\u0447\u0438!<\/p>\n<p>\u041d\u043e\u0443\u0442\u0431\u0443\u043a: <a href=\"https:\/\/drive.google.com\/file\/d\/19dLuPkB5gALgqdmtbsaDLqjcwuOzYwJ0\/view?usp=sharing\" rel=\"noopener noreferrer nofollow\">GoogleCollab<\/a><br \/>GitHub: <a href=\"https:\/\/github.com\/SadSabrina\/XAI-open_materials\/blob\/main\/steering\/https:\/\/drive.google.com\/file\/d\/19dLuPkB5gALgqdmtbsaDLqjcwuOzYwJ0\/view?usp=sharing\" rel=\"noopener noreferrer nofollow\">RepoNotebockFile<\/a><\/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\/1047630\/\">https:\/\/habr.com\/ru\/articles\/1047630\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u041f\u0440\u0438\u0432\u0435\u0442, \u0434\u0440\u0443\u0437\u044c\u044f! \u0415\u0441\u043b\u0438 \u0432\u044b \u043f\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0443 &#171;\u043a\u0430\u043a \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u044c \u0434\u043e\u0431\u0440\u0435\u0435&#187; \u0432\u0438\u0434\u0438\u0442\u0435 \u0432 output-\u0435 LLM \u0444\u0440\u0430\u0437\u0443 &#171;\u0440\u0443\u043b\u0435\u0432\u043e\u0435 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435&#187; \u2014 \u0437\u043d\u0430\u0447\u0438\u0442 LLM \u0433\u043e\u0432\u043e\u0440\u0438\u0442 \u043f\u0440\u043e Steering. \u0412 \u044d\u0442\u043e\u043c \u0442\u0443\u0442\u043e\u0440\u0438\u0430\u043b\u0435 \u0432\u044b:\u0443\u0437\u043d\u0430\u0435\u0442\u0435, \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 steering \u0438 \u043d\u0430 \u0447\u0435\u043c \u043e\u043d \u043e\u0441\u043d\u043e\u0432\u0430\u043d;\u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0438\u0442\u0435 steering, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f pytorch-hooks;\u043f\u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u0435\u0441\u044c \u0441 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430\u043c\u0438 nnsight \u0438 pyvene \u0434\u043b\u044f interventions;\u0418 \u0435\u0441\u043b\u0438 \u043a\u0430\u043a\u043e\u0435-\u0442\u043e \u0441\u043b\u043e\u0432\u043e \u0438\u0437 bullet-\u043e\u0432 \u0431\u044b\u043b\u043e \u043d\u0435\u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u043e\u043d\u0438 \u0432\u0441\u0435 \u0441\u0442\u0430\u043d\u0443\u0442 \u0432\u0430\u043c \u043f\u043e\u043d\u044f\u0442\u043d\u044b \u043a \u043a\u043e\u043d\u0446\u0443. Created by my best friend \u2014 Claude.Activation Steering \u2014\u00a0\u044d\u0442\u043e\u0412 research-\u043d\u0430\u0440\u043e\u0434\u044c\u0435, Activation Steering \u2014 \u044d\u0442\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435, \u0432\u044b\u0447\u0438\u0442\u0430\u043d\u0438\u0435 \u0438\u043b\u0438 \u0438\u043d\u0430\u044f \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u0432\u0435\u043a\u0442\u043e\u0440\u043e\u0432 \u0432\u043e \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0445 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f\u0445 LLM \u0432\u043e \u0432\u0440\u0435\u043c\u044f forward pass-\u0430. Steering \u043e\u0441\u043d\u043e\u0432\u0430\u043d \u043d\u0430 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u0443 \u043e\u0431\u0443\u0447\u0435\u043d\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u0435\u0441\u0442\u044c \u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u00ab\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f\u00bb \u0432 \u043b\u0430\u0442\u0435\u043d\u0442\u043d\u043e\u043c \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0435. Activation Steering \u2014 \u044d\u0442\u043e inference-time intervention (\u0432\u043c\u0435\u0448\u0430\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u043e \u0432 \u043c\u043e\u0434\u0435\u043b\u044c \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0438\u043d\u0444\u0435\u0440\u0435\u043d\u0441\u0430). \u041c\u044b \u043d\u0435 \u043c\u0435\u043d\u044f\u0435\u043c \u0432\u0435\u0441\u0430 \u043c\u043e\u0434\u0435\u043b\u0438 (\u0432 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 fine-tuning) \u2014 \u043c\u044b \u0432\u043c\u0435\u0448\u0438\u0432\u0430\u0435\u043c\u0441\u044f \u0432 \u043f\u043e\u0442\u043e\u043a \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439 &#171;\u043d\u0430 \u043b\u0435\u0442\u0443&#187;, \u043f\u043e\u043a\u0430 \u043c\u043e\u0434\u0435\u043b\u044c &#171;\u0434\u0443\u043c\u0430\u0435\u0442&#187; \u2014\u00a0\u0442\u043e \u0435\u0441\u0442\u044c \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442.\u0411\u0430\u0437\u043e\u0432\u0430\u044f \u0444\u043e\u0440\u043c\u0443\u043b\u0430:\u0433\u0434\u0435  \u2014 steering vector, \u0432\u0435\u043a\u0442\u043e\u0440, \u043a\u043e\u0434\u0438\u0440\u0443\u044e\u0449\u0438\u0439 \u043d\u0443\u0436\u043d\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435,\u2014 \u043d\u043e\u043c\u0435\u0440 \u0441\u043b\u043e\u044f, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0432\u043c\u0435\u0448\u0438\u0432\u0430\u0435\u043c\u0441\u044f,  \u2014 \u0441\u0438\u043b\u0430 \u0432\u043c\u0435\u0448\u0430\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u0430.\u0421\u0434\u0432\u0438\u0433\u0430\u0435\u043c\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0447\u0451\u0442\u043a\u043e \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u043e \u0438 \u0438\u043c\u0435\u0442\u044c \u043f\u043e\u043b\u044f\u0440\u043d\u0443\u044e \u043f\u0430\u0440\u0443, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440:refusal vs compliance;positive sentiment vs negative sentiment;\u0417\u0430\u043c\u0435\u0442\u0438\u043c, \u0447\u0442\u043e \u0432\u043e \u0432\u0442\u043e\u0440\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 &#171;positive&#187; \u0438 &#171;negative&#187; \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043e\u043c. \u041a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u0438\u0437 \u0436\u0438\u0437\u043d\u0438 \u2014\u00a0\u0442\u043e, \u0447\u0442\u043e &#171;positive&#187; \u0434\u043b\u044f \u043a\u043e\u043d\u0441\u0435\u0440\u0432\u0430\u0442\u0438\u0432\u043d\u044b\u0445 \u043b\u044e\u0434\u0435\u0439, \u044f\u0432\u043d\u043e &#171;negative&#187; \u0434\u043b\u044f \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u043a\u043e\u0432 \u043d\u043e\u0432\u043e\u0433\u043e. \u041e\u0442\u043b\u043e\u0436\u0438\u043c \u044d\u0442\u043e \u043f\u043e\u043a\u0430 \u0432 \u043f\u0430\u043c\u044f\u0442\u0438. \u0412 \u044d\u0442\u043e\u043c \u0442\u0443\u0442\u043e\u0440\u0438\u0430\u043b\u0435 \u043c\u044b \u043f\u043e\u0441\u0442\u0430\u0432\u0438\u043c \u0446\u0435\u043b\u044c \u0441\u0434\u0432\u0438\u043d\u0443\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u044c \u0432 \u0441\u0442\u043e\u0440\u043e\u043d\u0443 hate-speech. \u0412\u044b\u0431\u043e\u0440 \u0442\u0435\u043c\u044b hate-speech \u043e\u0431\u0443\u0441\u043b\u043e\u0432\u043b\u0435\u043d \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u043c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043e\u043c. \u0421\u0434\u0432\u0438\u0433\u0430\u0442\u044c, \u043f\u043e\u0432\u0442\u043e\u0440\u044e\u0441\u044c, \u043c\u043e\u0436\u043d\u043e \u0432 \u043b\u044e\u0431\u043e\u0435 \u043c\u0435\u0441\u0442\u043e, \u0432\u044b\u0440\u0430\u0436\u0430\u044e\u0449\u0435\u0435 \u043f\u043e\u043b\u044f\u0440\u043d\u043e\u0441\u0442\u044c.\u041f\u0440\u0438\u043c\u0435\u0440\u044b \u0438\u0437 \u043d\u043e\u0443\u0442\u0431\u0443\u043a\u0430 \u043d\u0435 \u0432\u044b\u0440\u0430\u0436\u0430\u044e\u0442 \u043c\u043e\u044e \u043b\u0438\u0447\u043d\u0443\u044e \u043f\u043e\u0437\u0438\u0446\u0438\u044e \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u0443\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0432\u044b\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u043d\u0438\u044f.\u0427\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0434\u043b\u044f steering?\u041f\u0435\u0440\u0432\u043e\u0435 \u2014\u00a0\u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u043c\u043e\u0434\u0435\u043b\u044c. \u0414\u043b\u044f \u0431\u044b\u0441\u0442\u0440\u043e\u0433\u043e \u0434\u0435\u043c\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c gpt2, \u0447\u0442\u043e\u0431\u044b \u043d\u043e\u0443\u0442\u0431\u0443\u043a \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u043b\u0441\u044f \u043f\u043e\u0447\u0442\u0438 \u0432\u0435\u0437\u0434\u0435.\u0421\u043a\u0440\u044b\u0442\u044b\u0439 \u0442\u0435\u043a\u0441\u0442\u0414\u043b\u044f \u0431\u043e\u043b\u0435\u0435 \u0432\u0435\u0441\u0435\u043b\u044b\u0445 \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u043e\u0432 \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c MODEL_NAME \u0432 \u043d\u043e\u0443\u043a\u0442\u0431\u0443\u043a\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u044f \u043f\u0440\u0438\u043a\u0440\u0435\u043f\u043b\u044e \u043d\u0438\u0436\u0435 \u043d\u0430:- gpt2-medium- EleutherAI\/pythia-410m- TinyLlama\/TinyLlama-1.1B-Chat-v1.0- Llama\/Mistral\/Gemma open-weight \u043c\u043e\u0434\u0435\u043b\u0438, \u0435\u0441\u043b\u0438 \u0435\u0441\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u0438 GPU\u0412\u044b\u0431\u0438\u0440\u0430\u0439\u0442\u0435 \u0441\u0432\u043e\u0451!Contrastive dataset\u041f\u0435\u0440\u0432\u044b\u0439 \u0448\u0430\u0433 \u0441\u0442\u0438\u0440\u0438\u043d\u0433\u0430 \u2014\u00a0\u043a\u043e\u043d\u0441\u0442\u0440\u0443\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f. \u0427\u0442\u043e\u0431\u044b \u0435\u0433\u043e \u043d\u0430\u0439\u0442\u0438, \u043d\u0430\u043c \u043d\u0443\u0436\u0435\u043d \u043d\u0430\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445, \u043e\u0442\u0440\u0430\u0436\u0430\u044e\u0449\u0438\u0439 \u0441\u0434\u0432\u0438\u0433\u0430\u0435\u043c\u0443\u044e \u043f\u043e\u043b\u044f\u0440\u043d\u043e\u0441\u0442\u044c. \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043d\u0430\u0448\u0430 \u0446\u0435\u043b\u044c hate-speech, \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c mixed_hate_dataset, \u0433\u0434\u0435 \u043a\u0430\u0436\u0434\u043e\u0435 \u0432\u044b\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u043d\u0438\u0435 \u0438\u043c\u0435\u0435\u0442 \u043e\u0434\u043d\u0443 \u0438\u0437 \u0434\u0432\u0443\u0445 \u043c\u0435\u0442\u043e\u043a:0 (is_harmfull_opposition): \u043d\u0435\u043d\u0430\u0432\u0438\u0441\u0442\u043d\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \/ \u0434\u0438\u0441\u043a\u0440\u0438\u043c\u0438\u043d\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u0435 \u0432\u044b\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u043d\u0438\u0435. \u041f\u0440\u0438\u043c\u0435\u0440:&#187;Mentally retarded people are uneducated and should not be accepted into schools.&#187;1 (is_harmfull_opposition): \u043e\u043f\u0440\u043e\u0432\u0435\u0440\u0436\u0435\u043d\u0438\u0435 \/ tolerant&#187;Mentally retarded people can be educated and should be accepted into schools.&#187;\u0414\u0430\u0442\u0430\u0441\u0435\u0442 \u0441\u043e\u0431\u0440\u0430\u043d \u0442\u0430\u043a, \u0447\u0442\u043e \u043a\u0430\u0436\u0434\u043e\u0435 harmfull \u0438\u043c\u0435\u0435\u0442 safe \u043f\u0430\u0440\u0443. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043e\u043d \u0445\u043e\u0440\u043e\u0448 \u0434\u043b\u044f steering. \u0418\u0434\u0435\u0430\u043b\u0435\u043d \u043e\u043d \u0431\u044b\u043b \u0431\u044b, \u0435\u0441\u043b\u0438 \u0431\u044b \u0432\u0441\u0435 \u0442\u043e\u043f\u0438\u043a\u0438 \u0431\u044b\u043b\u0438 \u0438\u0437 \u043e\u0434\u043d\u043e\u0439 \u0442\u0435\u043c\u044b, \u043d\u043e \u043b\u0443\u0447\u0448\u0435\u0435 \u2014\u00a0\u0432\u0440\u0430\u0433 \u0445\u043e\u0440\u043e\u0448\u0435\u0433\u043e \u0438 \u0435\u0433\u043e \u043d\u0430\u043c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e. \u0412 \u0442\u0430\u043a\u043e\u0439 \u043f\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0435 \u0434\u0430\u043d\u043d\u044b\u0445, \u043c\u044b \u043e\u0436\u0438\u0434\u0430\u0435\u043c, \u0447\u0442\u043e steering vector \u0431\u0443\u0434\u0435\u0442 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0438\u0437 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0430 \u043d\u0435\u043d\u0430\u0432\u0438\u0441\u0442\u043d\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0432\u044b\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u043d\u0438\u0439 \u0432 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u043e \u0432\u044b\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u043d\u0438\u0439 \u0442\u043e\u043b\u0435\u0440\u0430\u043d\u0442\u043d\u044b\u0445:steering_vector = mean(acts_tolerant) \u2212 mean(acts_hate)\u041f\u043e \u043f\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0435 \u0432\u0435\u043a\u0442\u043e\u0440\u0430, \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u044f \u0435\u0433\u043e \u0441 alpha &gt; 0, \u043c\u044b \u0442\u043e\u043b\u043a\u0430\u0435\u043c \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044e \u0432 \u0441\u0442\u043e\u0440\u043e\u043d\u0443 tolerant (\u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0432\u0435\u0441\u044c hate \u0438\u0437 tolerant \u043c\u044b \u0432\u044b\u0447\u043b\u0438). \u0421 alpha &lt; 0 \u2014 \u0432 \u043e\u0431\u0440\u0430\u0442\u043d\u0443\u044e \u0441\u0442\u043e\u0440\u043e\u043d\u0443. \u0423 \u044d\u0442\u043e\u0433\u043e \u0435\u0441\u0442\u044c \u043d\u044e\u0430\u043d\u0441\u044b \u0438 \u0438\u0445 \u0432\u044b \u0443\u0432\u0438\u0434\u0438\u0442\u0435 \u043d\u0438\u0436\u0435. \u0414\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c residual stream \u043c\u043e\u0434\u0435\u043b\u0438 \u043d\u0430 \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u043e\u0435. Residual streamGPT-2, \u043a\u0430\u043a \u0438 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0435\u0440\u043e\u0432, \u0443\u0441\u0442\u0440\u043e\u0435\u043d \u043f\u043e \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0443 residual connections: \u043a\u0430\u0436\u0434\u044b\u0439 \u0431\u043b\u043e\u043a \u043d\u0435 \u00ab\u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442\u00bb \u0442\u0435\u043d\u0437\u043e\u0440 \u0441 \u043d\u0443\u043b\u044f, \u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u0432\u043e\u0439 \u0432\u043a\u043b\u0430\u0434 \u043a \u0443\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u043c\u0443:\u042d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e \u043e\u0434\u0438\u043d \u0438 \u0442\u043e\u0442 \u0436\u0435 \u00ab\u043f\u043e\u0442\u043e\u043a\u00bb \u2014 residual stream \u2014 \u0438\u0434\u0435\u0442 \u043e\u0442 \u0432\u0445\u043e\u0434\u0430 \u0434\u043e \u0432\u044b\u0445\u043e\u0434\u0430 \u0447\u0435\u0440\u0435\u0437 \u0432\u0441\u0435 \u0441\u043b\u043e\u0438. \u041a\u0430\u0436\u0434\u044b\u0439 \u0441\u043b\u043e\u0439 \u0447\u0438\u0442\u0430\u0435\u0442 \u0438\u0437 \u043d\u0435\u0433\u043e \u0438 \u0434\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u0432 \u043d\u0435\u0433\u043e. model.transformer.h[layer] \u2014 \u044d\u0442\u043e \u0432\u044b\u0445\u043e\u0434 residual block , \u0442\u043e \u0435\u0441\u0442\u044c  \u043f\u043e\u0441\u043b\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0441\u043b\u043e\u044f. \u041e\u043d \u0436\u0435 \u0438\u043c\u0435\u043d\u0443\u0435\u0442\u0441\u044f \u043a\u0430\u043a hidden_state. \u041f\u043e\u0447\u0435\u043c\u0443 residual stream \u0432\u0430\u0436\u0435\u043d \u0434\u043b\u044f \u043d\u0430\u0441: \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u0432 \u043d\u0451\u043c \u043d\u0430\u043a\u0430\u043f\u043b\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0430\u0434\u0434\u0438\u0442\u0438\u0432\u043d\u043e \u2014 \u0435\u0441\u043b\u0438 \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u043d\u0430 \u0441\u043b\u043e\u0435 &#171;\u0434\u043e&#187; \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043d\u0430\u0434\u0435\u044f\u0442\u0441\u044f, \u0447\u0442\u043e \u043a\u043e\u043d\u0446\u0435\u043f\u0442 \u043f\u0440\u043e\u0441\u0442\u043e \u0436\u0438\u0432\u0435\u0442 \u0432 \u0434\u0440\u0443\u0433\u043e\u043c \u0441\u043b\u043e\u0435;\u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043f\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044e \u0432\u044b\u043d\u0443\u0436\u0434\u0435\u043d\u0430 \u0447\u0438\u0442\u0430\u0442\u044c\u0441\u044f \u043b\u0438\u043d\u0435\u0439\u043d\u043e, \u043e\u0442\u0441\u044e\u0434\u0430 \u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0433\u043e \u0441\u0434\u0432\u0438\u0433\u0430 \u043d\u0430\u043c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e (\u0432\u043e \u043c\u043d\u043e\u0433\u043e\u043c \u0442\u0430\u043a \u043a\u0430\u043a \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u0441\u043e\u0431\u0440\u0430\u043d \u0446\u0435\u043b\u0438\u043a\u043e\u043c \u0438\u0437 \u043b\u0438\u043d\u0435\u0439\u043d\u044b\u0445 \u043f\u0440\u043e\u0435\u043a\u0446\u0438\u0439: )\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u0442\u043e\u043a\u0435\u043d\u0430. \u0417\u0430\u043c\u0435\u0442\u0438\u043c, \u0447\u0442\u043e \u0432 residual stream, \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435, \u043c\u043d\u043e\u0433\u043e \u0442\u043e\u043a\u0435\u043d\u043e\u0432. \u041c\u044b \u0431\u0443\u0434\u0435\u043c \u0431\u0440\u0430\u0442\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439. GPT-2 \u2014 \u0430\u0432\u0442\u043e\u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u043e\u043d\u043d\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c \u0441 causal attention: \u0442\u043e\u043a\u0435\u043d \u043d\u0430 \u043f\u043e\u0437\u0438\u0446\u0438\u0438  \u0432\u0438\u0434\u0438\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u043e\u043a\u0435\u043d\u044b \u0441 \u043f\u043e\u0437\u0438\u0446\u0438\u044f\u043c\u0438 . \u042d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0442\u043e\u043a\u0435\u043d \u0432\u0438\u0434\u0438\u0442 \u0432\u0435\u0441\u044c \u043f\u0440\u0435\u0434\u0448\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0438 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0435\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c \u00ab\u0441\u0431\u043e\u0440\u0449\u0438\u043a\u043e\u043c\u00bb \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e \u043f\u0440\u043e\u043c\u043f\u0442\u0435.\u0410\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u044b \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u2014 \u0443\u0441\u0440\u0435\u0434\u043d\u0435\u043d\u0438\u0435 \u043f\u043e \u0432\u0441\u0435\u043c \u0442\u043e\u043a\u0435\u043d\u0430\u043c, \u0432\u0437\u0432\u0435\u0448\u0435\u043d\u043d\u043e\u0435 \u043f\u043e attention \u2014 \u043d\u043e \u043e\u043d\u0438 \u043d\u0435\u043f\u043e\u043d\u044f\u0442\u043d\u044b \u0434\u043b\u044f \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0446\u0438\u0438 \u0438 \u043f\u043e\u0447\u0442\u0438 \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f. Hook.Hook \u2014 \u044d\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f-\u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u0447\u0438\u043a, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0432\u044b \u00ab\u0432\u0435\u0448\u0430\u0435\u0442\u0435\u00bb \u043d\u0430 \u043c\u043e\u0434\u0443\u043b\u044c. \u041e\u043d\u0430 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u0440\u0438 \u043a\u0430\u0436\u0434\u043e\u043c forward pass:handle = model.transformer.h[layer].register_forward_hook(hook_fn)# hook_fn(module, input, output) \u2014 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u043e\u0441\u043b\u0435 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0441\u043b\u043e\u044fPyTorch \u0432\u044b\u0437\u043e\u0432\u0435\u0442 hook_fn \u0441\u0440\u0430\u0437\u0443 \u043f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u0441\u043b\u043e\u0439 \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435. \u041c\u043e\u0436\u043d\u043e:\u0447\u0438\u0442\u0430\u0442\u044c output \u0438 \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u0442\u044c \u0430\u043a\u0442\u0438\u0432\u0430\u0446\u0438\u0438 (\u043a\u0430\u043a \u0437\u0434\u0435\u0441\u044c)\u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0442\u0435\u043d\u0437\u043e\u0440 \u0438 \u0434\u0435\u043b\u0430\u0442\u044c steering\u0422\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u2014\u00a0\u043f\u043e\u0441\u043b\u0435 \u0440\u0430\u0431\u043e\u0442\u044b \u2014 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e handle.remove(), \u0438\u043d\u0430\u0447\u0435 hook \u043e\u0441\u0442\u0430\u043d\u0435\u0442\u0441\u044f \u0432\u0438\u0441\u0435\u0442\u044c \u043d\u0430 \u043c\u043e\u0434\u0435\u043b\u0438 \u043d\u0430\u0432\u0441\u0435\u0433\u0434\u0430. \u041f\u0440\u0438\u043c\u0435\u0440 \u0445\u0443\u043a\u0430 \u2014 \u043d\u0438\u0436\u0435. \u0415\u0441\u043b\u0438 \u044f \u043d\u0430\u043a\u043e\u0441\u044f\u0447\u0438\u043b\u0430 \u0441 \u043e\u0442\u0441\u0442\u0443\u043f\u0430\u043c\u0438 \u2014\u00a0\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u0435, \u043d\u043e \u0443 \u0432\u0430\u0441 \u0431\u0443\u0434\u0435\u0442 \u0442\u0435\u0442\u0440\u0430\u0434\u044c. \u041f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0435 steering vector\u041c\u0435\u0442\u043e\u0434 \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f Contrastive Activation Addition (CAA) \u2014 \u0438\u0437 \u0441\u0442\u0430\u0442\u044c\u0438 Steering Llama 2 via Contrastive Activation Addition. \u0418\u0434\u0435\u044f: \u0411\u0435\u0440\u0451\u043c \u0434\u0432\u0430 \u043d\u0430\u0431\u043e\u0440\u0430 \u043f\u0440\u043e\u043c\u043f\u0442\u043e\u0432: \u043f\u043e\u0437\u0438\u0442\u0438\u0432\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441  (tolerant) \u0438 \u043d\u0435\u0433\u0430\u0442\u0438\u0432\u043d\u044b\u0439  (hate).\u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u0440\u043e\u043c\u043f\u0442\u0430 \u0441\u043d\u0438\u043c\u0430\u0435\u043c \u0430\u043a\u0442\u0438\u0432\u0430\u0446\u0438\u044e \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u0442\u043e\u043a\u0435\u043d\u0430 \u043d\u0430 \u0441\u043b\u043e\u0435 $\\ell$.\u0412\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c \u0440\u0430\u0437\u043d\u043e\u0441\u0442\u044c \u0441\u0440\u0435\u0434\u043d\u0438\u0445:\u041d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u0443\u0435\u043c: \u0421\u0442\u043e\u043f. \u0412\u0435\u0434\u044c \u043f\u0430\u0440\u0443 \u0430\u0431\u0437\u0430\u0446\u0435\u0432 \u0432\u044b\u0448\u0435 \u0442\u044b \u0441\u043a\u0430\u0437\u0430\u043b\u0430, \u0447\u0442\u043e \u0441\u0440\u0435\u0434\u043d\u0435\u0435 \u0431\u0435\u0441\u0441\u043c\u044b\u0441\u043b\u0435\u043d\u043d\u043e. \u0421\u0440\u0435\u0434\u043d\u0435\u0435 \u043f\u043e \u0442\u043e\u043a\u0435\u043d\u0430\u043c \u0432\u043d\u0443\u0442\u0440\u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u2014 \u043d\u0435 \u0442\u043e, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0441\u043c\u0435\u0448\u0438\u0432\u0430\u0435\u0442 \u0440\u0430\u0437\u043d\u044b\u0435 \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0440\u043e\u043b\u0438.\u0421\u0440\u0435\u0434\u043d\u0435\u0435 \u0436\u0435 \u043f\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c \u2014  \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0430 \u043d\u0430\u0434 \u043f\u043e\u043d\u044f\u0442\u0438\u0435\u043c \u2014\u00a0\u0435\u0441\u043b\u0438 \u043f\u043e\u043d\u044f\u0442\u0438\u0435  (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, &#171;\u0442\u043e\u043a\u0441\u0438\u0447\u043d\u043e\u0441\u0442\u044c&#187;) \u043a\u043e\u0434\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0432 residual stream, \u0442\u043e \u043e\u043d\u043e \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044e .\u0422\u043e\u0433\u0434\u0430 \u0430\u043a\u0442\u0438\u0432\u0430\u0446\u0438\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u0442\u043e\u043a\u0435\u043d\u0430 \u0434\u043b\u044f -\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0440\u0430\u0441\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043a\u0430\u043a:\u0433\u0434\u0435  \u0434\u043b\u044f \u043f\u043e\u0437\u0438\u0442\u0438\u0432\u043d\u044b\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432,  \u0434\u043b\u044f \u043d\u0435\u0433\u0430\u0442\u0438\u0432\u043d\u044b\u0445,  \u2014 \u0448\u0443\u043c.\u0422\u043e\u0433\u0434\u0430:\u041d\u0430 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u0443 \u2014 \u0437\u0430\u0431\u0438\u043b\u0438. \u041f\u043e\u0447\u0435\u043c\u0443 \u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u0443\u0435\u043c?\u0411\u0435\u0437 \u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u043b\u0438\u043d\u0430  \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442:\u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u043f\u0440\u043e\u043c\u043f\u0442\u043e\u0432 \u0432 \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u0435\u00ab\u0440\u0430\u0437\u0431\u0440\u043e\u0441\u0430\u00bb \u0430\u043a\u0442\u0438\u0432\u0430\u0446\u0438\u0439 \u0432 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u043c \u0441\u043b\u043e\u0435\u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0430 \u0441\u0430\u043c\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438\u041f\u043e\u0441\u043b\u0435 \u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438  \u2014 \u0435\u0434\u0438\u043d\u0438\u0447\u043d\u044b\u0439 \u0432\u0435\u043a\u0442\u043e\u0440, \u0438  \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c, \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u043c \u0441\u0438\u043b\u043e\u0439 \u0432\u043c\u0435\u0448\u0430\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u0430. def build_steering_vector(pos_prompts: List[str], neg_prompts: List[str], layer: int) -&gt; torch.Tensor:    pos = get_block_output_activations(pos_prompts, layer)    neg = get_block_output_activations(neg_prompts, layer)    vec = (pos &#8212; neg).mean(dim=0)    vec = vec \/ (vec.norm() + 1e-8)    return vec.to(DEVICE)STEER_LAYER = 6steering_vector = build_steering_vector(positive_prompts, negative_prompts, STEER_LAYER)print(&#171;vector shape:&#187;, steering_vector.shape)print(&#171;norm:&#187;, steering_vector.norm().item()) # \u041f\u043e\u0434\u0443\u043c\u0430\u0439\u0442\u0435, \u043f\u043e\u0447\u0435\u043c\u0443 \u043d\u043e\u0440\u043c\u0430 \u0440\u0430\u0432\u043d\u0430 \u0435\u0434\u0438\u043d\u0438\u0446\u0435. # \u0415\u0441\u043b\u0438 \u0432\u044b \u043d\u0435 \u0434\u0430\u043b\u0438 \u043e\u0442\u0432\u0435\u0442 \u0441\u0445\u043e\u0434\u0443 \u2014\u00a0\u0432\u0435\u0440\u043d\u0438\u0442\u0435\u0441\u044c \u043a \u0442\u0435\u043e\u0440\u0438\u0438!Sanity check\u0427\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u044f\u0442\u044c, \u0441\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u043d\u043d\u044b\u0439 \u0432\u0435\u043a\u0442\u043e\u0440 \u043e\u0441\u043c\u044b\u0441\u043b\u0435\u043d\u043d\u0435\u0435, \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0435\u043a\u0446\u0438\u044e \u0432 \u0441\u0435\u043c\u0430\u043d\u0442\u0438\u043a\u0443 \u043c\u0435\u0442\u043e\u0434\u043e\u043c logit lens. \u041f\u0440\u043e \u043d\u0435\u0433\u043e \u044f \u043f\u0438\u0441\u0430\u043b\u0430 (\u043d\u043e \u0434\u043b\u044f \u043a\u0430\u0440\u0442\u0438\u043d\u043e\u043a), \u0434\u043b\u044f \u0442\u0435\u043a\u0441\u0442\u043e\u0432 \u0442\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435 \u2014 \u043c\u044b \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0432\u0435\u043a\u0442\u043e\u0440 \u0447\u0435\u0440\u0435\u0437 lm_head \u0438 \u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a\u0438\u0435 \u0442\u043e\u043a\u0435\u043d\u044b \u043e\u043d \u00ab\u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0438\u0442\u0430\u0435\u0442\u00bb \u0438 \u00ab\u0438\u0437\u0431\u0435\u0433\u0430\u0435\u0442\u00bb.\u0422\u043e, \u0447\u0442\u043e \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c, \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0442\u043e\u0447\u043d\u043e \u2014\u00a0 \u0432\u0435\u043a\u0442\u043e\u0440 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0435 \u0430\u043a\u0442\u0438\u0432\u0430\u0446\u0438\u0439 residual stream, \u0430 \u043d\u0435 \u0444\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u043c logit-\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0435, \u043d\u043e \u0434\u0430\u0441\u0442 \u0438\u043d\u0442\u0443\u0438\u0446\u0438\u044e \u043e \u0441\u0435\u043c\u0430\u043d\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u043c \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0438 \u0432\u0435\u043a\u0442\u043e\u0440\u0430 \u2014 \u0438 \u043e\u0442\u0441\u044e\u0434\u0430 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u043e \u043a\u0430\u043a sanity check. \u041d\u0430 \u043f\u043e\u0434\u043e\u043f\u044b\u0442\u043d\u043e\u043c \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u0435, \u043c\u044b \u0441 \u0432\u0430\u043c\u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:\u0421\u043f\u0438\u0441\u043e\u043a \u043f\u0440\u043e\u0442\u0438\u0432 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0441\u044f \u0432\u043f\u043e\u043b\u043d\u0435 \u0441\u0435\u0431\u0435 hate, \u043e\u0434\u043d\u0430\u043a\u043e \u0441\u043f\u0438\u0441\u043e\u043a \u0441 \u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438 \u0432\u044b\u0448\u0435\u043b \u0448\u0443\u043c\u043d\u044b\u043c \u2014\u00a0\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043c\u0443\u0441\u043e\u0440 \u0434\u043b\u044f \u043d\u0430\u0448\u0435\u0439 \u0437\u0430\u0434\u0430\u0447\u0438 \u2014 \u0442\u043e\u0447\u043d\u043e \u0442\u043e\u043a\u0435\u043d\u044b stellar, NAV, incorpor, eele. \u041e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u043c\u044b \u043d\u0430\u0448\u043b\u0438 \u043d\u0435 \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u044b\u0439 \u0432\u0435\u043a\u0442\u043e\u0440, \u043e\u043d \u043a\u043e\u0434\u0438\u0440\u0443\u0435\u0442 \u043e\u0441\u044c &#171;\u0430\u0433\u0440\u0435\u0441\u0441\u0438\u0432\u043d\u0430\u044f \u043b\u0435\u043a\u0441\u0438\u043a\u0430 vs \u0447\u0442\u043e-\u0442\u043e \u0435\u0449\u0451&#187;, \u0430 \u043d\u0435 \u0441\u0442\u0440\u043e\u0433\u043e &#171;hate vs tolerant&#187;.\u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u043d\u0430\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u043c\u0435\u0435\u0442 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0448\u0443\u043c \u2014 \u043e\u043d \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0444\u0440\u0430\u0437, \u0433\u0434\u0435 \u043e\u043f\u043f\u043e\u0437\u0438\u0442 \u2014 \u043b\u0438\u0448\u044c \u043e\u0442\u0440\u0438\u0446\u0430\u043d\u0438\u0435 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, &#171;Blacks are not dangerous&#187;). \u0422\u0430\u043a\u0438\u0435 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442 hate-\u0442\u0435\u043c\u0443 \u043a\u0430\u043a \u0441\u0443\u0431\u044a\u0435\u043a\u0442 \u0438 \u043c\u043e\u0434\u0435\u043b\u044c \u043c\u043e\u0436\u0435\u0442 \u0430\u043a\u0442\u0438\u0432\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0430 \u043d\u0438\u0445 hate-\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435. \u0420\u0430\u0437\u043d\u043e\u0441\u0442\u044c \u0441\u0440\u0435\u0434\u043d\u0438\u0445 \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0437\u0430\u0448\u0443\u043c\u043b\u0435\u043d\u0430 \u043f\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044e. \u041e\u0434\u043d\u0430\u043a\u043e, \u043d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0432\u0441\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f, \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 hate speech \u043c\u044b \u0438\u043c\u0435\u0435\u043c, \u0438 \u0432\u0441\u0451 \u0440\u0430\u0432\u043d\u043e \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0434\u043b\u044f \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0438. \u041e\u0434\u043d\u0430\u043a\u043e \u0443\u0447\u0442\u0435\u043c \u043d\u0435 \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u0443\u044e \u043f\u043e\u043b\u044f\u0440\u043d\u043e\u0441\u0442\u044c. \u0418 \u043d\u0430 \u044d\u0442\u043e\u043c \u043c\u0435\u0441\u0442\u0435 \u0441\u0430\u043c\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u0434\u043e\u0441\u0442\u0430\u0442\u044c \u043d\u0430\u0448\u0443 \u043e\u0442\u043b\u043e\u0436\u043a\u0443 \u0438\u0437 \u043f\u0430\u043c\u044f\u0442\u0438! \u041f\u043e\u043c\u043d\u0438\u0442\u0435, \u0447\u0442\u043e &#171;positive&#187; \u0438 &#171;negative&#187; \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043e\u043c?  \u0412\u043e\u0442 \u0432\u0430\u043c \u0438 \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u043e\u0435 gargbage in = garbage out. \u0421\u0442\u0438\u0440\u0438\u043c \u041a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0432\u0435\u043d\u0446\u0438\u044f\u041d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c decode-\u0448\u0430\u0433\u0435 (\u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u043e\u0434\u043d\u043e\u0433\u043e \u043d\u043e\u0432\u043e\u0433\u043e \u0442\u043e\u043a\u0435\u043d\u0430) \u043c\u043e\u0434\u0435\u043b\u044c \u0434\u0435\u043b\u0430\u0435\u0442 \u043f\u043e\u043b\u043d\u044b\u0439 forward pass. \u041d\u0430\u0448 hook \u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0432\u044b\u0445\u043e\u0434 \u0441\u043b\u043e\u044f  \u0438 \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u0443\u0435\u0442 \u0435\u0433\u043e:\u0414\u0430\u043b\u044c\u0448\u0435 \u0441\u043b\u043e\u0438  \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u044e\u0442 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0443\u0436\u0435 \u0441 \u0438\u0437\u043c\u0435\u043d\u0451\u043d\u043d\u044b\u043c \u0442\u0435\u043d\u0437\u043e\u0440\u043e\u043c. \u041f\u0440\u0438 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u043d\u043e\u0432\u044b\u0445 \u0442\u043e\u043a\u0435\u043d\u043e\u0432 \u0432\u043c\u0435\u0448\u0430\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u043e \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u0438 \u043a\u0430\u0436\u0434\u043e\u043c decode-\u0448\u0430\u0433\u0435 \u2014 \u043c\u043e\u0434\u0435\u043b\u044c \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u043e\u0434 \u0432\u043e\u0437\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435\u043c \u0432\u0435\u043a\u0442\u043e\u0440\u0430.\u041f\u043e\u0447\u0435\u043c\u0443 \u043e\u043d\u0430 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442?\u041e\u0442\u0432\u0435\u0442 \u0434\u0430\u0451\u0442 \u043d\u0430\u0448\u0435 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u2014\u00a0\u0435\u0441\u043b\u0438 \u043f\u043e\u043d\u044f\u0442\u0438\u0435 \u00abtolerant\u00bb \u043a\u043e\u0434\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0435 \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 , \u0442\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435  \u043a \u0430\u043a\u0442\u0438\u0432\u0430\u0446\u0438\u0438 \u0431\u0443\u043a\u0432\u0430\u043b\u044c\u043d\u043e \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0430\u0435\u0442 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u0432 \u0442\u0443 \u0447\u0430\u0441\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0430\u0441\u0441\u043e\u0446\u0438\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0441 \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u043e\u0439 \u043f\u043e\u043b\u044f\u0440\u043d\u043e\u0441\u0442\u044c\u044e.\u0421\u043b\u043e\u0438, \u0441\u0442\u043e\u044f\u0449\u0438\u0435 \u0432\u044b\u0448\u0435 , \u00ab\u0432\u0438\u0434\u044f\u0442\u00bb \u0441\u043c\u0435\u0449\u0451\u043d\u043d\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0438 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u044e\u0442 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u043a\u0430\u043a \u0431\u0443\u0434\u0442\u043e \u044d\u0442\u043e\u0442 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u0431\u044b\u043b \u0432 \u043d\u0443\u0436\u043d\u044e-\u0441\u0442\u043e\u0440\u043e\u043d\u0443-\u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c. \u042d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0435\u0440\u044b \u0441 residual connections \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u044e\u0442 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u0430\u0434\u0434\u0438\u0442\u0438\u0432\u043d\u043e \u2014 \u043a\u0430\u0436\u0434\u044b\u0439 \u0441\u043b\u043e\u0439 \u0447\u0438\u0442\u0430\u0435\u0442 \u0438\u0437 \u043e\u0431\u0449\u0435\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430 \u0438 \u043f\u0438\u0448\u0435\u0442 \u0432 \u043d\u0435\u0433\u043e. \u041d\u0430\u0448\u0430 \u0434\u043e\u0431\u0430\u0432\u043a\u0430 \u043d\u0435 \u00ab\u043b\u043e\u043c\u0430\u0435\u0442\u00bb \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u2014 \u043e\u043d\u0430 \u0441\u043c\u0435\u0449\u0430\u0435\u0442  \u0442\u043e\u0447\u043a\u0443 \u043e\u0442\u0441\u0447\u0451\u0442\u0430.\u0410 \u043a\u0443\u0434\u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c?\u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043a\u0430\u043a \u043d\u0430 \u0432\u0441\u0435 \u0442\u043e\u043a\u0435\u043d\u044b, \u0442\u0430\u043a \u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439. \u041d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a\u0438 \u0442\u0430\u043a\u0438\u0435:last: \u0441\u0434\u0432\u0438\u0433\u0430\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0437\u0438\u0446\u0438\u044e \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u0442\u043e\u043a\u0435\u043d\u0430 \u2014 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0432\u043c\u0435\u0448\u0430\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u043e, \u043c\u0435\u043d\u044c\u0448\u0435 \u043f\u043e\u0431\u043e\u0447\u043d\u044b\u0445 \u044d\u0444\u0444\u0435\u043a\u0442\u043e\u0432, \u0432\u043b\u0438\u044f\u0435\u0442 \u043d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0439 \u0442\u043e\u043a\u0435\u043d \u0447\u0435\u0440\u0435\u0437 attention \u0434\u0430\u043b\u044c\u0448\u0435 \u043f\u043e \u0441\u0435\u0442\u0438all: \u0441\u0434\u0432\u0438\u0433\u0430\u0435\u043c \u0432\u0441\u0435 \u043f\u043e\u0437\u0438\u0446\u0438\u0438 \u2014 \u0431\u043e\u043b\u0435\u0435 \u0430\u0433\u0440\u0435\u0441\u0441\u0438\u0432\u043d\u043e, \u043c\u0435\u043d\u044f\u0435\u0442 \u0432\u0435\u0441\u044c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 attention \u0431\u0443\u0434\u0435\u0442 \u0447\u0438\u0442\u0430\u0442\u044c \u043d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0441\u043b\u043e\u044f\u0445\u0414\u043b\u044f baseline-\u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u043e\u0432 \u043e\u0431\u044b\u0447\u043d\u043e \u0431\u0435\u0440\u0443\u0442 all \u2014 \u044d\u0444\u0444\u0435\u043a\u0442 \u0441\u0438\u043b\u044c\u043d\u0435\u0435 \u0438 &#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-483710","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/483710","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=483710"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/483710\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=483710"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=483710"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=483710"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}