metadata
license: mit
task_categories:
- question-answering
language:
- en
tags:
- agent
Mathematics Stack Exchange Q&A Dataset
A curated dataset of question-and-answer pairs harvested from Mathematics Stack Exchange (math.stackexchange.com). Each entry contains the question, the top answer (if available), metadata (scores, tags, URL), and a combined Q/A text useful for training and evaluation of question-answering and tutoring models.
Dataset summary
- Source: Mathematics Stack Exchange (via the official Stack Exchange API)
- Content: High-quality Q&A pairs (question title + body, top answer body)
- Formats: CSV and JSON
- Typical fields:
question_id(int)question_title(string)question_body(string, cleaned of HTML)question_score(int)question_tags(string, comma-separated)question_url(string)answer_body(string, cleaned of HTML; empty if no answer)answer_score(int)answer_accepted(bool)combined_text(string, "Q:\n\n<body>\n\nA: <answer or placeholder>")</li> <li><code>scraped_at</code> (ISO 8601 timestamp)</li> </ul> </li> </ul> <p>Example CSV header:</p> <pre><code>question_id,question_title,question_body,question_score,question_tags,question_url,answer_body,answer_score,answer_accepted,combined_text,scraped_at </code></pre> <h2 class="relative group flex items-center"> <a id="license-and-attribution" class="block pr-1.5 text-lg md:absolute md:p-1.5 md:opacity-0 md:group-hover:opacity-100 md:right-full" href="#license-and-attribution" > <span class="header-link"><svg class="text-gray-500 hover:text-black dark:hover:text-gray-200 w-4" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span> </a> <span> License and attribution </span> </h2> <p>Content in this dataset is user-contributed content from Stack Exchange and is licensed under the Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.</p> <p>When using or redistributing the dataset, include attribution. A suggested attribution statement:</p> <p>"Data from Mathematics Stack Exchange (math.stackexchange.com). Licensed under CC BY-SA 4.0."</p> <p>Also include a link to the original question pages (the <code>question_url</code> field) when practical.</p> <h2 class="relative group flex items-center"> <a id="how-the-dataset-was-generated" class="block pr-1.5 text-lg md:absolute md:p-1.5 md:opacity-0 md:group-hover:opacity-100 md:right-full" href="#how-the-dataset-was-generated" > <span class="header-link"><svg class="text-gray-500 hover:text-black dark:hover:text-gray-200 w-4" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span> </a> <span> How the dataset was generated </span> </h2> <p>The dataset was produced by a script that uses the official Stack Exchange API:</p> <ul> <li>Requests top-voted mathematics questions (configurable count)</li> <li>For each question, fetches the top answer (if any)</li> <li>Cleans HTML from bodies (HTML entities unescaped and tags removed), collapses whitespace</li> <li>Produces both CSV and JSON exports</li> <li>Respects rate limits and inserts polite delays</li> </ul> <p>Notes:</p> <ul> <li>The generator script is not included in this repository. If you want to include it, add the script file (for example <code>scripts/generate_math_se_dataset.py</code>) and reference it here.</li> <li>For reproducibility, include the script, the exact arguments used, and the timestamp of generation.</li> </ul> <h2 class="relative group flex items-center"> <a id="regenerating-the-dataset" class="block pr-1.5 text-lg md:absolute md:p-1.5 md:opacity-0 md:group-hover:opacity-100 md:right-full" href="#regenerating-the-dataset" > <span class="header-link"><svg class="text-gray-500 hover:text-black dark:hover:text-gray-200 w-4" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span> </a> <span> Regenerating the dataset </span> </h2> <p>Prerequisites:</p> <ul> <li>Python 3.8+ (or compatible)</li> <li><code>requests</code> (for API calls)</li> <li>Optional: a Stack Exchange API key (recommended for higher rate limits)</li> </ul> <p>Important considerations:</p> <ul> <li>Respect Stack Exchange API rate limits; use an API key if you will fetch many pages.</li> <li>The script should include backoff/retry and delays between requests; do not parallelize requests without careful rate-limit handling.</li> <li>If exporting large datasets, consider paging and storing intermediate results.</li> </ul> <h2 class="relative group flex items-center"> <a id="data-quality--known-limitations" class="block pr-1.5 text-lg md:absolute md:p-1.5 md:opacity-0 md:group-hover:opacity-100 md:right-full" href="#data-quality--known-limitations" > <span class="header-link"><svg class="text-gray-500 hover:text-black dark:hover:text-gray-200 w-4" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span> </a> <span> Data quality & known limitations </span> </h2> <ul> <li>Bodies are cleaned of HTML but some formatting (math markup, code blocks, LaTeX) may be simplified or lost; consider preserving LaTeX if you need formula fidelity.</li> <li>Only the top answer (by score) is captured — accepted vs. highest-scored may differ; both are recorded if available.</li> <li>Potential biases:<ul> <li>Questions with higher votes and English-language questions are overrepresented if using a top-voted query.</li> <li>Highly specialized or duplicate content may appear.</li> </ul> </li> <li>Empty <code>answer_body</code> means no answer was available at scraping time.</li> <li>Some fields may contain non-ASCII characters; files are exported with UTF-8 encoding.</li> </ul> <h2 class="relative group flex items-center"> <a id="suggested-preprocessing-for-ml" class="block pr-1.5 text-lg md:absolute md:p-1.5 md:opacity-0 md:group-hover:opacity-100 md:right-full" href="#suggested-preprocessing-for-ml" > <span class="header-link"><svg class="text-gray-500 hover:text-black dark:hover:text-gray-200 w-4" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span> </a> <span> Suggested preprocessing for ML </span> </h2> <ul> <li>Deduplicate entries by <code>question_id</code>.</li> <li>Normalize or preserve LaTeX as needed (consider using a LaTeX-aware tokenizer when training models that must understand formulas).</li> <li>Truncate or chunk very long texts (both question and answer) when fitting into model context windows.</li> <li>Optionally filter by tags for domain-specific datasets (e.g., <code>algebra</code>, <code>calculus</code>, <code>probability</code>).</li> </ul> <h2 class="relative group flex items-center"> <a id="use-cases" class="block pr-1.5 text-lg md:absolute md:p-1.5 md:opacity-0 md:group-hover:opacity-100 md:right-full" href="#use-cases" > <span class="header-link"><svg class="text-gray-500 hover:text-black dark:hover:text-gray-200 w-4" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span> </a> <span> Use cases </span> </h2> <ul> <li>Training and evaluating question-answering systems and math tutoring chatbots</li> <li>Fine-tuning language models on math Q&A patterns</li> <li>Research on problem-solving strategies and reasoning in mathematics</li> <li>Building retrieval-augmented systems with real Q&A examples</li> </ul> <h2 class="relative group flex items-center"> <a id="privacy-ethics-and-policy" class="block pr-1.5 text-lg md:absolute md:p-1.5 md:opacity-0 md:group-hover:opacity-100 md:right-full" href="#privacy-ethics-and-policy" > <span class="header-link"><svg class="text-gray-500 hover:text-black dark:hover:text-gray-200 w-4" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span> </a> <span> Privacy, ethics, and policy </span> </h2> <ul> <li>The dataset contains user-contributed content under CC BY-SA; comply with the license and provide attribution.</li> <li>Do not claim the content as your own; include proper attribution and linkbacks where practical.</li> <li>Avoid publishing personally identifiable information beyond what is already publicly available on Stack Exchange.</li> </ul> <h2 class="relative group flex items-center"> <a id="citation" class="block pr-1.5 text-lg md:absolute md:p-1.5 md:opacity-0 md:group-hover:opacity-100 md:right-full" href="#citation" > <span class="header-link"><svg class="text-gray-500 hover:text-black dark:hover:text-gray-200 w-4" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span> </a> <span> Citation </span> </h2> <p>If you use this dataset in publications, we suggest citing it as:</p> <p>Furkan Nar or <a href="https://github.com/TheOfficialFurkanNar/StackMathematics" rel="nofollow">https://github.com/TheOfficialFurkanNar/StackMathematics</a>. (2026). Mathematics Stack Exchange Q&A Dataset. Retrieved from <a href="https://github.com/TheOfficialFurkanNar/StackMathematics" rel="nofollow">https://github.com/TheOfficialFurkanNar/StackMathematics</a> (data originally from mathematics.stackexchange.com; licensed CC BY-SA 4.0)</p> <h2 class="relative group flex items-center"> <a id="contact" class="block pr-1.5 text-lg md:absolute md:p-1.5 md:opacity-0 md:group-hover:opacity-100 md:right-full" href="#contact" > <span class="header-link"><svg class="text-gray-500 hover:text-black dark:hover:text-gray-200 w-4" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span> </a> <span> Contact </span> </h2> <p>Contact via: <a href="mailto:furkannar168@hotmail.com" rel="nofollow">furkannar168@hotmail.com</a> For questions about this dataset or generation script, open an issue in this repository or contact the maintainer.</p> <h2 class="relative group flex items-center"> <a id="community--support" class="block pr-1.5 text-lg md:absolute md:p-1.5 md:opacity-0 md:group-hover:opacity-100 md:right-full" href="#community--support" > <span class="header-link"><svg class="text-gray-500 hover:text-black dark:hover:text-gray-200 w-4" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span> </a> <span> Community & Support </span> </h2> <p>Join the community to ask questions, discuss the dataset, and get help:</p> <ul> <li>Discord: <a href="https://discord.gg/dcjh8S5H" rel="nofollow">https://discord.gg/dcjh8S5H</a></li> <li></li> </ul>