|
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: |
|
print("Completion:", completion, f"type({type(completion)}):") |
|
print("Prediction:", prediction, f"type({type(prediction)}):") |
|
|
|
completion = completion.split(',') |
|
prediction = prediction.split(',') |
|
|
|
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""" |
|
json_string = json_string.replace('\n', '') |
|
json_string = json_string.replace('\t', '') |
|
json_string = json_string.replace(' ', '') |
|
json_string = json_string.replace('"', '') |
|
json_string = json_string.replace('{', '') |
|
json_string = json_string.replace('}', '') |
|
json_string = json_string.replace(':', ',') |
|
json_string = json_string.split(',') |
|
return { |
|
json_string[i]: json_string[i + 1] |
|
for i in range(0, len(json_string), 2) |
|
} |
|
|
|
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} |
|
|