このリポジトリは、学校の授業の一環として取り組んでいる 軽量の数学LLM(大規模言語モデル) の作成プロジェクトです。 四則演算などの基本的な演算から始め、段階的にモデルの数学的能力を高めることを目的としています。
以下のような構成のファイルが含まれています:
-
📂 学習用データセット(JSONL形式) 例:
data_set/math_model_data_expr_answer.jsonl -
🛠 トークナイザー訓練用
.txt変換スクリプトとその生成物 例:jsonl_to_txt.py、math_tokenizer_corpus_expr_answer.txt、data_set/math_tokenizer_train_data3.txt -
🧠 SentencePiece を使ったトークナイザー訓練スクリプト 例:
tokenizer_train.py -
トークナイザーファイル 例:
math_tokenizer_v3.model -
🐍 PyTorch による LLM 訓練スクリプト 例:
train_math_llm.py -
🔢 SymPy を用いたデータセット生成/データ整形スクリプト 例:
scripts/generate_data_sympy1.py、data_formatting1.py、combine_data1.py -
依存関係の管理 例:
requirements.txt
学習データセットはすべて SymPy を用いて自動生成しています。 訓練したモデルは Hugging Face Hub に一部アップロードしています。
- このプロジェクトは
sentencepieceの使用のため、Python 3.12.7 で開発・動作確認を行っています。 sentencepieceが Python 3.13 系に対応していないため、Python 3.12 系の使用を推奨しています。- それ以外のライブラリは他のバージョンでも動作する可能性があります。
このプロジェクトは仮想環境内で動作させることを推奨しています。以下の手順でセットアップできます:
python -m venv .venv
.venv\Scripts\activatepython3 -m venv .venv
source .venv/bin/activatepip install -r requirements.txtPython 3.12.x を推奨(特に
sentencepieceが Python 3.13 非対応のため) 上記で.venvという仮想環境名を使っていますが、任意の名前でもかまいません。
-
📄 データ生成用スクリプト(Google Colab)
Google Colab Link
※リポジトリ内にも生成スクリプトを同梱しています。 -
📦 モデルファイル(Hugging Face)
https://huggingface.co/nobuchiyo345/my-math-llm-large-no-latex
-
UIは Flask で構築しており、
app2.pyなどを実行することで起動します。 -
HTML / CSS / JavaScript ファイルは
static/とtemplates/に含まれています。 -
app2.py内では以下のように、使用するモデルとトークナイザーのファイルパスをハードコードしています:PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__)) MODEL_DIR_PATH = os.path.join(PROJECT_ROOT, "output_model", "lightweight_math_llm") TOKENIZER_FILE_PATH = os.path.join(PROJECT_ROOT, "output_model", "math_tokenizer_v3.model")
そのため、使用するモデルやトークナイザーのファイル名・フォルダ構成が異なる場合は、これらのパスを手動で書き換えてください。
-
起動方法(VSCode のターミナルなどで):
python app2.py
-
起動後、ブラウザで
http://127.0.0.1:5000/を開きます。
日本語版(注意書き) ファイルやコードはまだ完全に整理されておらず、わかりにくい部分も多く含まれています。 不明点や使い方については、AIアシスタントに問い合わせていただくと解説が得られる場合があります。
This repository is part of a school project focused on building a lightweight mathematical language model (LLM). The training begins with basic arithmetic operations and gradually expands to more advanced topics.
This repository includes the following components:
-
📂 Training datasets in JSONL format Example:
data_set/math_model_data_expr_answer.jsonl -
🔄 Scripts for converting datasets into
.txtformat for tokenizer training Example:jsonl_to_txt.py,math_tokenizer_corpus_expr_answer.txt,data_set/math_tokenizer_train_data3.txt -
🧠 Tokenizer training scripts using SentencePiece Example:
tokenizer_train.py -
Tokenizer files Example:
math_tokenizer_v3.model -
🐍 LLM training scripts using PyTorch Example:
train_math_llm.py -
🔢 Dataset generation and formatting scripts using SymPy Example:
scripts/generate_data_sympy1.py,data_formatting1.py,combine_data1.py -
Dependency management Example:
requirements.txt
All training datasets are automatically generated using SymPy. Some trained models are uploaded to Hugging Face Hub.
- This project is developed and tested with Python 3.12.7 due to usage of
sentencepiece. sentencepiecedoes not support Python 3.13 series, so Python 3.12.x is recommended.- Other libraries may work with different Python versions.
It is recommended to run this project inside a Python virtual environment. Follow these steps:
python -m venv .venv
.venv\Scripts\activatepython3 -m venv .venv
source .venv/bin/activatepip install -r requirements.txtRecommended Python version: 3.12.x (due to
sentencepiecenot yet supporting 3.13) You can use any name for the virtual environment;.venvis just a convention.
-
📄 Google Colab for dataset generation
https://colab.research.google.com/drive/1_QzZUL_T2HfS5_iuz7xG23h5hf7p2fC7?usp=sharing -
📦 Model files (Hugging Face)
https://huggingface.co/nobuchiyo345/my-math-llm-large-no-latex
-
The UI is built with Flask and can be started by running
app2.pyor similar files. -
HTML / CSS / JavaScript files are included in the
static/andtemplates/folders. -
In
app2.py, the model and tokenizer file paths are hardcoded as follows:PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__)) MODEL_DIR_PATH = os.path.join(PROJECT_ROOT, "output_model", "lightweight_math_llm") TOKENIZER_FILE_PATH = os.path.join(PROJECT_ROOT, "output_model", "math_tokenizer_v3.model")
Therefore, if your model or tokenizer filenames or folder structure differ, please manually edit these paths.
-
How to start (in VSCode terminal or command line):
python app2.py
-
Then open your browser and go to
http://127.0.0.1:5000/.
English version (Note) The files and code are not yet fully organized and may contain parts that are hard to understand. If you have any questions or need help using the code, you may ask AI assistants for explanations.
以下は実際に動かしたときの画面例です。
