プロンプティム:プロンプト最適化のための実験的ライブラリ
LangChain Blog は、手動のプロンプトエンジニアリングの時間を短縮し、評価データに基づいて自動的にプロンプトを最適化する実験的ライブラリ「Promptim」を発表した。
キーポイント
自動最適化ループの実装
初期プロンプト、データセット、カスタム評価器(および人的フィードバック)を入力とし、システムが自動的に改善されたプロンプトを生成するループを実現する。
評価駆動型開発の自動化
従来の手動調整から脱却し、明確なデータセットと評価指標を用いてプロンプトの変更を自動提案・スコアリングするアプローチを推進する。
エンジニア時間の節約
時間集約型のプロセスである手動プロンプトエンジニアリングを自動化することで、開発者の工数を大幅に削減し、効率化を図ることを目的としている。
影響分析・編集コメントを表示
影響分析
本記事は、LLM エンジニアリングの標準化と自動化に向けた重要な一歩を示しており、手動依存からデータ駆動型の自動最適化へパラダイムシフトを促すものです。特に評価指標(Evaluator)の定義が容易である点は、大規模な AI システム開発における品質保証プロセスの効率化に直結するインパクトを持ちます。
編集コメント
評価駆動開発の概念を自動化ツールとして具体化した興味深い実験であり、LLM アプリケーションの開発フローに組み込むことで、プロンプト品質の安定化が期待できる。ただし「実験的」と明記されているため、本番環境での導入には慎重な検証が必要である。
Promptim は、AI システムを体系的に改善するために設計された実験的なプロンプト 最適化ライブラリです。
Promptim は、特定のタスクにおけるプロンプトの改善プロセスを自動化します。初期のプロンプト、データセット、カスタム評価関数(およびオプションで人間のフィードバック)を提供すると、promptim は最適化ループを実行し、元のプロンプトを上回る性能を目指す洗練されたプロンプトを生成します。
評価駆動開発からプロンプト最適化へ
AI エンジニアの主要な責任の一つはプロンプトエンジニアリングです。これには、より良い結果を生み出すために手動でプロンプトを調整することが含まれます。
このアプローチに有用な方法は、評価駆動開発(evaluation-driven development)を通じて行うことです。これには、まず入力データセット(およびオプションで期待される出力)を作成し、その後、複数の評価指標を定義することが含まれます。プロンプトに変更を加えるたびに、データセットに対してそれを実行し、出力にスコアを付けます。このようにして、プロンプトのパフォーマンスを測定し、それが改善されていることを確認するか、少なくとも後退していないことを保証できます。LangSmith などのツールは、データセットのキュレーションと評価を支援します。
プロンプト最適化の考え方は、これらの明確に定義されたデータセットと評価指標を用いて、プロンプトを自動的に改善することにあります。プロンプトへの変更を自動化された方法で提案し、その新しいプロンプトをこの評価手法でスコアリングすることができます。DSPy などのツールは、このような取り組みにおいて長年にわたり先駆的な役割を果たしてきました。
なぜプロンプト最適化を行うのか?
プロンプト最適化にはいくつかの動機があります:
時間の節約: 手動のプロンプトエンジニアリングは、しばしば時間がかかるプロセスになります。自動化されたプロンプト最適化により、プロンプトエンジニアリングの作業を加速し、エンジニアリング時間を節約できます。
厳密性の導入: プロンプトエンジニアリングは、時に科学よりも芸術に近い側面があります。これによりプロセスに一定の厳密さをもたらします。なお、一般的に評価駆動型開発(evaluation-driven development)は、この目的を達成するのに役立ちます。
モデル間の切り替えの容易化: 異なるモデルは、しばしば異なるプロンプティング戦略を必要とします。モデルプロバイダーを変更することは、呼び出す URL を変更するだけ那么简单ではありません。多くの場合、プロンプト自体も変更する必要があります。プロンプト最適化により、このプロセスが加速されます。なぜなら、モデル非依存(model agnostic)である評価指標の開発に多くの労力を集中し、モデル依存性が高いプロンプティングにはあまり労力を割かなくても済むからです。
Promptim の仕組み
プロンプト最適化の最初の試みとして、このライブラリを公開できることを嬉しく思います。これはオープンソースのライブラリ(promptim)であり、LangSmith と統合されています。LangSmith は、データセット管理、プロンプト管理、結果の追跡、そして(オプションで)人間のラベリングに使用しています。
コアアルゴリズムは以下の通りです:
- LangSmith のデータセット、LangSmith 内のプロンプト、ローカルで定義された評価器を指定します。オプションとして、学習用・検証用・テスト用のデータセット分割を指定することもできます。
- 初期プロンプトを検証用(または全)データセットに対して実行し、ベースラインスコアを取得します。
- 次に、学習用(または全)データセット内のすべての例に対してループ処理を行います。各例に対してプロンプトを実行し、スコアリングします。その後、結果(入力、出力、期待される出力、スコア)をメタプロンプトに渡し、現在のプロンプトへの変更提案を求めます。
- 次に、更新された新しいプロンプトを使用して、検証分割に対して再度メトリクスを計算します。
- メトリクスが改善を示す場合、更新されたプロンプトが保持されます。改善がない場合は、元のプロンプトが維持されます。
- このプロセスを N 回繰り返します。
オプションとして、人間のフィードバックを残すステップを追加することもできます。これは、優れた自動メトリクスがない場合や、自動メトリクスが提供できる範囲を超えたフィードバックに基づいてプロンプトを最適化したい場合に有用です。これには LangSmith のアノテーションキュー を使用します。
プロンプト最適化の限界
プロンプト最適化には大きな期待を抱いていますが、これが万能薬(silver bullet)であるとは考えていません。このプロセスにおいて人間が関与する(human-in-the-loop)ことは依然として価値があります——最終結果に対する妥当性確認のためであっても構いません。これが、LangSmithのPrompt Hub を使用してプロンプトを保存する理由の一部です——これにより、後から容易にプロンプトを検証することができます。
Promptim と DSPy の比較
DSPy は最適化分野における主要なツールです。私たちのアプローチとの比較を行う価値があります。
まず、今回の初期の取り組みは単一のプロンプトを最適化することに焦点を当てています。DSPy は「複合 AI システム」全体を最適化することに重点を置いています。私たちは現時点でより扱いやすい問題であると考え、単一のプロンプトに焦点を当てることを選択しました。
第二に、私たちは人間が関与する状態を維持することに重点を置く一方、DSPy は人間の関与をより排除する方向にあります。この一例として、最適化プロセスの一部としてフィードバック用の注釈キュー(annotation queues)に接続し、人間のフィードバックを得る方法があります。もう一つの例は、後からの容易な検証のためにこれらのプロンプトを LangSmith に保存することです。最後の例は、LangSmith 内で評価結果を追跡することです。
第三に、私たちはプロンプトの書き換えみに焦点を当て、その点で非常に優れたものを目指しているのに対し、DSPy はシステムを最適化するためのより広範なソリューション(ファインチューニング、few-shot プロンプティング)を提供しています。
💡
これらの違いから、私たちは Promptim と DSPy を異なる問題に対する異なるツールと見なしています。
今後の課題
基盤モデルが安定するにつれて、プロンプト最適化への関心は高まっています。私たちが期待している取り組みは以下の通りです:
- ダイナミック・フューショット・プロンプティングのさらなる推進
- LangSmith UI への Promptim の統合
- Promptim への最適化手法の追加
- プロンプトだけでなく、LangGraph グラフ全体を最適化する(理想的には DSPy との統合を通じて)
今日から Promptim を試す ことができます:pip install promptim。チュートリアルについては この YouTube 動画 を、フィードバックは GitHub または Twitter でお寄せください。
原文を表示
Promptim is an experimental prompt optimization library to help you systematically improve your AI systems.
Promptim automates the process of improving prompts on specific tasks. You provide initial prompt, a dataset, and custom evaluators (and optional human feedback), and promptim runs an optimization loop to produce a refined prompt that aims to outperform the original.
From evaluation-driven development to prompt optimization
A core responsibility of AI engineers is prompt engineering. This involves manually tweaking the prompt to produce better results.
A useful way to approach this is through evaluation-driven development. This involves first creating a dataset of inputs (and optionally, expected outputs) and then defining a number of evaluation metrics. Every time you make a change to the prompt, you can run it over the dataset and then score the outputs. In this way, you can measure the performance of your prompt and make sure its improving, or at the very least not regressing. Tools like LangSmith help with dataset curation and evaluation.
The idea behind prompt optimization is to use these well-defined datasets and evaluation metrics to automatically improve the prompt. You can suggest changes to the prompt in an automated way, and then score the new prompt with this evaluation method. Tools like DSPy have been pioneering efforts like this for a while.
Why do prompt optimization?
There are several motivations for prompt optimization:
Save time: Manual prompt engineering can often be a time-intensive process. Automated prompt optimization can speed up prompt engineering efforts and save engineering time.
Bring rigor: Prompt engineering is sometimes more of an art than a science – so this brings some rigor to the process. Note that evaluation-driven development in general can help accomplish this.
Facilitate swapping between models: Different models often require different prompting strategies. Switching model providers isn't as simple as changing the URL you are calling; you also often need to change the prompt. Prompt optimization can speed up that process, as you focus most of your effort on developing evals (which are model agnostic) as opposed to prompting (which is not model agnostic).
How Promptim works
We're excited to release our first attempt at prompt optimization. It is an open source library (promptim) that integrates with LangSmith (which we use for dataset management, prompt management, tracking results, and (optionally) human labeling.
The core algorithm is as follows:
- Specify a LangSmith dataset, a prompt in LangSmith, and evaluators defined locally. Optionally, you can specify train/dev/test dataset splits.
- We run the initial prompt over the dev (or full) dataset to get a baseline score.
- We then loop over all examples in the train (or full) dataset. We run the prompt over all examples, then score them. We then pass the results (inputs, outputs, expected outputs, scores) to a metaprompt and ask it to suggest changes to the current prompt
- We then use the new updated prompt to compute metrics again on the dev split.
- If the metrics show improvement, the the updated prompt is retained. If no improvement, then the original prompt is kept.
- This is repeated N times
Optionally, you can add a step where you leave human feedback. This is useful when you don't have good automated metrics, or want to optimize the prompt based on feedback beyond what the automated metrics can provide. This uses LangSmith's Annotation Queues.
Limitations of prompt optimization
Although we are excited by prompt optimization, we don't think this is a silver bullet. It's still worthwhile to have a human-in-the-loop in this process - even if it's just to provide a sanity check for the final result. That's part of the reason why we use LangSmith's Prompt Hub to store prompts — so you can easily review the prompts afterwards.
Comparing Promptim to DSPy
DSPy is the leading tool in the optimization space. It's worth comparing our approach to theirs.
First, this initial effort is focused on just optimizing a single prompt. DSPy focuses on optimizing your whole "compound AI system". We chose to focus on a single prompt for now as we think it is a more tractable problem at the moment.
Second, we focus more on still having the human in-the-loop, while DSPy removes the human a bit more. One example of this through hooking this up to annotation queues for human feedback as part of the optimization process. Another example is storing these prompts in LangSmith for easy review after the fact. A final example is tracking evaluation results in LangSmith.
Third, we focus solely on rewriting the prompt and aim to be really good at that, while DSPy offers a wider breadth of solutions to optimize your system (finetuning, few shot prompting).
💡
Because of these differences, we view promptim and dspy as different tools for different problems.
Future work
As the foundation models stabilize, we are getting more and more excited about prompt optimization. Things we are looking forward to:
- Pushing more on dynamic few shot prompting
- Integrating promptim into the LangSmith UI
- Adding more optimization methods to promptim
- Optimizing LangGraph graphs as a whole, not just prompts (ideally through an integration with DSPy)
You can try out Promptim today: pip install promptim. Check out this YouTube video for a walkthrough, and drop us a line on GitHub or Twitter with any feedback.
関連記事
今日のまとめ
AI日報で今日の重要ニュースをまとめ読み