型付きホールを用いた大規模言語モデルの静的文脈化
Statically Contextualizing Large Language Models with Typed Holes
September 2, 2024
著者: Andrew Blinn, Xiang Li, June Hyung Kim, Cyrus Omar
cs.AI
要旨
大規模言語モデル(LLM)はプログラム合成の分野を再構築してきた。しかし、現代のLLMベースのコード補完システムは、適切な文脈、特にトレーニングデータに存在しないかカーソル近くにない定義を扱う際に、壊れたコードを生成(ハルシネーション)することが多い。本論文では、言語サーバーが提供する型とバインディング構造との緊密な統合が、この文脈化問題をトークン効率の良い方法で解決できることを示す。端的に言えば、AIにもIDEが必要だと我々は主張する!特に、LLMコード生成をHazelライブプログラムスケッチ環境に統合した。Hazel言語サーバーは、エラーが存在する場合でも、穴埋め対象のホールの型と型付けコンテキストを識別し、意味のあるプログラムスケッチが常に利用可能であることを保証する。これにより、カーソルの字句的に近くになく、同じファイル内にある必要もないが、開発者の目標に対して意味的に近い可能性が高い、コードベース全体の文脈情報を用いたプロンプティングが可能となる。LLMによって合成された補完候補は、その後、言語サーバーとの対話を通じて反復的に洗練される。これらの手法を評価するために、モデル・ビュー・アップデート(MVU)ウェブアプリケーションのデータセットであるMVUBenchを導入する。これらのアプリケーションは、アプリケーション固有のデータ構造に依存するため、難問として機能する。型定義を用いた文脈化が特に効果的であることがわかった。Hazelを背景に我々のアイデアを紹介した後、これらの手法の汎用性を検証するために、手法を複製し、MVUBenchをTypeScriptに移植した。最後に、言語サーバーが実装可能なLanguage Server Protocol(LSP)への保守的拡張であるChatLSPの概要を説明する。これは、様々な設計のAIコード補完システムが、LLMへのプロンプト生成時に静的コンテキストを組み込むために利用できる機能を公開するものである。
English
Large language models (LLMs) have reshaped the landscape of program
synthesis. However, contemporary LLM-based code completion systems often
hallucinate broken code because they lack appropriate context, particularly
when working with definitions not in the training data nor near the cursor.
This paper demonstrates that tight integration with the type and binding
structure of a language, as exposed by its language server, can address this
contextualization problem in a token-efficient manner. In short, we contend
that AIs need IDEs, too! In particular, we integrate LLM code generation into
the Hazel live program sketching environment. The Hazel Language Server
identifies the type and typing context of the hole being filled, even in the
presence of errors, ensuring that a meaningful program sketch is always
available. This allows prompting with codebase-wide contextual information not
lexically local to the cursor, nor necessarily in the same file, but that is
likely to be semantically local to the developer's goal. Completions
synthesized by the LLM are then iteratively refined via further dialog with the
language server. To evaluate these techniques, we introduce MVUBench, a dataset
of model-view-update (MVU) web applications. These applications serve as
challenge problems due to their reliance on application-specific data
structures. We find that contextualization with type definitions is
particularly impactful. After introducing our ideas in the context of Hazel we
duplicate our techniques and port MVUBench to TypeScript in order to validate
the applicability of these methods to higher-resource languages. Finally, we
outline ChatLSP, a conservative extension to the Language Server Protocol (LSP)
that language servers can implement to expose capabilities that AI code
completion systems of various designs can use to incorporate static context
when generating prompts for an LLM.