File size: 1,498 Bytes
02b83fa | 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 | """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()
|