0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【GPT-3.5】「これは乱数列です。3,<?>」←最初に渡す数字で結果に偏りが出るか?

Posted at

今更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()

結果

image.png

  • 最初に渡された数字とその隣はほぼ出さない
  • 4,5個くらい離れた数字をよく出す
  • 7->2と3->7が異常に出やすい

ということになりました。
本当にランダムならば、最初に渡された数字に関わらず等確率で出力されるはずです。
まあ等確率なわけないとは予想していましたが、ここまではっきりだとは……
今回の範囲だと、渡された数字と同じ数字は1回も出力していませんね。

今後の課題(?)

  • GPT-4だとどうなのか?
  • もっと値の範囲を増やすとどうなるのか?
    お金持ちの方、頼みました!!
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?