in src/engine/step4/model_dev/utils/metrics.py [0:0]
def get_metrics(tool, df, query2args_dict):
"""
Computes the exact matching and execution accuracies for each inferred query.
Args:
tool(nlq2SqlTool): Tool with the functions for the query is be rendered and executed.
df(pd.DataFrame): Pandas dataframe where the input and inferred queries are stored.
query2args_dict(dict): Dictionary of default arguments for the queries.
Returns:
Pandas dataframe with the calculated accuracies.
"""
df["exact_match_wiki"] = df.apply(exact_matching, args=("preds_wiki",), axis=1)
df0 = df.drop_duplicates(
subset=["base_question", "query", "preds_wiki"], inplace=False
).reset_index(drop=True)
exec_match_wiki = []
for i, (_, row) in enumerate(df0.iterrows()):
if i % 10 == 0:
print(f"Executing {i}/{df0.shape[0]}...")
exec_match_wiki.append(
execute_matching(
tool, row, query2args_dict.get(row["query"], query2args_dict["default"])
)
)
df0["exec_match_wiki"] = exec_match_wiki
columns = ["base_question", "query", "preds_wiki", "exec_match_wiki"]
df1 = df0[columns]
common = ["base_question", "query", "preds_wiki"]
df_final = pd.merge(
left=df, right=df1, how="inner", left_on=common, right_on=common
)
return df_final