o
    	Ti                     @   s   d dl Z d dlmZmZ d dlmZ d dlmZ d dlm	Z	 d dl
mZ d dlmZ eG dd	 d	Zd
d ZedZedkrteeZe d  Ze	dddZejeg dejdZejdddZejrveej ejejdd dS dS dS )    N)	dataclassfield)chain)Optional)load_dataset)	ModelCard)HfArgumentParserc                   @   s^   e Zd ZU dZedddidZeed< edddidZe	ed	< ed
ddidZ
ee ed< d
S )ScriptArgumentsa  
    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____doc__r   r   bool__annotations__r   strr   r   int r   r   S/home/ubuntu/.local/lib/python3.10/site-packages/examples/datasets/math_shepherd.pyr	      s   
 r	   c                    s   d  dddd tdD }t fdd|D s J  fdd|D }fd	dttd
g|t|d gD }|d d }|d
 }|dd  }tdd |D sXJ dd |D }|drk|dd  }nLd|v r|d\}}d| }| g| }n5d|v r|d\}}d| }| g| }nd|v r|d\}}|d }| g| }nt	d| | }t
|t
|ksJ |||dS )Ninputu   ки   ⶻc                 S   s   g | ]}|  qS r   )start).0mr   r   r   
<listcomp>:   s    z#process_example.<locals>.<listcomp>c                 3   s     | ]} d  | dv V  qdS )label)+-Nr   r   idxexampler   r   	<genexpr>=   s    z"process_example.<locals>.<genexpr>c                    s   g | ]
} d  | dkqS )r    r!   r   r#   r%   r   r   r   @       c                    s   g | ]
\}} || qS r   r   )r   ij)inputsr   r   r   C   r(   r      c                 s   s    | ]}| d V  qdS )r   N)
startswithr   
completionr   r   r   r'   M   s    c                 S   s   g | ]
}|d d   qS )r-   N)stripr/   r   r   r   r   N   r(   )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allzipr   r.   splitr1   
ValueErrorlen)r&   indexesr6   stepsr4   r5   
first_stepr   )r&   r+   r   process_example5   s<   (rB   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)r8   dataclassesr   r   	itertoolsr   typingr   datasetsr   huggingface_hubr   transformersr   r	   rB   
model_cardr   parserparse_args_into_dataclassesscript_argsrK   mapr   train_test_splitr   r   r   r   r   r   <module>   s4   J