Skip to content

Instantly share code, notes, and snippets.

@belkarx
Created June 28, 2023 03:45
Show Gist options
  • Select an option

  • Save belkarx/b61bf00b9cb2b19def9c802a57619180 to your computer and use it in GitHub Desktop.

Select an option

Save belkarx/b61bf00b9cb2b19def9c802a57619180 to your computer and use it in GitHub Desktop.
Script to test responses to PCQ-9 questions
import openai
import os
import json
from tqdm import tqdm
#change this!
TEMPERATURE=1
#past work: https://twitter.com/colin_fraser/status/1636755134679224320
openai.api_key = os.environ["OPENAI_KEY"]
initial_prompt = "Over the last 2 weeks, how often have you been bothered by any of the following problems, where 0 is not at all, 1 is several days, 2 is more than half the days, and 3 is nearly every day?"
#source: https://www.apa.org/depression-guideline/patient-health-questionnaire.pdf
questions = ["1. Little interest or pleasure in doing things:", "2. Feeling down, depressed, or hopeless:", "3. Trouble falling or staying asleep, or sleeping too much:","4. Feeling tired or having little energy:","5. Poor appetite or overeating:", "6. Feeling bad about yourself — or that you are a failure or have let yourself or your family down:","7. Trouble concentrating on things, such as reading the newspaper or watching television:","8. Moving or speaking so slowly that other people could have noticed? Or the opposite — being so fidgety or restless that you have been moving around a lot more than usual:","9. Thoughts that you would be better off dead or of hurting:"]
#question #s are truncated for now
responses = {k[3:]:[] for k in questions}
for _ in tqdm(range(10)):
for question in questions:
response = openai.Completion.create(
model="text-davinci-003",
prompt=initial_prompt+"\n"+question[3:],
temperature=TEMPERATURE,
max_tokens=256,
top_p=1,
frequency_penalty=0,
presence_penalty=0
)
try:
number = int(response["choices"][0]["text"].strip().split("\n")[0])
responses[question[3:]].append(number)
except:
print("ISSUE")
print(response["choices"][0]["text"])
print(responses)
json.dump(responses, open(f"responses_temp_{TEMPERATURE}.json", "w"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment