MCPcopy Index your code
hub / github.com/HongyuanLuke/frequencylaw

github.com/HongyuanLuke/frequencylaw @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
36 symbols 144 edges 12 files 3 documented · 8%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

README.md

FrequencyLaw: Textual Frequency Law on Large Language Models

Project Introduction

This project is the official code repository accompanying the paper Textual Frequency Law on Large Language Models. It implements the three core methods proposed in the paper: Textual Frequency Law (TFL), Textual Frequency Distillation (TFD), and Curriculum Textual Frequency Training (CTFT), verifying the optimization effect of textual frequency on Large Language Models (LLMs) in Mathematical Reasoning (MR) and Machine Translation (MT) tasks.

Based on GSM8K (Mathematical Reasoning) and FLORES-200 (Machine Translation), the project constructs the Textual Frequency Paired Dataset (TFPD). It provides end-to-end code for frequency calculation, dataset processing, model fine-tuning and evaluation, enabling the reproduction of the experimental conclusions in the paper.

Environment Setup

Dependency Installation

pip install -r requirements.txt

If requirements.txt is not generated, run the following command to create it:

pip freeze > requirements.txt

Core Dependencies

  • Python 3.9+
  • PyTorch 2.0+
  • Hugging Face Transformers/Datasets/Accelerate
  • NumPy/Pandas (Data Processing)
  • LoRA (peft): For lightweight model fine-tuning

Project Structure

frequencyclaw/
├── datasets/                # Textual Frequency Paired Dataset (TFPD)
│   ├── csqa-highfrequency.txt  # CSQA high-frequency math problems
│   ├── csqa-lowfrequency.txt   # CSQA low-frequency math problems
│   ├── gsm8k-highfrequency.txt # GSM8K high-frequency math problems
│   └── gsm8k-lowfrequency.txt  # GSM8K low-frequency math problems
├── MT-SFT/                  # Machine Translation (MT) Fine-tuning Module (CTFT)
│   ├── data/                # MT task data storage directory
│   ├── merge.py             # Data merging script
│   └── sort_frequency.py    # Frequency sorting tool
│   └── runmodel.py          # Run the fine-tuned model weights

├── frequency.py             # Core script for textual frequency calculation (TFL implementation)
├── newfrequency.py          # Re-calculate frequency after TFD distillation
├── get_correct_answer.py    # Mathematical reasoning answer verification
├── issame.py                # Semantic consistency check (dataset construction)
├── judge.py                 # Automatic evaluation of model outputs
├── readdata.py              # Dataset loading utility
├── rephrase.py              # Text paraphrasing generation (high/low frequency)
├── reply_mr.py              # Mathematical Reasoning (MR) model inference
├── reply_mt.py              # Machine Translation (MT) model inference
└── README.md                # Project documentation

Community Implementations

  • AdamOpt – Turn "Prompt Alchemy" into science. Boost LLM performance 10-20% with zero cost and zero training. Thanks to @happyii for the outstanding work.

Core symbols most depended-on inside this repo

clean_and_tokenize
called by 4
newfrequency.py
clean_and_tokenize
called by 3
MT-SFT/sort_frequency.py
calculate_weighted_score_new
called by 3
MT-SFT/sort_frequency.py
load_and_normalize_corpus
called by 2
newfrequency.py
process_questions
called by 2
reply_mr.py
compare_numbers
called by 2
judge.py
geometric_mean
called by 2
MT-SFT/sort_frequency.py
align_and_merge
called by 1
newfrequency.py

Shape

Function 33
Method 2
Class 1

Languages

Python100%

Modules by API surface

newfrequency.py6 symbols
reply_mr.py5 symbols
MT-SFT/sort_frequency.py5 symbols
reply_mt.py4 symbols
frequency.py4 symbols
MT-SFT/runmodel.py4 symbols
rephrase.py3 symbols
issame.py3 symbols
judge.py2 symbols

For agents

$ claude mcp add frequencylaw \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact