LangChainJSとZapierNLAを使用したBigQueryクエリ実行におけるGPT-3.5とGPT-4の比較

この記事では、LangChainJSとZapierNLAを使用してBigQuery上でクエリを実行し、GPT-3.5とGPT-4の性能差を比較しました。

背景

LangChainJSとZapierNLAは、2023年3月16日に連携を開始しました。これらのツールは、自然言語処理 (NLU) 技術を用いて、高度なタスクを実行することができます。 この統合により、自然言語APIインターフェースを通じて、Zapierのプラットフォーム上の5k以上のアプリと20k以上のアクションにアクセスすることができます。

具体的な設定方法はLangChainのブログ記事 https://blog.langchain.dev/langchain-zapier-nla/ を参照してください。統合の方法も非常に簡単で、Zapier側で連携したいアプリケーションをポチポチしたあと、API Keyを払い出すだけです。

LangChain側も下記のようなコードを書くだけで終わりです。

llm = OpenAI(temperature=0)
zapier = ZapierNLAWrapper()
toolkit = ZapierToolkit.from_zapier_nla_wrapper(zapier)
agent = initialize_agent(toolkit.get_tools(), llm, agent="zero-shot-react-description", verbose=True)

また、同日に、OpenAIのGPT-4のAPIウェイトリストが開放されたのでAPIを利用できるようになりました。

  • GPT4とGPT3.5は性能に差があるというのは認識していたので、特にLangChainのzero-shot-react-descriptionの性能差が如実に出ると考えたので比較してみたかった

  • QLクエリは正確に実行しないとエラーになるという特性があるのでBigQueryで連携して見ると良さそうと考えた

というところで、今回の検証をやってみたという感じです。

本稿では、LangChainJSとZapierNLAを使用して、BigQuery上で特定タスクを実行しました。具体的には、与えられたタスクは、特定のデータセットから全てのテーブルスキーマを取得し、ほしいデータを含むテーブルを特定し、そのテーブルの特定の数値の合計を計算することです。 この比較では、LangChainJSとZapierNLAを使用してBigQueryでクエリを実行し、GPT-3.5とGPT-4のパフォーマンスの違いを確認しました。

シナリオ

実行したクエリは下記のとおりです。

Run query to get all of table schema from <データセット名> dataset.
And find out the table which has <欲しいデータ> data.
And run query on that table to make the sum of <欲しいデータのカラム名>. if the result is null, execute another query for 3 times.

与えられたタスクは、

  1. 特定のデータセットからすべてのテーブルスキーマを取得

  2. ほしいデータを持つテーブルを見つけ

  3. そのテーブルで欲しいデータのカラムの合計を計算するクエリを実行すること

  4. もし結果がnullであれば、3回別のクエリを実行する必要があります。

GPT-4の結果

LangChainの出力結果は下記です

Loaded agent.
Executing with input "
Run query to get all of table schema from XXX dataset.
And find out the table which has XXX data.
And run query on that table to make the sum of XXX. if the result is null, execute another query for 3 times."...
Entering new agent_executor chain...
I need to run a query to get the schema of all tables in the XXX dataset and find the table with XXX data. Then, I need to run a query to sum the XXX on that table. If the result is null, I need to execute the query three more times.

Action: Google BigQuery: Run a Query (XXX project id)
Action Input: SELECT table_name, column_name FROM `XXX.XXX.INFORMATION_SCHEMA.COLUMNS` WHERE column_name LIKE '%XXX%'
{"rows[]column_name":"XXX, XXX, ....","rows[]table_name":"XXX, XXX, ..."}
I found the tables with XXX data: XXX, XXX,... and XXX. I will now run a query to sum the XXX on the first table and if the result is null, I will execute the query three more times.

Action: Google BigQuery: Run a Query (XXX project id)
Action Input: SELECT SUM(XXX) as total_XXX FROM `XXX.XXX.XXX`
{"rows[]total_XXX":"YYY"}
Finished chain.
Got output The sum of XXX in the `XXX` table is YYY.

GPT-4はクエリを正常に実行し、以下の結果を提供しました:Got output The sum of XXX in the `XXX` table is YYY. GPT-4は、当該データが含まれるテーブルをすべて特定しました。次に、最初のテーブルで欲しいデータを合計するクエリを実行し、結果がnullでなかったため、タスクは正常に完了しました。

GPT-3.5の結果

Loaded agent.
Executing with input "
Run query to get all of table schema from XXX dataset.
And find out the table which has XXX data.
And run query on that table to make the sum of XXX. if the result is null, execute another query for 3 times."...
Entering new agent_executor chain...
I need to use Google BigQuery: Run a Query (XXX project id) tool to run a query on the `XXX` dataset to get all table schema. Then, I need to find the table that has XXX data and run a query on that table to make the sum of XXX. If the result is null, I need to execute another query for 3 times.
Action: Google BigQuery: Run a Query (XXX project id)
Action Input: "SELECT * FROM `XXX`.INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE='BASE TABLE'"
{"rows[]table_type":"BASE TABLE, BASE TABLE, BASE TABLE, BASE TABLE, BASE TABLE, BASE TABLE, BASE TABLE, BASE TABLE, BASE TABLE, BASE TABLE, BASE TABLE, BASE TABLE, BASE TABLE, BASE TABLE, BASE TABLE","rows[]table_schema":"XXX, XXX, XXX, XXX, XXX, XXX, XXX, XXX, XXX, XXX, XXX, XXX, XXX, XXX, XXX","rows[]base_table_catalog":"None, None, None, None, None, None, None, None, None, None, None, None, None, None, None","rows[]base_table_name":"None, None, None, None, None, None, None, None, None, None, None, None, None, None, None","rows[]base_table_schema":"None, None, None, None, None, None, None, None, None, None, None, None, None, None, None","rows[]is_insertable_into":"YES, YES, YES, YES, YES, YES, YES, YES, YES, YES, YES, YES, YES, YES, YES"}
I need to filter the results from the previous query to only include tables with XXX data. Then, I need to run a query on that table to make the sum of XXX. If the result is null, I need to execute another query for 3 times.
Action: Google BigQuery: Run a Query (XXX project id)
Action Input: "SELECT * FROM `XXX`.INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='<table_name>' AND COLUMN_NAME='XXX'"
null
The previous query returned null, so I need to execute it again for 2 more times.
Action: Google BigQuery: Run a Query (XXX project id)
Action Input: "SELECT * FROM `XXX`.INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='<table_name>' AND COLUMN_NAME='XXX'"
null
The previous query returned null again, so I need to execute it one more time.
Action: Google BigQuery: Run a Query (XXX project id)
Action Input: "SELECT * FROM `XXX`.INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='<table_name>' AND COLUMN_NAME='XXX'"
null
error: Uncaught Error: Could not parse LLM output: There is not enough information provided in the instruction to fill in the <table_name> param for the previous queries.

GPT-3.5は実行中にエラーが発生しました:

error: Uncaught Error: Could not parse LLM output: There is not enough information provided in the instruction to fill in the <table_name> param for the previous queries.

GPT-3.5は、クエリの<table_name>パラメータに十分な情報が提供されていなかったため、結果がnullとなり、最終的にエラーが発生しました。

結論

この比較から、LangChainJSとZapierNLAを使用してBigQueryで指定されたタスクを実行する際に、GPT-4がより理解力があり、より優れたパフォーマンスを発揮することが示されました。特に、LangChainのzero-shot-react-descriptionを使用すると、GPT-4の性能差がより明確に出ることがわかりました。

※この記事はGPT-3.5で書いてます

この記事が気に入ったらサポートをしてみませんか?