今更GPT-3.5です
gpt-3.5-turbo-instructを使って次にくるトークンを予測させて遊んでいたら、ふと思いついたネタです。
"これは0〜9の乱数列です。 3, "
の続きを予想させるのですが、このとき最初に渡す数字(ここでは3)を変化させると結果に偏りが生まれるか?という実験です。
問題設定
プロンプト
"The following is a random sequence of numbers with a lower limit of 0 and an upper limit of 9.\n\n3, "
今は仮で3にしていますが、実際は0〜9を順番に入れてモデルに渡します。
それぞれ100回予測させて集計します。
やってみた
from collections import Counter
import seaborn as sns
import pandas as pd
import matplotlib.pyplot as plt
import openai
import tqdm.auto as tqdm
openai.api_key = "..."
# 入力28トークン・出力1トークン -> 1000回実行すると$0.044かかる(たぶん)
def random_number_by_gpt(n=0):
response = openai.Completion.create(
model="gpt-3.5-turbo-instruct",
prompt=f"The following is a random sequence of numbers with a lower limit of 0 and an upper limit of 9.\n\n{n}, ",
max_tokens=1,
)
try:
generated_number = int(response.choices[0].text)
except ValueError:
generated_number = None
return generated_number
# ------------------------------
# 予測させる
response_numbers = []
for n in tqdm.tqdm(range(10)):
response_numbers_inner = []
for _ in tqdm.tqdm(range(100)):
response_numbers_inner.append(random_number_by_gpt(n))
response_numbers.append(response_numbers_inner)
# 集計とプロット
frequency_counts = [Counter(numbers) for numbers in response_numbers]
frequency_df = pd.DataFrame(frequency_counts).fillna(0).sort_index(axis=1)
frequency_df = frequency_df.T
frequency_df = frequency_df.iloc[::-1]
plt.figure(figsize=(10, 8))
sns.heatmap(frequency_df, annot=True, cmap="YlGnBu", fmt=".0f")
plt.title("Frequency Counts Heatmap")
plt.xlabel("Starting Number")
plt.ylabel("Generated Number")
plt.show()
結果
- 最初に渡された数字とその隣はほぼ出さない
- 4,5個くらい離れた数字をよく出す
- 7->2と3->7が異常に出やすい
ということになりました。
本当にランダムならば、最初に渡された数字に関わらず等確率で出力されるはずです。
まあ等確率なわけないとは予想していましたが、ここまではっきりだとは……
今回の範囲だと、渡された数字と同じ数字は1回も出力していませんね。
今後の課題(?)
- GPT-4だとどうなのか?
- もっと値の範囲を増やすとどうなるのか?
お金持ちの方、頼みました!!