def str_to_dict_eedi_df(df: pd.DataFrame):
cols = ["correct_option", "gt_distractors", "generated_distractors", "distractors", "construct_info"]
cols = [col for col in cols if col in df.columns]
for i, row in df.iterrows():
for col in cols:
try:
df.at[i, col] = ast.literal_eval(row[col])
except Exception:
df.at[i, col] = None
return df
def process_data(data_address):
data_file = pd.read_csv(data_address)
data_file = str_to_dict_eedi_df(data_file)
data = []
for _, row in data_file.iterrows():
temp = {}
input = "[INST] You are given the following math question along with the correct answer and explanation. Please use the following template to give three alternative incorrect answers to be used as multiple-choice options in a multiple-choice exam. Prior to the incorrect answer, provide feedback to be displayed to the student as an explanation of why that is not the correct answer.n" +
"[Template]n" +
"Distractor1 Feedback:n" +
"Distractor1:n" +
"Distractor2 Feedback:n" +
"Distractor2:n" +
"Distractor3 Feedback:n" +
"Distractor3:n" +
"Question: " + row["question"].strip() + "nExplanation: " + row["correct_option"]["explanation"].strip() + " nAnswer: " + row["correct_option"]["option"].strip() + " [/INST]"
temp["input"] = input
output = "nDistractor1 Feedback: " + row["distractors"][0]["explanation"].strip() + "nDistractor1: " + row["distractors"][0]["option"].strip()
output += "nDistractor2 Feedback: " + row["distractors"][1]["explanation"].strip() + "nDistractor2: " + row["distractors"][1]["option"].strip()
output += "nDistractor3 Feedback: " + row["distractors"][2]["explanation"].strip() + "nDistractor3: " + row["distractors"][2]["option"].strip()
temp["output"] = output
data.append(temp)
return data
temp_data = process_data("data/eedi_train_80_cleaned_4_18.csv")
While calling str_to_dict_eedi_df()
it convert all entry to none? don’t know why my ast.litral_eva() function pass an error.
I there any one kind enough to help me with the code
New contributor
Adarsh Patel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.