File size: 1,641 Bytes
9797e5d
 
9de5882
73588d1
 
 
 
 
 
 
 
 
 
 
 
 
9de5882
 
 
 
 
 
 
73588d1
9de5882
73588d1
9de5882
 
 
73588d1
9de5882
73588d1
 
 
b82e84f
73588d1
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import json

def compare_completion_and_prediction(completion, prediction, verbose=False):
    """
    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

    Args:
        completion (_type_): str
        prediction (_type_): str
        verbose (bool, optional): bool. Defaults to False.

    Returns:
        _type_: json object with completion, prediction, matches, and num_correct
    """
    # 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 matches between completion and prediction
    matches = [completion[i] == prediction[i] for i in range(len(completion))]
    return {
        "completion": completion,
        "prediction": prediction,
        "matches": matches,
        "num_correct": sum(matches),
    }

def json_to_dict(json_string):
    """function that takes string in the form of json and returns a dictionary"""
    return json.loads(json_string)

def join_dicts(dict1, dict2):
    """function that joins two dictionaries into one dictionary

    Args:
        dict1 (_type_): dict
        dict2 (_type_): dict

    Returns:
        _type_: dict
    """
    return {key:[dict1[key], dict2[key]] for key in dict1}