"""Extract linguistic + math feature matrices for ASDiv (grade-labeled) and SVAMP.""" import json import pandas as pd from datasets import load_dataset from features import linguistic_features, math_features_from_chain, math_features_from_equation def build_asdiv(): ds = load_dataset("MU-NLPC/Calc-asdiv_a", split="test") rows = [] for ex in ds: q = ex["question"] if not q or not q.strip(): continue lf = linguistic_features(q) mf = math_features_from_chain(ex["chain"] or "") row = {"id": ex["id"], "grade": ex["grade"], "text": q} row.update(lf) row.update(mf) rows.append(row) df = pd.DataFrame(rows) df.to_parquet("asdiv_features.parquet") print("ASDiv:", df.shape, "grades:", sorted(df.grade.unique())) print(df.grade.value_counts().sort_index().to_dict()) return df def build_svamp(): ds = load_dataset("ChilleD/SVAMP", split="train") rows = [] for ex in ds: text = (ex["Body"] + " " + ex["Question"]).strip() lf = linguistic_features(text) mf = math_features_from_equation(ex["Equation"] or "") row = {"id": ex["ID"], "type": ex["Type"], "text": text} row.update(lf) row.update(mf) rows.append(row) df = pd.DataFrame(rows) df.to_parquet("svamp_features.parquet") print("SVAMP:", df.shape, "types:", df.type.nunique()) return df if __name__ == "__main__": build_asdiv() build_svamp()