Spaces:
Runtime error
Runtime error
# write a function that compares the completion and prediction, separating each string by comma into their respective columns, then compare each column and return a dataframe with the results | |
def compare_completion_and_prediction(completion, prediction, verbose=False): | |
# if verbose is True, print the completion and prediction strings | |
if verbose: | |
print("Completion:", completion, f"type({type(completion)}):") | |
print("Prediction:", prediction, f"type({type(prediction)}):") | |
# split completion and prediction strings on comma character | |
completion = completion.split(',') | |
prediction = prediction.split(',') | |
# create a column that counts the number of matchs between completion and prediction | |
matches = [completion[i] == prediction[i] for i in range(len(completion))] | |
# create a json dictionary with the completion, prediction, matches, and num_correct fields | |
json_dict = { | |
"completion": completion, | |
"prediction": prediction, | |
"matches": matches, | |
"num_correct": sum(matches) | |
} | |
# return the json dictionary | |
return json_dict |