-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from patham9/Evaluation
Evaluation
- Loading branch information
Showing
14 changed files
with
1,396 additions
and
77 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from NarsGPT import * | ||
import json | ||
|
||
Line_Input_Output_ExpectedOutput = [] | ||
Line = 1 | ||
while True: | ||
try: | ||
line = input() | ||
except EOFError: | ||
#print(NarsGPT_AddInput("where is the cat?")) | ||
exit(0) | ||
parts = ",".join(line.split(",")[1:]).split(",,,,,,") | ||
Input, expectedOutput = parts | ||
Input = Input.strip() | ||
expectedOutput = expectedOutput.strip() | ||
if expectedOutput != "": | ||
if not Input.endswith("?"): | ||
Input += "?" | ||
actualOutput = NarsGPT_AddInput(Input) | ||
Dic = {"Line": Line, "Input": Input, "actualOutput": actualOutput, "expectedOutput": expectedOutput} | ||
Line_Input_Output_ExpectedOutput.append(Dic) | ||
for k in Dic: | ||
print(k+":", Dic[k]) | ||
print("\n") | ||
filename = "OUT.json" | ||
with open(filename, 'w') as f: | ||
json.dump((Line_Input_Output_ExpectedOutput, currentTime), f) | ||
Line += 1 | ||
|
||
|
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import json | ||
import openai | ||
import time | ||
import sys | ||
for x in sys.argv: | ||
if x.startswith("API_KEY="): | ||
openai.api_key = x.split("API_KEY=")[1] | ||
|
||
with open("OUT.json") as json_file: | ||
ListOfDicts, _ = json.load(json_file) | ||
|
||
# {"Line": Line, "Input": Input, "actualOutput": actualOutput, "expectedOutput": expectedOutput} | ||
Questions = [] | ||
for D in ListOfDicts: | ||
Line = D["Line"] | ||
Input = D["Input"] | ||
actualOutput = D["actualOutput"] | ||
expectedOutput = D["expectedOutput"] | ||
if expectedOutput != "": | ||
Questions.append(D) | ||
|
||
with open("QUESTIONS.json", 'w') as f: | ||
json.dump(Questions, f) | ||
|
||
PROMPT = """Does the actual output contain the asked information answered in the expected output? | ||
The question: _QUESTION_ | ||
The actual output: _ACTUAL_OUTPUT_ | ||
The expected output: _EXPECTED_OUTPUT_ | ||
Please answer yes/no only!""" | ||
|
||
All = [] | ||
Correct = [] | ||
Incorrect = [] | ||
for D in Questions: | ||
Line = D["Line"] | ||
Input = D["Input"] | ||
actualOutput = D["actualOutput"] | ||
expectedOutput = D["expectedOutput"] | ||
send_prompt = PROMPT.replace("_QUESTION_", Input).replace("_ACTUAL_OUTPUT_",actualOutput).replace("_EXPECTED_OUTPUT_",expectedOutput) | ||
print(send_prompt) | ||
while True: | ||
try: | ||
response = openai.ChatCompletion.create(model='gpt-3.5-turbo', messages=[ {"role": "user", "content": send_prompt}], max_tokens=200, temperature=0) | ||
ret = response['choices'][0]['message']['content'] | ||
except: | ||
print("Error: API call failed, will try repeating it in 10 seconds!") | ||
time.sleep(10) #wait 10 seconds | ||
continue | ||
break | ||
YES = "yes" in ret.lower() | ||
D["Correct"] = YES | ||
print("Correct?", YES) | ||
if YES: | ||
Correct.append(D) | ||
else: | ||
Incorrect.append(D) | ||
All.append(D) | ||
scores = {"Correct": len(Correct), "Incorrect": len(Incorrect), "Ratio" : float(len(Correct)) / float(len(All))} | ||
print("So far:", scores) | ||
with open("All.json", 'w') as f: | ||
json.dump(All, f) | ||
with open("Correct.json", 'w') as f: | ||
json.dump(Correct, f) | ||
with open("Incorrect.json", 'w') as f: | ||
json.dump(Incorrect, f) | ||
with open("scores.json", 'w') as f: | ||
json.dump(scores, f) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.