Home

Awesome

Overview

This repository contains resources for accessing the official benchmarks, codes, and checkpoints of the paper: "Breaking Language Barriers in Multilingual Mathematical Reasoning: Insights and Observations".

This work pioneers exploring and building powerful Multilingual Math Reasoning (xMR) LLMs. To accomplish this, we make the following works:

News

πŸ™πŸ™MathOctopus πŸ™πŸ™

This repo contains the code, data, and models for "Breaking Language Barriers in Multilingual Mathematical Reasoning: Insights and Observations"

<div align="center"> πŸ”₯ πŸ”₯ πŸ”₯ Check out our <a href = "https://mathoctopus.github.io/">[Project Page]</a> for more results and analysis! </div> <br> <div align="center"> <img src="new_model.png" width="90%" title="Introduction Figure"> </div>

Official Website

πŸ€—Datasets

Our collected MGSM8KInstruct training dataset and MSVAMP testset both contain 10 languages:

MGSM8KInstruct

Training DatasetEnSwZhBnDeEsFrJaRuThOverall
MGSM8KInstruct747374727466653974667470746974717361747373.6K

MSVAMP

Test DatasetEnSwZhBnDeEsFrJaRuThOverall
MSVAMP100010001000100010001000100010001000100010K

Usage

Our dataset and models are available at Huggingface!

πŸ¦‘πŸ¦‘πŸ¦‘

πŸ€— MGSM8KInstruct_Parallel Dataset

πŸ€— MGSM8KInstruct_Cross Dataset

πŸ€— MSVAMP Dataset

πŸ€—Models

Base Model: LLamaParallel-TrainingCross-Training
7B-LLaMA 2πŸ™ MathOctopus-Parallel-7BπŸ™ MathOctopus-Cross-7B
πŸ™MathOctopus-Parallel-xRFT-7BπŸ™MathOctopus-Cross-xRFT-7B
Mistral-7BπŸ™MathOctopus-Parallel-7B
13B-LLaMA 2πŸ™ MathOctopus-Parallel-13BπŸ™ MathOctopus-Cross-13B
πŸ™MathOctopus-Parallel-xRFT-13BπŸ™MathOctopus-Cross-xRFT-13B
33B-LLaMA 1πŸ™ MathOctopus-Parallel-33BπŸ™ MathOctopus-Cross-33B
70B-LLaMA 2Coming soon!Coming Soon!

*-Parallel refers to our model trained with the parallel-training strategy.

*-Cross refers to our model trained with cross-training strategy.

*-xRFT means we train the model with multilingual rejection sampling.

Results

We evaluate our models in two datasets: MGSM and MSVAMP

Overall Results on MGSM

7B ModelEnSwZhBnDeEsFrJaRuThOverall
MathOctopus<sup>C</sup>52.023.631.618.838.039.236.427.233.621.632.2
xRFT-MathOctopus<sup>C</sup>51.224.033.218.836.041.237.629.636.425.233.3
MathOctopus<sup>P</sup>-LoRA30.415.223.610.422.824.826.418.022.014.820.8
MathOctopus<sup>P</sup>52.439.238.428.844.842.443.636.039.634.440.0
xRFT-MathOctopus<sup>P</sup>54.838.445.233.243.645.238.035.648.436.441.9
MathOctopus<sup>P</sup>-Mistral58.451.651.6445053.247.24849.648.850.2
<p></p >
13B ModelEnSwZhBnDeEsFrJaRuThOverall
MathOctopus<sup>C</sup>56.427.239.224.047.649.647.640.442.024.839.9
xRFT-MathOctopus<sup>C</sup>53.628.045.221.248.046.446.035.245.628.839.8
MathOctopus<sup>P</sup>53.242.848.835.244.448.048.443.247.646.845.8
xRFT-MathOctopus<sup>P</sup>51.646.051.242.049.253.249.639.647.646.047.6
<p></p >
30-34B ModelEnSwZhBnDeEsFrJaRuThOverall
MathOctopus<sup>C</sup>55.624.436.019.240.451.244.427.237.221.635.7
xRFT-MathOctopus<sup>C</sup>53.627.634.419.247.247.644.830.838.822.836.7
MathOctopus<sup>P</sup>56.446.852.035.247.253.248.039.245.641.246.5
xRFT-MathOctopus<sup>P</sup>51.647.252.437.651.252.844.441.650.047.647.6

Overall Results on MSVAMP

7B ModelEnSwZhBnDeEsFrJaRuThOverall
MathOctopus<sup>C</sup>49.236.643.630.248.646.846.442.546.734.042.5
xRFT-MathOctopus<sup>C</sup>49.937.743.332.946.547.647.342.746.636.243.1
MathOctopus<sup>P</sup>-LoRA30.415.223.610.422.824.826.418.022.014.820.8
MathOctopus<sup>P</sup>46.540.142.529.143.545.446.042.545.435.741.7
xRFT-MathOctopus<sup>P</sup>46.842.343.232.843.144.545.343.242.140.542.4
MathOctopus<sup>P</sup>-Mistral49.741.243.136.746.4474941.54440.243.9
<p></p >
13B ModelEnSwZhBnDeEsFrJaRuThOverall
MathOctopus<sup>C</sup>56.640.449.030.350.954.254.746.352.435.747.1
xRFT-MathOctopus<sup>C</sup>52.941.949.234.150.552.851.545.850.235.746.5
MathOctopus<sup>P</sup>50.743.442.631.848.449.450.641.146.939.344.4
xRFT-MathOctopus<sup>P</sup>44.643.446.434.247.748.249.943.148.239.544.5
<p></p >
30-34B ModelEnSwZhBnDeEsFrJaRuThOverall
MathOctopus<sup>C</sup>51.542.146.223.250.552.152.942.250.533.444.5
xRFT-MathOctopus<sup>C</sup>48.142.843.623.348.750.048.943.444.635.542.9
MathOctopus<sup>P</sup>56.446.852.035.247.253.248.039.245.641.246.5
xRFT-MathOctopus<sup>P</sup>48.042.346.136.247.548.548.345.847.241.245.1

