Welcome to the official repository for the paper MathDisAm: Towards Math Query Disambiguation. This repository contains the dataset, query generation pipelines, and baseline classifier models designed to distinguish between ambiguous and unambiguous mathematical queries.
Choosing_sample_questions/: Contains the scripts used to process a snapshot of Math Stack Exchange and select candidate questions for the dataset.query_generator/: Contains thegenerate_ambiguousandgenerate_unambiguouscodebases that power the synthetic generation of queries based on the Math Stack Exchange posts.data/: Stores the dataset splits for the MathDisAM task.classifier/: Contains the training pipeline (train_bert_classifier.py) and scripts to run the baseline transformer models.
The data directory contains the core datasets used for training and evaluating the disambiguation models:
MathDisAM_train.tsv: The training file containing MathSE IDs, mathematical questions, and their corresponding tags ("Ambiguous" or "Unambiguous").MathDisAM_test.tsv: The untouched, held-out test file used for final model evaluation.
The query generation process leverages a two-agent Large Language Model pipeline (using Gemma) to process natural mathematical questions:
- Ambiguous Query Generation:
- Uses an "Injector" agent to rewrite a math question to introduce deliberate ambiguity.
- Uses a "Verifier" agent to independently judge if the rewrite is genuinely ambiguous.
- The script processes questions until a target of 1,000 verified ambiguous questions is produced.
- Unambiguous Query Generation:
- Uses a "Clarifier" agent to rewrite queries to remove ambiguity.
- Uses a "Verifier" agent to evaluate if the query is fully well-posed and unambiguous.
- This pipeline also targets 1,000 verified unambiguous questions.
To run the classifier code, you can use the following commands. These represent the three baseline models we introduced for this task:
A) RoBERTa Base
CUDA_VISIBLE_DEVICES=0 python classifier/train_bert_classifier.py --train_file data/MathDisAM_train.tsv --test_file data/MathDisAM_test.tsv --model_name roberta-base --epochs 20B) BERT Base Uncased
CUDA_VISIBLE_DEVICES=0 python classifier/train_bert_classifier.py --train_file data/MathDisAM_train.tsv --test_file data/MathDisAM_test.tsv --model_name bert-base-uncased --epochs 20C) MathBERT
CUDA_VISIBLE_DEVICES=0 python classifier/train_bert_classifier.py --train_file data/MathDisAM_train.tsv --test_file data/MathDisAM_test.tsv --model_name tbs17/MathBERT --epochs 20To run the classifier pipeline, install the required dependencies:
pip install transformers datasets torch scikit-learn pandas accelerate matplotlib tqdm beautifulsoup4You will also need to find and download the file 'Posts.xml' to run most of the files in the choosing_sample_questions folder