File size: 1,114 Bytes
9de5882
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 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