MathOctopus in English

ModelsGSM8KSVAMP
LLaMA 2-7B42.438.3
MathOctopus<sup>P</sup>-7B49.346.8
MathOctopus<sup>C</sup>-7B50.849.3
MathOctopus<sup>P</sup>-Mistral57.149.7
LLaMA 2-13B51.050.9
MathOctopus<sup>P</sup>-13B55.552.1
MathOctopus<sup>C</sup>-13B56.656.6
LLaMA 1-33B50.049.0
MathOctopus<sup>P</sup>-33B56.052.5
MathOctopus<sup>C</sup>-33B53.751.5

Table of Contents

Introduction

We introduce πŸ™ MathOctopus, a series of open-source large language models (LLMs) specifically tailored for multilingual math problem-solving. The MathOctopus models are trained on πŸ€— MGSM8KInstruct Dataset, encompassing ten distinct languages. MathOctopus notably outperforms conventional open-source LLMs and exhibits superiority over ChatGPT in few-shot scenarios.

Installation

Clone this repository and install the required packages:

git clone https://github.com/nuochenpku/MathOctopus.git
cd MathOctopus
pip install -r requirements.txt

Training and Inference

Data Loading

Run the following command to preprocess the data from our Instruct in the Parallel-training setting:

from datasets import load_dataset

dataset = load_dataset("https://huggingface.co/datasets/Mathoctopus/GSM8KInstruct_Parallel")

Quick Start

To play with our model, run:

# Use a pipeline as a high-level helper
from transformers import pipeline

pipe = pipeline("text-generation", model="Mathoctopus/Parallel_7B")

alpaca_template = "Below is an instruction that describes a task. Write a response that appropriately completes the request in {lang}. Please answer in {lang}. \n### Instruction:\n{query}\n\n### Response:"

query = "Janet's ducks lay 16 eggs per day. She eats three for breakfast every morning and bakes muffins for her friends every day with four. She sells the remainder at the farmers' market daily for $2 per fresh duck egg. How much in dollars does she make every day at the farmers' market?"



### You can let MathOctopus output in a specific language.
language = English

input = alpaca_template.format(lang= language, query = query)

output = pipeline(input)[0]['generated_text']
print(output)

Evaluation

To replicate the experimental results of MGSM in our paper, run:

CUDA_VISIBLE_DEVICES=1 python3  generate_and_eval.py --model_path $MODEL_PATH \
    --streategy Parallel \
    --batch_size 32 \
&> $MODEL_PATH/mgsm_Parallel_testbf16.log 

To replicate the experimental results of MSVAMP in our paper, run:


CUDA_VISIBLE_DEVICES=1 python3  svamp_test.py --model_path $MODEL_PATH \
    --streategy Parallel \
    --batch_size 32 \
&> $MODEL_PATH/svamp_parallel_testbf16.log &

--strategy should be Parallel or Cross. If you want to test in a specific language, you can add --lang_only $lang.

Large-scale Evaluation

If you have four GPUs, you can get test models with parallel/cross strategy in two datasets via:


bash test_xmath.sh

Fine-tuning

To train the 7B/13B model, run:

cd step1_supervised_finetuning
bash training_scripts/single_node/run_llama2.sh

which consists of the following commands:


#!/bin/bash
# Copyright (c) Microsoft Corporation.
# SPDX-License-Identifier: Apache-2.0
# local/xjsonfile/rftV2
# DeepSpeed Team
OUTPUT=$1
ZERO_STAGE=$2
MODEL_PATH=$3
DATA_PATH=$4
if [ "$OUTPUT" == "" ]; then
    OUTPUT=./OUTPUT
fi
if [ "$ZERO_STAGE" == "" ]; then
    ZERO_STAGE=3
fi
mkdir -p $OUTPUT

deepspeed --include localhost:0,1,2,3 --master_port=29500 main.py  \
   --data_path $DATA_PATH \
   --data_split 10,0,0 \
   --model_name_or_path $MODEL_PATH \
   --per_device_train_batch_size 8 \
   --per_device_eval_batch_size 8 \
   --max_seq_len 512 \
   --learning_rate 2e-5  \
   --weight_decay 0. \
   --num_train_epochs 3  \
   --gradient_accumulation_steps 4 \
   --lr_scheduler_type cosine \
   --num_warmup_steps 0 \
   --seed 1234 \
   --gradient_checkpointing \
   --zero_stage $ZERO_STAGE \
   --deepspeed \
   --output_dir $OUTPUT \
   &> $OUTPUT/training.log

To train the 34B/70B model, run:

cd step1_supervised_finetuning
bash training_scripts/single_node/run_llama_30b.sh

Citation

Please cite our paper if you use our data, model or code. Please also kindly cite the original dataset papers.

@misc{chen2023breaking,
      title={Breaking Language Barriers in Multilingual Mathematical Reasoning: Insights and Observations}, 
      author={Nuo Chen and Zinan Zheng and Ning Wu and Linjun Shou and Ming Gong and Yangqiu Song and Dongmei Zhang and Jia Li},
      year={2023},
      eprint={2310.20246},
      archivePrefix={arXiv},
      primaryClass={cs.CL}
}