Skip to content

Instantly share code, notes, and snippets.

@rgreenblatt
Created December 17, 2023 01:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rgreenblatt/edab6babc565107ad9c64c55dccc3d59 to your computer and use it in GitHub Desktop.
Save rgreenblatt/edab6babc565107ad9c64c55dccc3d59 to your computer and use it in GitHub Desktop.
Fraction chess
# %%
import os
import openai
import numpy as np
from tqdm import trange
# %%
if "OPENAI_API_KEY" not in os.environ:
openai.api_key_path = os.path.expanduser("~/.openai_api_key")
# %%
# model = "babbage-002"
model = "davinci-002"
# %%
counts_chess_str = 0
chess_seqs_seqs = []
loop_count = 50
n = 128
total_seqs = loop_count * n
max_tokens = 50
for _ in trange(loop_count):
r = openai.Completion.create(
engine=model,
prompt="<|endoftext|>",
logprobs=0,
n=n,
max_tokens=max_tokens,
temperature=1,
)
for c in r["choices"]:
if " d4 " in c["text"] or " O-O " in c["text"] or " e4 " in c["text"]:
chess_seqs_seqs.append(c["text"])
counts_chess_str += 1
# %%
frac_chess = counts_chess_str / total_seqs
print(f"{frac_chess=}")
# %%
print("chess seqs")
for seq in chess_seqs_seqs:
print(seq)
print("========")
# %%
uncertainty = np.sqrt(frac_chess * (1 - frac_chess) / total_seqs)
print(f"{frac_chess:.3f} +/- {uncertainty:.3f}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment