
    h                        S SK r S SKJrJr  S SKJr  S SKJr  S SKJ	r	  S SK
Jr  S SKJr  \ " S S	5      5       rS
 r\" S5      r\S:X  a  \" \5      r\R'                  5       S    r\	" SSS9r\R-                  \/ SQ\R.                  S9r\R1                  SSS9r\R2                  (       a6  \R3                  \R4                  5        \R3                  \R4                  SS9  ggg)    N)	dataclassfield)chain)Optional)load_dataset)	ModelCard)HfArgumentParserc                   t    \ rS rSr% Sr\" SSS0S9r\\S'   \" SSS	0S9r	\
\S
'   \" SSS0S9r\\   \S'   Srg)ScriptArguments   a  
Arguments for the script.

Args:
    push_to_hub (`bool`, *optional*, defaults to `False`):
        Whether to push the dataset to the Hugging Face Hub.
    repo_id (`str`, *optional*, defaults to `"trl-lib/math_shepherd"`):
        Hugging Face repository ID to push the dataset to.
    dataset_num_proc (`int` or `None`, *optional*, defaults to `None`):
        Number of workers to use for dataset processing.
Fhelpz4Whether to push the dataset to the Hugging Face Hub.)defaultmetadatapush_to_hubztrl-lib/math_shepherdz2Hugging Face repository ID to push the dataset to.repo_idNz0Number of workers to use for dataset processing.dataset_num_proc )__name__
__module____qualname____firstlineno____doc__r   r   bool__annotations__r   strr   r   int__static_attributes__r       Y/home/james-whalen/.local/lib/python3.13/site-packages/examples/datasets/math_shepherd.pyr   r      si    
 PQK  'NOGS  ',LM'hsm r   r   c                   ^  T S   R                  SS5      n[        R                  " SU5       Vs/ s H  o"R                  5       PM     nn[	        U 4S jU 5       5      (       d   eU Vs/ s H  nT S   U   S:H  PM     nn[        [        S/U5      [        US /5      5       VVs/ s H	  u  pgXU PM     nnnUS S nUS   n	US	S  n
[	        S
 U
 5       5      (       d   eU
 Vs/ s H  oS	S  R                  5       PM     n
nU	R                  S5      (       a  US	S  nOSU	;   a-  U	R                  S5      u  pSU-   nUR                  5       /U
-   n
OtSU	;   a-  U	R                  S5      u  pSU-   nUR                  5       /U
-   n
OASU	;   a-  U	R                  S5      u  pU	S-   n	UR                  5       /U
-   n
O[        SU	 35      eU	R                  5       n	[        U
5      [        U5      :X  d   eXUS.$ s  snf s  snf s  snnf s  snf )Ninputu   ки   ⶻc              3   :   >#    U  H  nTS    U   S;   v   M     g7f)label)+-Nr   ).0idxexamples     r   	<genexpr>"process_example.<locals>.<genexpr>=   s      Fgsww$
2gs   r$   r%   r      c              3   B   #    U  H  oR                  S 5      v   M     g7f)r"   N)
startswith)r'   
completions     r   r*   r+   M   s     Jk
$$U++ks   )z	Mr. RockyParkerzWhat is the smallest positivez	 The MythzLet $\mathbf{a}$zFind the arithmeticzDetermine an ordered pairzDetermine the ordered pairz"At the Quill and Scroll stationeryzRound to the nearestzCalculate $\sqrt{10p}zSimplify $\sqrt{28x}zStep 1:zstep 1:?zPrompt can't be processed: )promptcompletionslabels)replacerefinditerstartallzipr   stripr/   split
ValueErrorlen)r)   inputsmindexesr(   r5   ijstepsr3   r4   r0   
first_steps   `            r   process_examplerG   5   s@   W%%fe4F #%++eV"<="<Qwwy"<G= FgFFFFF 7>>gsggs#s*gF> &)sG)<eGdV>T%UV%UTQVa[%UEV #2JE 1XF)K JkJJJJJ<GHKjab>'')KKH 	
 "  
f	#\\)4+
!'')*[8	f	#\\)4+
!'')*[8	#\\#.#!'')*[86vh?@@ \\^F {s6{***FKKE > ? W Is   G6+G;'H &Ha  
---
tags: [trl]
---

# Math-Shepherd Dataset

## Summary

The Math-Shepherd dataset is a processed version of [Math-Shepherd dataset](peiyi9979/Math-Shepherd), designed to train models using the [TRL library](https://github.com/huggingface/trl) for stepwise supervision tasks. It provides step-by-step solutions to mathematical problems, enabling models to learn and verify each step of a solution, thereby enhancing their reasoning capabilities.

## Data Structure

- **Format**: [Standard](https://huggingface.co/docs/trl/main/dataset_formats#standard)
- **Type**: [Stepwise supervision](https://huggingface.co/docs/trl/main/dataset_formats#stepwise-supervision)

Columns:
- `"prompt"`: The problem statement.
- `"completions"`: A list of reasoning steps generated to solve the problem.
- `"labels"`: A list of booleans or floats indicating the correctness of each corresponding reasoning step.

This structure allows models to learn the correctness of each step in a solution, facilitating improved reasoning and problem-solving abilities.

## Generation script

The script used to generate this dataset can be found [here](https://github.com/huggingface/trl/blob/main/examples/datasets/math_shepherd.py).
__main__zpeiyi9979/Math-Shepherdtrain)r=   )r!   r$   task)remove_columnsnum_procg?*   )	test_sizeseeddataset)	repo_type)r7   dataclassesr   r   	itertoolsr   typingr   datasetsr   huggingface_hubr   transformersr	   r   rG   
model_cardr   parserparse_args_into_dataclassesscript_argsrP   mapr   train_test_splitr   r   r   r   r   <module>r^      s    
 (   ! % )   6GLT   
8 zo.F446q9K4GDGkk1--  G
 &&B&?GK//0{22iH  r   