{"id":448525,"date":"2025-02-17T03:01:51","date_gmt":"2025-02-17T03:01:51","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=448525"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=448525","title":{"rendered":"<span>\u0410\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u0440\u043e\u043c\u043f\u0442\u0430 \u043f\u043e\u0434 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u0443\u044e \u0437\u0430\u0434\u0430\u0447\u0443 \u0441 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u043e\u0439 DSPy<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0426\u0435\u043b\u044c \u2014 \u043d\u0430\u0443\u0447\u0438\u0442\u044c\u0441\u044f \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043c\u043e\u0434\u0443\u043b\u044c\u043d\u044b\u0435 (multi-stage) \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u043d\u0430 \u0431\u0430\u0437\u0435 LLM, \u0430 \u0437\u0430\u0442\u0435\u043c \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u043c\u043f\u0442\u044b (\u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 \u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u044b) \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u0438\u0442\u043e\u0433\u043e\u0432\u0430\u044f \u043c\u0435\u0442\u0440\u0438\u043a\u0430 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0430 (accuracy, retrieval score \u0438 \u0442.\u043f.) \u043f\u0440\u0435\u0432\u044b\u0448\u0430\u043b\u0430 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0441 \u0440\u0443\u0447\u043d\u044b\u043c \u043f\u043e\u0434\u0431\u043e\u0440\u043e\u043c \u0442\u0435\u043a\u0441\u0442\u0430 \u043f\u0440\u043e\u043c\u043f\u0442\u0430.<\/p>\n<h4>\u041f\u043e\u0447\u0435\u043c\u0443 \u043d\u0443\u0436\u043d\u044b \u043c\u043d\u043e\u0433\u043e\u0448\u0430\u0433\u043e\u0432\u044b\u0435 LM-\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0438 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u0440\u043e\u043c\u043f\u0442\u0430<\/h4>\n<p>\u0421\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0431\u043e\u043b\u044c\u0448\u0438\u0435 \u044f\u0437\u044b\u043a\u043e\u0432\u044b\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 (LLM) \u2014 \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, GPT, Llama \u0438 \u043f\u0440. \u2014 \u043e\u0442\u043b\u0438\u0447\u043d\u043e \u0441\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0441 \u0437\u0430\u0434\u0430\u0447\u0430\u043c\u0438 \u043d\u0430 \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0438 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044e \u0442\u0435\u043a\u0441\u0442\u0430, <a href=\"https:\/\/blog.ivan.digital\/toward-software-engineer-llm-agent-emergent-abilities-and-reinforcement-learning-survey-ed32911f5145\" rel=\"noopener noreferrer nofollow\">\u044f \u043f\u0438\u0441\u0430\u043b \u0431\u043e\u043b\u0435\u0435 \u0434\u0435\u0442\u0430\u043b\u044c\u043d\u043e \u043f\u0440\u043e \u0434\u0443\u043c\u0430\u044e\u0449\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u0442\u0438\u043f\u0430 o1 \u0438\u043b\u0438 DeepSeek R1 \u0442\u0443\u0442,<\/a> \u043e\u0434\u043d\u0430\u043a\u043e:<\/p>\n<ol>\n<li>\n<p>\u0427\u0430\u0441\u0442\u043e \u00ab\u0433\u0430\u043b\u043b\u044e\u0446\u0438\u043d\u0438\u0440\u0443\u044e\u0442\u00bb (\u0432\u044b\u0434\u0443\u043c\u044b\u0432\u0430\u044e\u0442 \u0434\u0435\u0442\u0430\u043b\u0438),<\/p>\n<\/li>\n<li>\n<p>\u0422\u0440\u0443\u0434\u043d\u043e \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u0434\u043b\u044f \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u0441\u043b\u043e\u0436\u043d\u043e\u0433\u043e \u043f\u0430\u0439\u043f\u043b\u0430\u0439\u043d\u0430 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u043e\u0433\u0434\u0430 \u0437\u0430\u0434\u0430\u0447\u0430 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0448\u0430\u0433\u043e\u0432 \u043f\u043e\u0438\u0441\u043a\u0430, \u0441\u0432\u043e\u0434\u043a\u0438, \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438).<\/p>\n<\/li>\n<\/ol>\n<p>\u0412\u043e \u043c\u043d\u043e\u0433\u0438\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u043f\u043e\u0434\u0445\u043e\u0434 \u00ab\u043e\u0434\u0438\u043d \u0437\u0430\u043f\u0440\u043e\u0441 \u2013 \u043e\u0434\u0438\u043d \u043e\u0442\u0432\u0435\u0442\u00bb \u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u044b\u043c. \u0412\u043c\u0435\u0441\u0442\u043e \u044d\u0442\u043e\u0433\u043e \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u043c\u044b \u0441\u0442\u0440\u043e\u0438\u043c \u043c\u043d\u043e\u0433\u043e\u0441\u0442\u0443\u043f\u0435\u043d\u0447\u0430\u0442\u044b\u0435 \u043f\u0430\u0439\u043f\u043b\u0430\u0439\u043d\u044b (compound AI systems), \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043a\u0430\u0436\u0434\u044b\u0439 \u0448\u0430\u0433 \u0440\u0435\u0448\u0430\u0435\u0442 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u0443\u044e \u043f\u043e\u0434\u0437\u0430\u0434\u0430\u0447\u0443:<\/p>\n<ul>\n<li>\n<p>\u0421\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0438\u0441\u043a\u043e\u0432\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441,<\/p>\n<\/li>\n<li>\n<p>\u041d\u0430\u0439\u0442\u0438 \u0438\u043b\u0438 \u0438\u0437\u0432\u043b\u0435\u0447\u044c \u0440\u0435\u043b\u0435\u0432\u0430\u043d\u0442\u043d\u044b\u0435 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b,<\/p>\n<\/li>\n<li>\n<p>\u0421\u0432\u0435\u0441\u0442\u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b,<\/p>\n<\/li>\n<li>\n<p>\u0421\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0444\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442.<\/p>\n<\/li>\n<\/ul>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u043f\u043e\u0434\u043e\u0431\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u043c\u044b \u0432\u043d\u0435\u0437\u0430\u043f\u043d\u043e \u0441\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u0435\u043c\u0441\u044f \u0441 \u0437\u0430\u0434\u0430\u0447\u0435\u0439:<\/p>\n<ul>\n<li>\n<p><strong>\u041a\u0430\u043a \u0444\u043e\u0440\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u043c\u043f\u0442\u044b \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0448\u0430\u0433\u0430?<\/strong><\/p>\n<\/li>\n<li>\n<p><strong>\u041a\u0430\u043a \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e \u0443\u043b\u0443\u0447\u0448\u0430\u0442\u044c (\u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c) \u044d\u0442\u0438 \u043f\u0440\u043e\u043c\u043f\u0442\u044b, \u043d\u0435 \u0438\u043c\u0435\u044f \u0438\u043d\u0434\u0438\u0432\u0438\u0434\u0443\u0430\u043b\u044c\u043d\u043e\u0439 \u043c\u0435\u0442\u0440\u0438\u043a\u0438 \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u0448\u0430\u0433\u0435 (\u0442\u043e\u043b\u044c\u043a\u043e \u0438\u0442\u043e\u0433\u043e\u0432\u0430\u044f \u043c\u0435\u0442\u0440\u0438\u043a\u0430)?<\/strong><\/p>\n<\/li>\n<\/ul>\n<p>\u0422\u0443\u0442 \u043d\u0430 \u043f\u043e\u043c\u043e\u0449\u044c \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a<strong> <\/strong><a href=\"https:\/\/github.com\/stanfordnlp\/dspy\" rel=\"noopener noreferrer nofollow\"><strong>DSPy (Declarative Self-improving Python)<\/strong>,<\/a> \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e\u0449\u0438\u0439:<\/p>\n<ul>\n<li>\n<p>\u041e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u043a\u0430\u0436\u0434\u044b\u0439 \u044d\u0442\u0430\u043f \u0432 \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u0445 \u00ab\u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u00bb (signature) \u2014 \u0447\u0442\u043e \u043c\u043e\u0434\u0443\u043b\u044c \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043d\u0430 \u0432\u0445\u043e\u0434, \u0447\u0442\u043e \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u0435\u0440\u043d\u0443\u0442\u044c, \u043a\u0430\u043a\u043e\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438,<\/p>\n<\/li>\n<li>\n<p>\u0417\u0430\u0434\u0430\u0432\u0430\u0442\u044c \u00ab\u0430\u0434\u0430\u043f\u0442\u0435\u0440\u00bb (adapter), \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u044b \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u043a LLM,<\/p>\n<\/li>\n<li>\n<p>\u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u00ab\u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0442\u043e\u0440\u00bb (optimizer), \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u043e\u0434\u0431\u0438\u0440\u0430\u0435\u0442 \u043b\u0443\u0447\u0448\u0438\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 \u0438 \u043b\u0443\u0447\u0448\u0438\u0435 few-shot-\u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043c\u043e\u0434\u0443\u043b\u044f, \u0447\u0442\u043e\u0431\u044b \u043c\u0430\u043a\u0441\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0437\u0430\u0434\u0430\u043d\u043d\u0443\u044e \u0438\u0442\u043e\u0433\u043e\u0432\u0443\u044e \u043c\u0435\u0442\u0440\u0438\u043a\u0443,<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u00ab\u0431\u0443\u0442\u0441\u0442\u0440\u0430\u043f\u00bb (bootstrap) \u2014 \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u0435 \u0434\u0435\u043c\u043e-\u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u0438\u0437 \u0443\u0441\u043f\u0435\u0448\u043d\u044b\u0445 \u043f\u0440\u043e\u0433\u043e\u043d\u0430 \u043c\u043e\u0434\u0435\u043b\u0438, \u0438 \u0442.\u0434.<\/p>\n<\/li>\n<\/ul>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/9b2\/c73\/2c4\/9b2c732c4969de64aa28e6e99f8b4091.png\" alt=\"\u0418\u043b\u043b\u044e\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0433\u043e \u043f\u043e\u0438\u0441\u043a\u0430 \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u043c\u043f\u0442\u0430\" title=\"\u0418\u043b\u043b\u044e\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0433\u043e \u043f\u043e\u0438\u0441\u043a\u0430 \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u043c\u043f\u0442\u0430\" width=\"792\" height=\"952\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/9b2\/c73\/2c4\/9b2c732c4969de64aa28e6e99f8b4091.png\"\/><\/p>\n<div><figcaption>\u0418\u043b\u043b\u044e\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0433\u043e \u043f\u043e\u0438\u0441\u043a\u0430 \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u043c\u043f\u0442\u0430<\/figcaption><\/div>\n<\/figure>\n<h4>\u041a\u0430\u043a \u043e\u0431\u044b\u0447\u043d\u043e \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0440\u0430\u0431\u043e\u0442\u0430 DSPy-\u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0442\u043e\u0440\u043e\u0432 (Pipeline)<\/h4>\n<p>\u0415\u0441\u043b\u0438 \u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c \u0438\u043c\u0435\u043d\u043d\u043e \u043e DSPy \u0438\u043b\u0438 \u0441\u0445\u043e\u0436\u0438\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430\u0445, \u0442\u0430\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043e\u0431\u044b\u0447\u043d\u043e \u0441\u0442\u0440\u043e\u0438\u0442\u0441\u044f \u0442\u0430\u043a:<\/p>\n<ol>\n<li>\n<p>Adapter \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u0440\u043e\u043c\u043f\u0442 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043c\u043e\u0434\u0443\u043b\u044f (\u0438\u0441\u0445\u043e\u0434\u044f \u0438\u0437 \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u044b \u0438 \u043f\u0440\u0435\u0434\u0438\u043a\u0442\u043e\u0440\u0430). \u042d\u0442\u043e \u0434\u0430\u0451\u0442 \u0431\u0430\u0437\u043e\u0432\u0443\u044e \u0432\u0435\u0440\u0441\u0438\u044e \u0441\u0438\u0441\u0442\u0435\u043c\u044b.<\/p>\n<\/li>\n<li>\n<p>\u041c\u044b \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u044b (\u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0447\u0435\u0440\u0435\u0437 rejection sampling) \u043d\u0430 \u0442\u0440\u0435\u043d\u0438\u0440\u043e\u0432\u043e\u0447\u043d\u043e\u043c \u043d\u0430\u0431\u043e\u0440\u0435: \u0433\u043e\u043d\u044f\u0435\u043c \u043f\u0430\u0439\u043f\u043b\u0430\u0439\u043d \u0438 \u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u0433\u0434\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u044f\u0435\u0442 \u043c\u0435\u0442\u0440\u0438\u043a\u0435. \u0422\u0430\u043a\u0438\u0435 \u0443\u0434\u0430\u0447\u043d\u044b\u0435 \u0442\u0440\u0430\u0435\u043a\u0442\u043e\u0440\u0438\u0438 \u043c\u043e\u0433\u0443\u0442 \u0441\u0442\u0430\u0442\u044c \u0434\u0435\u043c\u043e-\u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c\u0438 (\u0431\u0443\u0442\u0441\u0442\u0440\u0430\u043f).<\/p>\n<\/li>\n<li>\n<p>\u041e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0442\u043e\u0440 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442 \u043c\u0435\u043d\u044f\u0442\u044c \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 \u0438\u043b\u0438 \u043d\u0430\u0431\u043e\u0440 \u0434\u0435\u043c\u043e-\u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 (few-shot), \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f:<\/p>\n<ul>\n<li>\n<p>\u0410\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 few-shot (dspy.BootstrapFewShotWithRandomSearch),<\/p>\n<\/li>\n<li>\n<p>\u0418\u043d\u0434\u0443\u043a\u0446\u0438\u044e \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0439 (dspy.MIPROv2), OPRO, \u043b\u0438\u0431\u043e \u0434\u0440\u0443\u0433\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u044b.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u041d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u0448\u0430\u0433\u0435 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0442\u043e\u0440 \u043f\u0440\u043e\u0431\u0443\u0435\u0442 \u043d\u043e\u0432\u044b\u0435 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438, \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u043f\u0430\u0439\u043f\u043b\u0430\u0439\u043d \u043d\u0430 \u0447\u0430\u0441\u0442\u0438 \u0442\u0440\u0435\u043d\u0438\u0440\u043e\u0432\u043e\u0447\u043d\u043e\u0433\u043e \u043d\u0430\u0431\u043e\u0440\u0430, \u0438\u0437\u043c\u0435\u0440\u044f\u0435\u0442 \u043c\u0435\u0442\u0440\u0438\u043a\u0443. \u041f\u043e \u0438\u0442\u043e\u0433\u0430\u043c \u043e\u043d \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u0442 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u044e\u044e \u043b\u043e\u0433\u0438\u043a\u0443 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432 Bayesian TPE-\u0441\u0442\u0438\u043b\u0435 \u0438\u043b\u0438 \u0447\u0435\u0440\u0435\u0437 LLM, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u00ab\u0443\u0447\u0430\u0442\u0441\u044f\u00bb \u043d\u0430 \u0441\u0432\u043e\u0438\u0445 \u043e\u0448\u0438\u0431\u043a\u0430\u0445) \u0438, \u043d\u0430\u043a\u043e\u043d\u0435\u0446, \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u0442 \u043b\u0443\u0447\u0448\u0443\u044e \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e \u043f\u0440\u043e\u043c\u043f\u0442\u043e\u0432.<\/p>\n<\/li>\n<\/ol>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043e\u0434\u0438\u043d \u0438 \u0442\u043e\u0442 \u0436\u0435 \u043c\u043e\u0434\u0443\u043b\u044c (\u0441\u043a\u0430\u0436\u0435\u043c, \u00abGenerateSearchQuery\u00bb) \u043c\u043e\u0436\u0435\u0442 \u0438\u0442\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e \u0443\u043b\u0443\u0447\u0448\u0430\u0442\u044c\u0441\u044f:<\/p>\n<ul>\n<li>\n<p>\u0427\u0451\u0442\u0447\u0435 \u0444\u043e\u0440\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044e,<\/p>\n<\/li>\n<li>\n<p>\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u043b\u0443\u0447\u0448\u0438\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u044b,<\/p>\n<\/li>\n<li>\n<p>\u0418\u0441\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u00ab\u0432\u0440\u0435\u0434\u043d\u044b\u0435\u00bb \u0438\u043b\u0438 \u043d\u0435\u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0438\u0435 \u043a\u0443\u0441\u043a\u0438,<\/p>\n<\/li>\n<li>\n<p>\u0421\u043e\u0433\u043b\u0430\u0441\u043e\u0432\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u0441 \u0434\u0440\u0443\u0433\u0438\u043c \u043c\u043e\u0434\u0443\u043b\u0435\u043c \u00abAnswerWithContext\u00bb.<\/p>\n<\/li>\n<\/ul>\n<h4>\u041c\u0435\u0439\u043d\u0441\u0442\u0440\u0438\u043c-\u043f\u043e\u0434\u0445\u043e\u0434\u044b \u043a \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u0440\u043e\u043c\u043f\u0442\u043e\u0432<\/h4>\n<p>\u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u0440\u0430\u0437\u043d\u044b\u0435 \u0442\u0438\u043f\u044b \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0442\u043e\u0440\u043e\u0432, \u043e\u043f\u0438\u0440\u0430\u044e\u0449\u0438\u0435\u0441\u044f \u043d\u0430 \u0438\u0434\u0435\u0438 \u0438\u0437 \u0441\u0442\u0430\u0442\u044c\u0438 \u201cOptimizing Instructions and Demonstrations for Multi-Stage Language Model Programs\u201d (Khattab et al., 2024) \u0438 \u0441\u043c\u0435\u0436\u043d\u044b\u0445 \u0440\u0430\u0431\u043e\u0442:<\/p>\n<ol>\n<li>\n<p><strong>Bootstrap Random Search<\/strong><\/p>\n<ul>\n<li>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043c\u043e\u0434\u0435\u043b\u044c, \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u043c \u00ab\u0443\u0434\u0430\u0447\u043d\u044b\u0435\u00bb \u043f\u0440\u0438\u043c\u0435\u0440\u044b (input-output) \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0438\u0445 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043a\u0430\u043d\u0434\u0438\u0434\u0430\u0442\u043e\u0432 \u0434\u043b\u044f few-shot.<\/p>\n<\/li>\n<li>\n<p>\u041f\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0435 \u043d\u0430\u0431\u043e\u0440\u044b \u0434\u0435\u043c\u043e-\u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432, \u0432\u044b\u0431\u0438\u0440\u0430\u044f \u0442\u0435, \u0447\u0442\u043e \u0434\u0430\u044e\u0442 \u043b\u0443\u0447\u0448\u0438\u0439 score.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<ol start=\"2\">\n<li>\n<p><strong>Module-Level OPRO (History-based)<\/strong><\/p>\n<ul>\n<li>\n<p>\u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043c\u043e\u0434\u0443\u043b\u044f \u0432\u0435\u0434\u0451\u043c \u00ab\u0438\u0441\u0442\u043e\u0440\u0438\u044e\u00bb \u0438\u0437 [Instruction, Score].<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u043e\u0431\u0443\u0435\u043c \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438, \u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u0443\u044f\u0441\u044c \u043d\u0430 \u043f\u0440\u043e\u0448\u043b\u044b\u0435 \u043b\u0443\u0447\u0448\u0438\u0435.<\/p>\n<\/li>\n<li>\n<p>\u041d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043c\u0438\u043d\u0443\u0441: \u043d\u0435\u0442 \u043f\u0440\u044f\u043c\u043e\u0439 \u043e\u0446\u0435\u043d\u043a\u0438 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0448\u0430\u0433\u0430, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0445\u0443\u0436\u0435, \u0447\u0435\u043c \u043f\u0440\u0438 \u0441\u043e\u0433\u043b\u0430\u0441\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>MIPRO \/ Bayesian Surrogate<\/strong><\/p>\n<ul>\n<li>\n<p>\u0425\u0440\u0430\u043d\u0438\u043c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u043a\u0430\u043d\u0434\u0438\u0434\u0430\u0442\u043e\u0432 (\u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0439, \u0434\u0435\u043c\u043e-\u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432) \u0432 \u043d\u0435\u043a\u043e\u0435\u043c \u043f\u0443\u043b\u0435.<\/p>\n<\/li>\n<li>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0431\u0430\u0439\u0435\u0441\u043e\u0432\u0441\u043a\u0438\u0439 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0442\u043e\u0440 (TPE, Optuna), \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c: \u00ab\u0435\u0441\u043b\u0438 \u044f \u0432\u044b\u0431\u0435\u0440\u0443 \u0442\u0430\u043a\u0438\u0435-\u0442\u043e \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 \u0438 \u0434\u0435\u043c\u043e-\u043f\u0440\u0438\u043c\u0435\u0440\u044b, \u0441\u043a\u043e\u0440\u0435\u0435 \u0432\u0441\u0435\u0433\u043e \u0438\u0442\u043e\u0433\u043e\u0432\u0430\u044f \u043c\u0435\u0442\u0440\u0438\u043a\u0430 \u0431\u0443\u0434\u0435\u0442 \u0442\u0430\u043a\u043e\u0439-\u0442\u043e\u00bb.<\/p>\n<\/li>\n<li>\n<p>\u0412\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u043f\u0435\u0440\u0441\u043f\u0435\u043a\u0442\u0438\u0432\u043d\u044b\u0435 \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u0438, \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0438\u0445 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u043c \u0437\u0430\u043f\u0443\u0441\u043a\u043e\u043c.<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430\u043c \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u043c \u043d\u0430\u0448\u0443 \u043c\u043e\u0434\u0435\u043b\u044c \u0438 \u0434\u0432\u0438\u0436\u0435\u043c\u0441\u044f \u0434\u0430\u043b\u044c\u0448\u0435. \u041e\u0431\u044b\u0447\u043d\u043e \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0441\u0435\u0431\u044f \u043c\u043e\u0449\u043d\u043e, \u0442\u0430\u043a \u043a\u0430\u043a \u0438\u0449\u0435\u0442 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e \u043b\u0443\u0447\u0448\u0438\u0435 \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u0438.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>OPRO (Program-level \/ Module-level)<\/strong><\/p>\n<ul>\n<li>\n<p>\u041c\u043e\u0434\u0435\u043b\u044c \u0441\u0430\u043c\u0430 \u00ab\u0443\u0447\u0438\u0442\u0441\u044f\u00bb \u043d\u0430 \u0438\u0441\u0442\u043e\u0440\u0438\u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432: \u0432\u0438\u0434\u0438\u0442 \u0441\u043f\u0438\u0441\u043e\u043a \u00ab[instr, score], [instr, score], &#8230;\u00bb \u0438 \u043f\u044b\u0442\u0430\u0435\u0442\u0441\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043d\u043e\u0432\u0443\u044e \u043b\u0443\u0447\u0448\u0443\u044e \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044e.<\/p>\n<\/li>\n<li>\n<p>\u0421\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c: \u0435\u0441\u043b\u0438 \u043f\u0430\u0439\u043f\u043b\u0430\u0439\u043d \u0438\u0437 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043c\u043e\u0434\u0443\u043b\u0435\u0439, \u043d\u0443\u0436\u043d\u043e \u0430\u043a\u043a\u0443\u0440\u0430\u0442\u043d\u043e \u0440\u0435\u0448\u0430\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0443 \u00abcredit assignment\u00bb (\u043a\u0430\u043a\u043e\u0439 \u0438\u0437 \u0448\u0430\u0433\u043e\u0432 \u0432\u0438\u043d\u043e\u0432\u0430\u0442 \u0432 \u043f\u0440\u043e\u0432\u0430\u043b\u0435?).<\/p>\n<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<h3>\u041f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0437\u0430\u0434\u0430\u043d\u0438\u0435<\/h3>\n<p><strong>\u0417\u0430\u0434\u0430\u0447\u0430<\/strong>: \u0420\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c (\u0438\u043b\u0438 \u043f\u0440\u043e\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0441\u0435\u0432\u0434\u043e\u043a\u043e\u0434) \u043c\u043d\u043e\u0433\u043e\u0448\u0430\u0433\u043e\u0432\u0443\u044e \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u00ab\u0412\u043e\u043f\u0440\u043e\u0441\u2013\u041e\u0442\u0432\u0435\u0442\u00bb (multi-hop QA) + \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044e \u043f\u0440\u043e\u043c\u043f\u0442\u043e\u0432 \u0434\u043b\u044f \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u044f \u0438\u0442\u043e\u0433\u043e\u0432\u043e\u0439 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438.<\/p>\n<ol>\n<li>\n<p><strong>\u0421\u0438\u0441\u0442\u0435\u043c\u0430:<\/strong><\/p>\n<ul>\n<li>\n<p>\u041c\u043e\u0434\u0443\u043b\u044c GenerateSearchQuery: \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 (question, context) \u0438 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 search_query.<\/p>\n<\/li>\n<li>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u043e\u0438\u0441\u043a\u0430: \u0438\u043c\u0438\u0442\u0438\u0440\u0443\u0435\u0442 \u043f\u043e\u0438\u0441\u043a, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0440\u0435\u043b\u0435\u0432\u0430\u043d\u0442\u043d\u044b\u0435 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b.<\/p>\n<\/li>\n<li>\n<p>\u041c\u043e\u0434\u0443\u043b\u044c AnswerWithContext: \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u0442 \u0432\u0441\u0451 \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u043e\u0435 \u0438 \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u0442 \u0444\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u041c\u0435\u0442\u0440\u0438\u043a\u0430:<\/strong><\/p>\n<ul>\n<li>\n<p>\u041f\u0443\u0441\u0442\u044c \u044d\u0442\u043e Exact Match \u0441 \u044d\u0442\u0430\u043b\u043e\u043d\u043d\u044b\u043c \u043e\u0442\u0432\u0435\u0442\u043e\u043c (\u0438\u043b\u0438 \u043b\u044e\u0431\u0430\u044f \u0441\u0432\u043e\u044f).<\/p>\n<\/li>\n<li>\n<p>\u0418\u043c\u0435\u0435\u043c \u0442\u0440\u0435\u043d\u0438\u0440\u043e\u0432\u043e\u0447\u043d\u044b\u0439 \u043d\u0430\u0431\u043e\u0440 \u0438\u0437 (\u0432\u043e\u043f\u0440\u043e\u0441, \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442).<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u041e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f:<\/strong><\/p>\n<ul>\n<li>\n<p>\u0412\u043e\u0437\u044c\u043c\u0451\u043c, \u043a \u043f\u0440\u0438\u043c\u0435\u0440\u0443, MIPRO \u0438\u043b\u0438 Bootstrap Random Search.<\/p>\n<\/li>\n<li>\n<p>\u0421\u043e\u0431\u0435\u0440\u0451\u043c \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u0434\u0435\u043c\u043e-\u043f\u0440\u0438\u043c\u0435\u0440\u044b (bootstrapping) \u0438\u043b\u0438 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043d\u0430 \u0433\u043e\u043b\u044b\u0445 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f\u0445.<\/p>\n<\/li>\n<li>\n<p>\u0418\u0442\u0435\u0440\u0438\u0440\u0443\u0435\u043c, \u043f\u043e\u043a\u0430 \u043d\u0435 \u043d\u0430\u0439\u0434\u0451\u043c \u0445\u043e\u0440\u043e\u0448\u0438\u0439 \u043d\u0430\u0431\u043e\u0440 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0439 + few-shot \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u041f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c<\/strong>\u00a0\u043d\u0430 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u043c \u043d\u0430\u0431\u043e\u0440\u0435, \u0441\u0440\u0430\u0432\u043d\u0438\u0442\u044c \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u043e \u0434\u043e \u0438 \u043f\u043e\u0441\u043b\u0435.<\/p>\n<\/li>\n<\/ol>\n<h3>\u0420\u0435\u0448\u0435\u043d\u0438\u0435<\/h3>\n<p>\u041d\u0438\u0436\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0451\u043d \u0443\u043f\u0440\u043e\u0449\u0451\u043d\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440. \u041e\u043d \u0438\u043b\u043b\u044e\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442, \u043a\u0430\u043a \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043e\u043f\u0438\u0441\u0430\u0442\u044c \u043c\u043e\u0434\u0443\u043b\u0438 (\u0447\u0435\u0440\u0435\u0437 \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u044b) \u0438 \u043a\u0430\u043a \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c DSPy-\u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044e (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e MIPRO). \u0414\u043b\u044f \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0433\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u043d\u0443\u0436\u043d\u043e \u0435\u0449\u0435 \u0441\u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u044f\u0437\u044b\u043a\u043e\u0432\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c.<\/p>\n<pre><code class=\"python\">import dspy lm = dspy.LM(model='ollama\/deepseek-r1:70b', api_base='http:\/\/localhost:11434') dspy.configure(lm=lm)<\/code><\/pre>\n<pre><code class=\"python\">import dspy  ############################################# # 1. Define Signatures for the Submodules   # #############################################  class GenerateSearchQuery(dspy.Signature):     context: str = dspy.InputField()     question: str = dspy.InputField()     search_query: str = dspy.OutputField()  class AnswerWithContext(dspy.Signature):     context: str = dspy.InputField()     question: str = dspy.InputField()     answer: str = dspy.OutputField()  ############################################# # 2. Define the MultiHopQA Module           # #############################################  class MultiHopQA(dspy.Module):     \"\"\"     \u041c\u043e\u0434\u0443\u043b\u044c\u043d\u0430\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u0430, \u0441\u043e\u0441\u0442\u043e\u044f\u0449\u0430\u044f \u0438\u0437 \u0434\u0432\u0443\u0445 \u043f\u043e\u0434\u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432:     1) \u0413\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u043f\u043e\u0438\u0441\u043a\u043e\u0432\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430,     2) \u0413\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u0438\u0442\u043e\u0433\u043e\u0432\u043e\u0433\u043e \u043e\u0442\u0432\u0435\u0442\u0430.     \"\"\"     def __init__(self, max_iterations=2):         super().__init__()         self.query_gen = dspy.ChainOfThought(GenerateSearchQuery)         self.answer_gen = dspy.ChainOfThought(AnswerWithContext)         self.max_iterations = max_iterations      def forward(self, question: str) -&gt; str:         context_collected = \"\"         for _ in range(self.max_iterations):             # 1) \u0413\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c \u043f\u043e\u0438\u0441\u043a\u043e\u0432\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441             out_query = self.query_gen(                 context=context_collected,                 question=question             )             search_query = out_query[\"search_query\"]              # 2) \u0418\u043c\u0438\u0442\u0438\u0440\u0443\u0435\u043c \u043f\u043e\u0438\u0441\u043a (\u0438\u043b\u0438 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u043a \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u043c\u0443 \u043f\u043e\u0438\u0441\u043a\u043e\u0432\u043e\u043c\u0443 \u0434\u0432\u0438\u0436\u043a\u0443)             retrieved_docs = f\"Docs_for_{search_query}\"              # 3) \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u043e\u0435 \u0432 \u043e\u0431\u0449\u0438\u0439 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442             context_collected += f\"\\n{retrieved_docs}\"          # 4) \u0413\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c \u0444\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442         out_ans = self.answer_gen(             context=context_collected,             question=question         )         final_answer = out_ans[\"answer\"]         return final_answer  ############################################# # 3. Prepare Data and Metric (Exact Match)  # #############################################  train_data = [     dspy.Example(inputs=\"\u041a\u0442\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u0440\u043e\u043c\u0430\u043d '\u041c\u0430\u0441\u0442\u0435\u0440 \u0438 \u041c\u0430\u0440\u0433\u0430\u0440\u0438\u0442\u0430'?\", reference=\"\u041c\u0438\u0445\u0430\u0438\u043b \u0411\u0443\u043b\u0433\u0430\u043a\u043e\u0432\"),     dspy.Example(inputs=\"\u041a\u0430\u043a\u043e\u0435 \u0443\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u043e\u0442\u043a\u0440\u044b\u043b \u0444\u0440\u0430\u043d\u0446\u0443\u0437\u0441\u043a\u0438\u0439 \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u043a \u0416\u043e\u0437\u0435\u0444 \u041b\u0438\u0443\u0432\u0438\u043b\u043b\u044c?\", reference=\"\u0423\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u041b\u0438\u0443\u0432\u0438\u043b\u043b\u044f (Liouville's equation)\")     # ... add more examples as needed ]  def exact_match(prediction: str, reference: str) -&gt; float:     pred = prediction.strip().lower()     ref = reference.strip().lower()     return 1.0 if ref in pred else 0.0  def my_metric_fn(outputs, references) -&gt; float:     scores = []     for pred, ref in zip(outputs, references):         scores.append(exact_match(pred, ref))     return sum(scores) \/ len(scores)  ############################################# # 4. Run the Optimizer (using MIPROv2)       # #############################################  pipeline = MultiHopQA(max_iterations=2)  # \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 def data_loader_fn():     return train_data  # Supply the required metric during instantiation. optimizer = dspy.MIPROv2(metric=my_metric_fn)  # Use the compile method instead of optimize; pass the trainset directly. trainset = data_loader_fn() best_pipeline = optimizer.compile(pipeline, trainset=trainset, minibatch_size=1)  ############################################# # 5. Test the Final System                 # #############################################  test_questions = [     \"\u041a\u0442\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u0440\u043e\u043c\u0430\u043d '\u041c\u0430\u0441\u0442\u0435\u0440 \u0438 \u041c\u0430\u0440\u0433\u0430\u0440\u0438\u0442\u0430'?\",     \"\u041a\u0430\u043a\u043e\u0432\u043e \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0435 \u0443\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u041b\u0438\u0443\u0432\u0438\u043b\u043b\u044f?\" ]  for q in test_questions:     ans = best_pipeline(q)     print(f\"\u0412\u043e\u043f\u0440\u043e\u0441: {q}\\n\u041e\u0442\u0432\u0435\u0442: {ans}\\n---\")<\/code><\/pre>\n<p>\u042d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u043c\u043e\u0434\u0443\u043b\u044c\u043d\u0443\u044e \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u0434\u043b\u044f \u043e\u0442\u0432\u0435\u0442\u0430 \u043d\u0430 \u0432\u043e\u043f\u0440\u043e\u0441\u044b:<\/p>\n<ul>\n<li>\n<p><strong>\u0414\u0432\u0430 \u0448\u0430\u0433\u0430:<\/strong><\/p>\n<ol>\n<li>\n<p>\u0413\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043f\u043e\u0438\u0441\u043a\u043e\u0432\u043e\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0432\u043e\u043f\u0440\u043e\u0441\u0430 \u0438 \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430.<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0438\u043c\u0438\u0442\u0430\u0446\u0438\u0438 \u043f\u043e\u0438\u0441\u043a\u0430 \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043a \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0443, \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043e\u043a\u043e\u043d\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442.<\/p>\n<\/li>\n<\/ol>\n<\/li>\n<li>\n<p><strong>\u041e\u0431\u0443\u0447\u0435\u043d\u0438\u0435:<\/strong><br \/>\u0421\u0438\u0441\u0442\u0435\u043c\u0430 \u043e\u0431\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0442\u043e\u0440\u0430 dspy.MIPROv2 \u0438 \u043c\u0435\u0442\u0440\u0438\u043a\u0438 \u0442\u043e\u0447\u043d\u043e\u0433\u043e \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u044f \u043d\u0430 \u0442\u0440\u0435\u043d\u0438\u0440\u043e\u0432\u043e\u0447\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<\/li>\n<li>\n<p><strong>\u0422\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435:<\/strong><br \/>\u041f\u043e\u0441\u043b\u0435 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u043d\u0430 \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0435 \u0432\u043e\u043f\u0440\u043e\u0441\u044b, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043d\u0430\u043a\u043e\u043f\u043b\u0435\u043d\u043d\u044b\u0439 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442.<\/p>\n<\/li>\n<\/ul>\n<p>\u041a\u043e\u043c\u0443 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u043d\u043e \u043f\u043e\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043d\u0430\u0434 \u043a\u0443\u0440\u0441\u043e\u043c \u043f\u043e \u0418\u043d\u0442\u0435\u043b\u043b\u0435\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u043c \u0410\u0433\u0435\u043d\u0442\u0430\u043c &#8212; \u043f\u0438\u0448\u0438\u0442\u0435 \u0432 \u043b\u0438\u0447\u043a\u0443.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \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\/882864\/\"> https:\/\/habr.com\/ru\/articles\/882864\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0426\u0435\u043b\u044c \u2014 \u043d\u0430\u0443\u0447\u0438\u0442\u044c\u0441\u044f \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043c\u043e\u0434\u0443\u043b\u044c\u043d\u044b\u0435 (multi-stage) \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u043d\u0430 \u0431\u0430\u0437\u0435 LLM, \u0430 \u0437\u0430\u0442\u0435\u043c \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u043c\u043f\u0442\u044b (\u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 \u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u044b) \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u0438\u0442\u043e\u0433\u043e\u0432\u0430\u044f \u043c\u0435\u0442\u0440\u0438\u043a\u0430 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0430 (accuracy, retrieval score \u0438 \u0442.\u043f.) \u043f\u0440\u0435\u0432\u044b\u0448\u0430\u043b\u0430 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0441 \u0440\u0443\u0447\u043d\u044b\u043c \u043f\u043e\u0434\u0431\u043e\u0440\u043e\u043c \u0442\u0435\u043a\u0441\u0442\u0430 \u043f\u0440\u043e\u043c\u043f\u0442\u0430.<\/p>\n<h4>\u041f\u043e\u0447\u0435\u043c\u0443 \u043d\u0443\u0436\u043d\u044b \u043c\u043d\u043e\u0433\u043e\u0448\u0430\u0433\u043e\u0432\u044b\u0435 LM-\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0438 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u0440\u043e\u043c\u043f\u0442\u0430<\/h4>\n<p>\u0421\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0431\u043e\u043b\u044c\u0448\u0438\u0435 \u044f\u0437\u044b\u043a\u043e\u0432\u044b\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 (LLM) \u2014 \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, GPT, Llama \u0438 \u043f\u0440. \u2014 \u043e\u0442\u043b\u0438\u0447\u043d\u043e \u0441\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0441 \u0437\u0430\u0434\u0430\u0447\u0430\u043c\u0438 \u043d\u0430 \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0438 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044e \u0442\u0435\u043a\u0441\u0442\u0430, <a href=\"https:\/\/blog.ivan.digital\/toward-software-engineer-llm-agent-emergent-abilities-and-reinforcement-learning-survey-ed32911f5145\" rel=\"noopener noreferrer nofollow\">\u044f \u043f\u0438\u0441\u0430\u043b \u0431\u043e\u043b\u0435\u0435 \u0434\u0435\u0442\u0430\u043b\u044c\u043d\u043e \u043f\u0440\u043e \u0434\u0443\u043c\u0430\u044e\u0449\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u0442\u0438\u043f\u0430 o1 \u0438\u043b\u0438 DeepSeek R1 \u0442\u0443\u0442,<\/a> \u043e\u0434\u043d\u0430\u043a\u043e:<\/p>\n<ol>\n<li>\n<p>\u0427\u0430\u0441\u0442\u043e \u00ab\u0433\u0430\u043b\u043b\u044e\u0446\u0438\u043d\u0438\u0440\u0443\u044e\u0442\u00bb (\u0432\u044b\u0434\u0443\u043c\u044b\u0432\u0430\u044e\u0442 \u0434\u0435\u0442\u0430\u043b\u0438),<\/p>\n<\/li>\n<li>\n<p>\u0422\u0440\u0443\u0434\u043d\u043e \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u0434\u043b\u044f \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u0441\u043b\u043e\u0436\u043d\u043e\u0433\u043e \u043f\u0430\u0439\u043f\u043b\u0430\u0439\u043d\u0430 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u043e\u0433\u0434\u0430 \u0437\u0430\u0434\u0430\u0447\u0430 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0448\u0430\u0433\u043e\u0432 \u043f\u043e\u0438\u0441\u043a\u0430, \u0441\u0432\u043e\u0434\u043a\u0438, \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438).<\/p>\n<\/li>\n<\/ol>\n<p>\u0412\u043e \u043c\u043d\u043e\u0433\u0438\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u043f\u043e\u0434\u0445\u043e\u0434 \u00ab\u043e\u0434\u0438\u043d \u0437\u0430\u043f\u0440\u043e\u0441 \u2013 \u043e\u0434\u0438\u043d \u043e\u0442\u0432\u0435\u0442\u00bb \u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u044b\u043c. \u0412\u043c\u0435\u0441\u0442\u043e \u044d\u0442\u043e\u0433\u043e \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u043c\u044b \u0441\u0442\u0440\u043e\u0438\u043c \u043c\u043d\u043e\u0433\u043e\u0441\u0442\u0443\u043f\u0435\u043d\u0447\u0430\u0442\u044b\u0435 \u043f\u0430\u0439\u043f\u043b\u0430\u0439\u043d\u044b (compound AI systems), \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043a\u0430\u0436\u0434\u044b\u0439 \u0448\u0430\u0433 \u0440\u0435\u0448\u0430\u0435\u0442 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u0443\u044e \u043f\u043e\u0434\u0437\u0430\u0434\u0430\u0447\u0443:<\/p>\n<ul>\n<li>\n<p>\u0421\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0438\u0441\u043a\u043e\u0432\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441,<\/p>\n<\/li>\n<li>\n<p>\u041d\u0430\u0439\u0442\u0438 \u0438\u043b\u0438 \u0438\u0437\u0432\u043b\u0435\u0447\u044c \u0440\u0435\u043b\u0435\u0432\u0430\u043d\u0442\u043d\u044b\u0435 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b,<\/p>\n<\/li>\n<li>\n<p>\u0421\u0432\u0435\u0441\u0442\u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b,<\/p>\n<\/li>\n<li>\n<p>\u0421\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0444\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442.<\/p>\n<\/li>\n<\/ul>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u043f\u043e\u0434\u043e\u0431\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u043c\u044b \u0432\u043d\u0435\u0437\u0430\u043f\u043d\u043e \u0441\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u0435\u043c\u0441\u044f \u0441 \u0437\u0430\u0434\u0430\u0447\u0435\u0439:<\/p>\n<ul>\n<li>\n<p><strong>\u041a\u0430\u043a \u0444\u043e\u0440\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u043c\u043f\u0442\u044b \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0448\u0430\u0433\u0430?<\/strong><\/p>\n<\/li>\n<li>\n<p><strong>\u041a\u0430\u043a \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e \u0443\u043b\u0443\u0447\u0448\u0430\u0442\u044c (\u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c) \u044d\u0442\u0438 \u043f\u0440\u043e\u043c\u043f\u0442\u044b, \u043d\u0435 \u0438\u043c\u0435\u044f \u0438\u043d\u0434\u0438\u0432\u0438\u0434\u0443\u0430\u043b\u044c\u043d\u043e\u0439 \u043c\u0435\u0442\u0440\u0438\u043a\u0438 \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u0448\u0430\u0433\u0435 (\u0442\u043e\u043b\u044c\u043a\u043e \u0438\u0442\u043e\u0433\u043e\u0432\u0430\u044f \u043c\u0435\u0442\u0440\u0438\u043a\u0430)?<\/strong><\/p>\n<\/li>\n<\/ul>\n<p>\u0422\u0443\u0442 \u043d\u0430 \u043f\u043e\u043c\u043e\u0449\u044c \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a<strong> <\/strong><a href=\"https:\/\/github.com\/stanfordnlp\/dspy\" rel=\"noopener noreferrer nofollow\"><strong>DSPy (Declarative Self-improving Python)<\/strong>,<\/a> \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e\u0449\u0438\u0439:<\/p>\n<ul>\n<li>\n<p>\u041e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u043a\u0430\u0436\u0434\u044b\u0439 \u044d\u0442\u0430\u043f \u0432 \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u0445 \u00ab\u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u00bb (signature) \u2014 \u0447\u0442\u043e \u043c\u043e\u0434\u0443\u043b\u044c \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043d\u0430 \u0432\u0445\u043e\u0434, \u0447\u0442\u043e \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u0435\u0440\u043d\u0443\u0442\u044c, \u043a\u0430\u043a\u043e\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438,<\/p>\n<\/li>\n<li>\n<p>\u0417\u0430\u0434\u0430\u0432\u0430\u0442\u044c \u00ab\u0430\u0434\u0430\u043f\u0442\u0435\u0440\u00bb (adapter), \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u044b \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u043a LLM,<\/p>\n<\/li>\n<li>\n<p>\u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u00ab\u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0442\u043e\u0440\u00bb (optimizer), \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u043e\u0434\u0431\u0438\u0440\u0430\u0435\u0442 \u043b\u0443\u0447\u0448\u0438\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 \u0438 \u043b\u0443\u0447\u0448\u0438\u0435 few-shot-\u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043c\u043e\u0434\u0443\u043b\u044f, \u0447\u0442\u043e\u0431\u044b \u043c\u0430\u043a\u0441\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0437\u0430\u0434\u0430\u043d\u043d\u0443\u044e \u0438\u0442\u043e\u0433\u043e\u0432\u0443\u044e \u043c\u0435\u0442\u0440\u0438\u043a\u0443,<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u00ab\u0431\u0443\u0442\u0441\u0442\u0440\u0430\u043f\u00bb (bootstrap) \u2014 \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u0435 \u0434\u0435\u043c\u043e-\u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u0438\u0437 \u0443\u0441\u043f\u0435\u0448\u043d\u044b\u0445 \u043f\u0440\u043e\u0433\u043e\u043d\u0430 \u043c\u043e\u0434\u0435\u043b\u0438, \u0438 \u0442.\u0434.<\/p>\n<\/li>\n<\/ul>\n<figure class=\"full-width\">\n<div><figcaption>\u0418\u043b\u043b\u044e\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0433\u043e \u043f\u043e\u0438\u0441\u043a\u0430 \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u043c\u043f\u0442\u0430<\/figcaption><\/div>\n<\/figure>\n<h4>\u041a\u0430\u043a \u043e\u0431\u044b\u0447\u043d\u043e \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0440\u0430\u0431\u043e\u0442\u0430 DSPy-\u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0442\u043e\u0440\u043e\u0432 (Pipeline)<\/h4>\n<p>\u0415\u0441\u043b\u0438 \u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c \u0438\u043c\u0435\u043d\u043d\u043e \u043e DSPy \u0438\u043b\u0438 \u0441\u0445\u043e\u0436\u0438\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430\u0445, \u0442\u0430\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043e\u0431\u044b\u0447\u043d\u043e \u0441\u0442\u0440\u043e\u0438\u0442\u0441\u044f \u0442\u0430\u043a:<\/p>\n<ol>\n<li>\n<p>Adapter \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u0440\u043e\u043c\u043f\u0442 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043c\u043e\u0434\u0443\u043b\u044f (\u0438\u0441\u0445\u043e\u0434\u044f \u0438\u0437 \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u044b \u0438 \u043f\u0440\u0435\u0434\u0438\u043a\u0442\u043e\u0440\u0430). \u042d\u0442\u043e \u0434\u0430\u0451\u0442 \u0431\u0430\u0437\u043e\u0432\u0443\u044e \u0432\u0435\u0440\u0441\u0438\u044e \u0441\u0438\u0441\u0442\u0435\u043c\u044b.<\/p>\n<\/li>\n<li>\n<p>\u041c\u044b \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u044b (\u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0447\u0435\u0440\u0435\u0437 rejection sampling) \u043d\u0430 \u0442\u0440\u0435\u043d\u0438\u0440\u043e\u0432\u043e\u0447\u043d\u043e\u043c \u043d\u0430\u0431\u043e\u0440\u0435: \u0433\u043e\u043d\u044f\u0435\u043c \u043f\u0430\u0439\u043f\u043b\u0430\u0439\u043d \u0438 \u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u0433\u0434\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u044f\u0435\u0442 \u043c\u0435\u0442\u0440\u0438\u043a\u0435. \u0422\u0430\u043a\u0438\u0435 \u0443\u0434\u0430\u0447\u043d\u044b\u0435 \u0442\u0440\u0430\u0435\u043a\u0442\u043e\u0440\u0438\u0438 \u043c\u043e\u0433\u0443\u0442 \u0441\u0442\u0430\u0442\u044c \u0434\u0435\u043c\u043e-\u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c\u0438 (\u0431\u0443\u0442\u0441\u0442\u0440\u0430\u043f).<\/p>\n<\/li>\n<li>\n<p>\u041e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0442\u043e\u0440 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442 \u043c\u0435\u043d\u044f\u0442\u044c \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 \u0438\u043b\u0438 \u043d\u0430\u0431\u043e\u0440 \u0434\u0435\u043c\u043e-\u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 (few-shot), \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f:<\/p>\n<ul>\n<li>\n<p>\u0410\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 few-shot (dspy.BootstrapFewShotWithRandomSearch),<\/p>\n<\/li>\n<li>\n<p>\u0418\u043d\u0434\u0443\u043a\u0446\u0438\u044e \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0439 (dspy.MIPROv2), OPRO, \u043b\u0438\u0431\u043e \u0434\u0440\u0443\u0433\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u044b.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u041d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u0448\u0430\u0433\u0435 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0442\u043e\u0440 \u043f\u0440\u043e\u0431\u0443\u0435\u0442 \u043d\u043e\u0432\u044b\u0435 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438, \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u043f\u0430\u0439\u043f\u043b\u0430\u0439\u043d \u043d\u0430 \u0447\u0430\u0441\u0442\u0438 \u0442\u0440\u0435\u043d\u0438\u0440\u043e\u0432\u043e\u0447\u043d\u043e\u0433\u043e \u043d\u0430\u0431\u043e\u0440\u0430, \u0438\u0437\u043c\u0435\u0440\u044f\u0435\u0442 \u043c\u0435\u0442\u0440\u0438\u043a\u0443. \u041f\u043e \u0438\u0442\u043e\u0433\u0430\u043c \u043e\u043d \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u0442 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u044e\u044e \u043b\u043e\u0433\u0438\u043a\u0443 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432 Bayesian TPE-\u0441\u0442\u0438\u043b\u0435 \u0438\u043b\u0438 \u0447\u0435\u0440\u0435\u0437 LLM, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u00ab\u0443\u0447\u0430\u0442\u0441\u044f\u00bb \u043d\u0430 \u0441\u0432\u043e\u0438\u0445 \u043e\u0448\u0438\u0431\u043a\u0430\u0445) \u0438, \u043d\u0430\u043a\u043e\u043d\u0435\u0446, \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u0442 \u043b\u0443\u0447\u0448\u0443\u044e \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e \u043f\u0440\u043e\u043c\u043f\u0442\u043e\u0432.<\/p>\n<\/li>\n<\/ol>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043e\u0434\u0438\u043d \u0438 \u0442\u043e\u0442 \u0436\u0435 \u043c\u043e\u0434\u0443\u043b\u044c (\u0441\u043a\u0430\u0436\u0435\u043c, \u00abGenerateSearchQuery\u00bb) \u043c\u043e\u0436\u0435\u0442 \u0438\u0442\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e \u0443\u043b\u0443\u0447\u0448\u0430\u0442\u044c\u0441\u044f:<\/p>\n<ul>\n<li>\n<p>\u0427\u0451\u0442\u0447\u0435 \u0444\u043e\u0440\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044e,<\/p>\n<\/li>\n<li>\n<p>\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u043b\u0443\u0447\u0448\u0438\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u044b,<\/p>\n<\/li>\n<li>\n<p>\u0418\u0441\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u00ab\u0432\u0440\u0435\u0434\u043d\u044b\u0435\u00bb \u0438\u043b\u0438 \u043d\u0435\u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0438\u0435 \u043a\u0443\u0441\u043a\u0438,<\/p>\n<\/li>\n<li>\n<p>\u0421\u043e\u0433\u043b\u0430\u0441\u043e\u0432\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u0441 \u0434\u0440\u0443\u0433\u0438\u043c \u043c\u043e\u0434\u0443\u043b\u0435\u043c \u00abAnswerWithContext\u00bb.<\/p>\n<\/li>\n<\/ul>\n<h4>\u041c\u0435\u0439\u043d\u0441\u0442\u0440\u0438\u043c-\u043f\u043e\u0434\u0445\u043e\u0434\u044b \u043a \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u0440\u043e\u043c\u043f\u0442\u043e\u0432<\/h4>\n<p>\u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u0440\u0430\u0437\u043d\u044b\u0435 \u0442\u0438\u043f\u044b \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0442\u043e\u0440\u043e\u0432, \u043e\u043f\u0438\u0440\u0430\u044e\u0449\u0438\u0435\u0441\u044f \u043d\u0430 \u0438\u0434\u0435\u0438 \u0438\u0437 \u0441\u0442\u0430\u0442\u044c\u0438 \u201cOptimizing Instructions and Demonstrations for Multi-Stage Language Model Programs\u201d (Khattab et al., 2024) \u0438 \u0441\u043c\u0435\u0436\u043d\u044b\u0445 \u0440\u0430\u0431\u043e\u0442:<\/p>\n<ol>\n<li>\n<p><strong>Bootstrap Random Search<\/strong><\/p>\n<ul>\n<li>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043c\u043e\u0434\u0435\u043b\u044c, \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u043c \u00ab\u0443\u0434\u0430\u0447\u043d\u044b\u0435\u00bb \u043f\u0440\u0438\u043c\u0435\u0440\u044b (input-output) \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0438\u0445 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043a\u0430\u043d\u0434\u0438\u0434\u0430\u0442\u043e\u0432 \u0434\u043b\u044f few-shot.<\/p>\n<\/li>\n<li>\n<p>\u041f\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0435 \u043d\u0430\u0431\u043e\u0440\u044b \u0434\u0435\u043c\u043e-\u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432, \u0432\u044b\u0431\u0438\u0440\u0430\u044f \u0442\u0435, \u0447\u0442\u043e \u0434\u0430\u044e\u0442 \u043b\u0443\u0447\u0448\u0438\u0439 score.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<ol start=\"2\">\n<li>\n<p><strong>Module-Level OPRO (History-based)<\/strong><\/p>\n<ul>\n<li>\n<p>\u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043c\u043e\u0434\u0443\u043b\u044f \u0432\u0435\u0434\u0451\u043c \u00ab\u0438\u0441\u0442\u043e\u0440\u0438\u044e\u00bb \u0438\u0437 [Instruction, Score].<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u043e\u0431\u0443\u0435\u043c \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438, \u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u0443\u044f\u0441\u044c \u043d\u0430 \u043f\u0440\u043e\u0448\u043b\u044b\u0435 \u043b\u0443\u0447\u0448\u0438\u0435.<\/p>\n<\/li>\n<li>\n<p>\u041d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043c\u0438\u043d\u0443\u0441: \u043d\u0435\u0442 \u043f\u0440\u044f\u043c\u043e\u0439 \u043e\u0446\u0435\u043d\u043a\u0438 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0448\u0430\u0433\u0430, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0445\u0443\u0436\u0435, \u0447\u0435\u043c \u043f\u0440\u0438 \u0441\u043e\u0433\u043b\u0430\u0441\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>MIPRO \/ Bayesian Surrogate<\/strong><\/p>\n<ul>\n<li>\n<p>\u0425\u0440\u0430\u043d\u0438\u043c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u043a\u0430\u043d\u0434\u0438\u0434\u0430\u0442\u043e\u0432 (\u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0439, \u0434\u0435\u043c\u043e-\u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432) \u0432 \u043d\u0435\u043a\u043e\u0435\u043c \u043f\u0443\u043b\u0435.<\/p>\n<\/li>\n<li>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0431\u0430\u0439\u0435\u0441\u043e\u0432\u0441\u043a\u0438\u0439 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0442\u043e\u0440 (TPE, Optuna), \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c: \u00ab\u0435\u0441\u043b\u0438 \u044f \u0432\u044b\u0431\u0435\u0440\u0443 \u0442\u0430\u043a\u0438\u0435-\u0442\u043e \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 \u0438 \u0434\u0435\u043c\u043e-\u043f\u0440\u0438\u043c\u0435\u0440\u044b, \u0441\u043a\u043e\u0440\u0435\u0435 \u0432\u0441\u0435\u0433\u043e \u0438\u0442\u043e\u0433\u043e\u0432\u0430\u044f \u043c\u0435\u0442\u0440\u0438\u043a\u0430 \u0431\u0443\u0434\u0435\u0442 \u0442\u0430\u043a\u043e\u0439-\u0442\u043e\u00bb.<\/p>\n<\/li>\n<li>\n<p>\u0412\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u043f\u0435\u0440\u0441\u043f\u0435\u043a\u0442\u0438\u0432\u043d\u044b\u0435 \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u0438, \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0438\u0445 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u043c \u0437\u0430\u043f\u0443\u0441\u043a\u043e\u043c.<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430\u043c \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u043c \u043d\u0430\u0448\u0443 \u043c\u043e\u0434\u0435\u043b\u044c \u0438 \u0434\u0432\u0438\u0436\u0435\u043c\u0441\u044f \u0434\u0430\u043b\u044c\u0448\u0435. \u041e\u0431\u044b\u0447\u043d\u043e \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0441\u0435\u0431\u044f \u043c\u043e\u0449\u043d\u043e, \u0442\u0430\u043a \u043a\u0430\u043a \u0438\u0449\u0435\u0442 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e \u043b\u0443\u0447\u0448\u0438\u0435 \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u0438.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>OPRO (Program-level \/ Module-level)<\/strong><\/p>\n<ul>\n<li>\n<p>\u041c\u043e\u0434\u0435\u043b\u044c \u0441\u0430\u043c\u0430 \u00ab\u0443\u0447\u0438\u0442\u0441\u044f\u00bb \u043d\u0430 \u0438\u0441\u0442\u043e\u0440\u0438\u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432: \u0432\u0438\u0434\u0438\u0442 \u0441\u043f\u0438\u0441\u043e\u043a \u00ab[instr, score], [instr, score], &#8230;\u00bb \u0438 \u043f\u044b\u0442\u0430\u0435\u0442\u0441\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043d\u043e\u0432\u0443\u044e \u043b\u0443\u0447\u0448\u0443\u044e \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044e.<\/p>\n<\/li>\n<li>\n<p>\u0421\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c: \u0435\u0441\u043b\u0438 \u043f\u0430\u0439\u043f\u043b\u0430\u0439\u043d \u0438\u0437 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043c\u043e\u0434\u0443\u043b\u0435\u0439, \u043d\u0443\u0436\u043d\u043e \u0430\u043a\u043a\u0443\u0440\u0430\u0442\u043d\u043e \u0440\u0435\u0448\u0430\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0443 \u00abcredit assignment\u00bb (\u043a\u0430\u043a\u043e\u0439 \u0438\u0437 \u0448\u0430\u0433\u043e\u0432 \u0432\u0438\u043d\u043e\u0432\u0430\u0442 \u0432 \u043f\u0440\u043e\u0432\u0430\u043b\u0435?).<\/p>\n<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<h3>\u041f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0437\u0430\u0434\u0430\u043d\u0438\u0435<\/h3>\n<p><strong>\u0417\u0430\u0434\u0430\u0447\u0430<\/strong>: \u0420\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c (\u0438\u043b\u0438 \u043f\u0440\u043e\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0441\u0435\u0432\u0434\u043e\u043a\u043e\u0434) \u043c\u043d\u043e\u0433\u043e\u0448\u0430\u0433\u043e\u0432\u0443\u044e \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u00ab\u0412\u043e\u043f\u0440\u043e\u0441\u2013\u041e\u0442\u0432\u0435\u0442\u00bb (multi-hop QA) + \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044e \u043f\u0440\u043e\u043c\u043f\u0442\u043e\u0432 \u0434\u043b\u044f \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u044f \u0438\u0442\u043e\u0433\u043e\u0432\u043e\u0439 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438.<\/p>\n<ol>\n<li>\n<p><strong>\u0421\u0438\u0441\u0442\u0435\u043c\u0430:<\/strong><\/p>\n<ul>\n<li>\n<p>\u041c\u043e\u0434\u0443\u043b\u044c GenerateSearchQuery: \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 (question, context) \u0438 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 search_query.<\/p>\n<\/li>\n<li>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u043e\u0438\u0441\u043a\u0430: \u0438\u043c\u0438\u0442\u0438\u0440\u0443\u0435\u0442 \u043f\u043e\u0438\u0441\u043a, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0440\u0435\u043b\u0435\u0432\u0430\u043d\u0442\u043d\u044b\u0435 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b.<\/p>\n<\/li>\n<li>\n<p>\u041c\u043e\u0434\u0443\u043b\u044c AnswerWithContext: \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u0442 \u0432\u0441\u0451 \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u043e\u0435 \u0438 \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u0442 \u0444\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u041c\u0435\u0442\u0440\u0438\u043a\u0430:<\/strong><\/p>\n<ul>\n<li>\n<p>\u041f\u0443\u0441\u0442\u044c \u044d\u0442\u043e Exact Match \u0441 \u044d\u0442\u0430\u043b\u043e\u043d\u043d\u044b\u043c \u043e\u0442\u0432\u0435\u0442\u043e\u043c (\u0438\u043b\u0438 \u043b\u044e\u0431\u0430\u044f \u0441\u0432\u043e\u044f).<\/p>\n<\/li>\n<li>\n<p>\u0418\u043c\u0435\u0435\u043c \u0442\u0440\u0435\u043d\u0438\u0440\u043e\u0432\u043e\u0447\u043d\u044b\u0439 \u043d\u0430\u0431\u043e\u0440 \u0438\u0437 (\u0432\u043e\u043f\u0440\u043e\u0441, \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442).<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u041e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f:<\/strong><\/p>\n<ul>\n<li>\n<p>\u0412\u043e\u0437\u044c\u043c\u0451\u043c, \u043a \u043f\u0440\u0438\u043c\u0435\u0440\u0443, MIPRO \u0438\u043b\u0438 Bootstrap Random Search.<\/p>\n<\/li>\n<li>\n<p>\u0421\u043e\u0431\u0435\u0440\u0451\u043c \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u0434\u0435\u043c\u043e-\u043f\u0440\u0438\u043c\u0435\u0440\u044b (bootstrapping) \u0438\u043b\u0438 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043d\u0430 \u0433\u043e\u043b\u044b\u0445 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f\u0445.<\/p>\n<\/li>\n<li>\n<p>\u0418\u0442\u0435\u0440\u0438\u0440\u0443\u0435\u043c, \u043f\u043e\u043a\u0430 \u043d\u0435 \u043d\u0430\u0439\u0434\u0451\u043c \u0445\u043e\u0440\u043e\u0448\u0438\u0439 \u043d\u0430\u0431\u043e\u0440 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0439 + few-shot \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u041f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c<\/strong>\u00a0\u043d\u0430 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u043c \u043d\u0430\u0431\u043e\u0440\u0435, \u0441\u0440\u0430\u0432\u043d\u0438\u0442\u044c \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u043e \u0434\u043e \u0438 \u043f\u043e\u0441\u043b\u0435.<\/p>\n<\/li>\n<\/ol>\n<h3>\u0420\u0435\u0448\u0435\u043d\u0438\u0435<\/h3>\n<p>\u041d\u0438\u0436\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0451\u043d \u0443\u043f\u0440\u043e\u0449\u0451\u043d\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440. \u041e\u043d \u0438\u043b\u043b\u044e\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442, \u043a\u0430\u043a \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043e\u043f\u0438\u0441\u0430\u0442\u044c \u043c\u043e\u0434\u0443\u043b\u0438 (\u0447\u0435\u0440\u0435\u0437 \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u044b) \u0438 \u043a\u0430\u043a \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c DSPy-\u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044e (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e MIPRO). \u0414\u043b\u044f \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0433\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u043d\u0443\u0436\u043d\u043e \u0435\u0449\u0435 \u0441\u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u044f\u0437\u044b\u043a\u043e\u0432\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c.<\/p>\n<pre><code class=\"python\">import dspy lm = dspy.LM(model='ollama\/deepseek-r1:70b', api_base='http:\/\/localhost:11434') dspy.configure(lm=lm)<\/code><\/pre>\n<pre><code class=\"python\">import dspy  ############################################# # 1. Define Signatures for the Submodules   # #############################################  class GenerateSearchQuery(dspy.Signature):     context: str = dspy.InputField()     question: str = dspy.InputField()     search_query: str = dspy.OutputField()  class AnswerWithContext(dspy.Signature):     context: str = dspy.InputField()     question: str = dspy.InputField()     answer: str = dspy.OutputField()  ############################################# # 2. Define the MultiHopQA Module           # #############################################  class MultiHopQA(dspy.Module):     \"\"\"     \u041c\u043e\u0434\u0443\u043b\u044c\u043d\u0430\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u0430, \u0441\u043e\u0441\u0442\u043e\u044f\u0449\u0430\u044f \u0438\u0437 \u0434\u0432\u0443\u0445 \u043f\u043e\u0434\u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432:     1) \u0413\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u043f\u043e\u0438\u0441\u043a\u043e\u0432\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430,     2) \u0413\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u0438\u0442\u043e\u0433\u043e\u0432\u043e\u0433\u043e \u043e\u0442\u0432\u0435\u0442\u0430.     \"\"\"     def __init__(self, max_iterations=2):         super().__init__()         self.query_gen = dspy.ChainOfThought(GenerateSearchQuery)         self.answer_gen = dspy.ChainOfThought(AnswerWithContext)         self.max_iterations = max_iterations      def forward(self, question: str) -&gt; str:         context_collected = \"\"         for _ in range(self.max_iterations):             # 1) \u0413\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c \u043f\u043e\u0438\u0441\u043a\u043e\u0432\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441             out_query = self.query_gen(                 context=context_collected,                 question=question             )             search_query = out_query[\"search_query\"]              # 2) \u0418\u043c\u0438\u0442\u0438\u0440\u0443\u0435\u043c \u043f\u043e\u0438\u0441\u043a (\u0438\u043b\u0438 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u043a \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u043c\u0443 \u043f\u043e\u0438\u0441\u043a\u043e\u0432\u043e\u043c\u0443 \u0434\u0432\u0438\u0436\u043a\u0443)             retrieved_docs = f\"Docs_for_{search_query}\"              # 3) \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u043e\u0435 \u0432 \u043e\u0431\u0449\u0438\u0439 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442             context_collected += f\"\\n{retrieved_docs}\"          # 4) \u0413\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c \u0444\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442         out_ans = self.answer_gen(             context=context_collected,             question=question         )         final_answer = out_ans[\"answer\"]         return final_answer  ############################################# # 3. Prepare Data and Metric (Exact Match)  # #############################################  train_data = [     dspy.Example(inputs=\"\u041a\u0442\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u0440\u043e\u043c\u0430\u043d '\u041c\u0430\u0441\u0442\u0435\u0440 \u0438 \u041c\u0430\u0440\u0433\u0430\u0440\u0438\u0442\u0430'?\", reference=\"\u041c\u0438\u0445\u0430\u0438\u043b \u0411\u0443\u043b\u0433\u0430\u043a\u043e\u0432\"),     dspy.Example(inputs=\"\u041a\u0430\u043a\u043e\u0435 \u0443\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u043e\u0442\u043a\u0440\u044b\u043b \u0444\u0440\u0430\u043d\u0446\u0443\u0437\u0441\u043a\u0438\u0439 \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u043a \u0416\u043e\u0437\u0435\u0444 \u041b\u0438\u0443\u0432\u0438\u043b\u043b\u044c?\", reference=\"\u0423\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u041b\u0438\u0443\u0432\u0438\u043b\u043b\u044f (Liouville's equation)\")     # ... add more examples as needed ]  def exact_match(prediction: str, reference: str) -&gt; float:     pred = prediction.strip().lower()     ref = reference.strip().lower()     return 1.0 if ref in pred else 0.0  def my_metric_fn(outputs, references) -&gt; float:     scores = []     for pred, ref in zip(outputs, references):         scores.append(exact_match(pred, ref))     return sum(scores) \/ len(scores)  ############################################# # 4. Run the Optimizer (using MIPROv2)       # #############################################  pipeline = MultiHopQA(max_iterations=2)  # \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 def data_loader_fn():     return train_data  # Supply the required metric during instantiation. optimizer = dspy.MIPROv2(metric=my_metric_fn)  # Use the compile method instead of optimize; pass the trainset directly. trainset = data_loader_fn() best_pipeline = optimizer.compile(pipeline, trainset=trainset, minibatch_size=1)  ############################################# # 5. Test the Final System                 # #############################################  test_questions = [     \"\u041a\u0442\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u0440\u043e\u043c\u0430\u043d '\u041c\u0430\u0441\u0442\u0435\u0440 \u0438 \u041c\u0430\u0440\u0433\u0430\u0440\u0438\u0442\u0430'?\",     \"\u041a\u0430\u043a\u043e\u0432\u043e \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0435 \u0443\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u041b\u0438\u0443\u0432\u0438\u043b\u043b\u044f?\" ]  for q in test_questions:     ans = best_pipeline(q)     print(f\"\u0412\u043e\u043f\u0440\u043e\u0441: {q}\\n\u041e\u0442\u0432\u0435\u0442: {ans}\\n---\")<\/code><\/pre>\n<p>\u042d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u043c\u043e\u0434\u0443\u043b\u044c\u043d\u0443\u044e \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u0434\u043b\u044f \u043e\u0442\u0432\u0435\u0442\u0430 \u043d\u0430 \u0432\u043e\u043f\u0440\u043e\u0441\u044b:<\/p>\n<ul>\n<li>\n<p><strong>\u0414\u0432\u0430 \u0448\u0430\u0433\u0430:<\/strong><\/p>\n<ol>\n<li>\n<p>\u0413\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043f\u043e\u0438\u0441\u043a\u043e\u0432\u043e\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0432\u043e\u043f\u0440\u043e\u0441\u0430 \u0438 \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430.<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0438\u043c\u0438\u0442\u0430\u0446\u0438\u0438 \u043f\u043e\u0438\u0441\u043a\u0430 \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043a \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0443, \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043e\u043a\u043e\u043d\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442.<\/p>\n<\/li>\n<\/ol>\n<\/li>\n<li>\n<p><strong>\u041e\u0431\u0443\u0447\u0435\u043d\u0438\u0435:<\/strong><br \/>\u0421\u0438\u0441\u0442\u0435\u043c\u0430 \u043e\u0431\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0442\u043e\u0440\u0430 dspy.MIPROv2 \u0438 \u043c\u0435\u0442\u0440\u0438\u043a\u0438 \u0442\u043e\u0447\u043d\u043e\u0433\u043e \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u044f \u043d\u0430 \u0442\u0440\u0435\u043d\u0438\u0440\u043e\u0432\u043e\u0447\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<\/li>\n<li>\n<p><strong>\u0422\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435:<\/strong><br \/>\u041f\u043e\u0441\u043b\u0435 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u043d\u0430 \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0435 \u0432\u043e\u043f\u0440\u043e\u0441\u044b, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043d\u0430\u043a\u043e\u043f\u043b\u0435\u043d\u043d\u044b\u0439 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442.<\/p>\n<\/li>\n<\/ul>\n<p>\u041a\u043e\u043c\u0443 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u043d\u043e \u043f\u043e\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043d\u0430\u0434<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-448525","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/448525","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=448525"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/448525\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=448525"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=448525"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=448525"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}