DarkhanOmirbay/ainn-final

0

stars

2

commits

Jupyter Notebook

primary language

May 11, 2026

updated

README

Variant 12 — Fine-tuning LLM for Business Letters (Russian)

Subject: Artificial Intelligence and Neural Networks
Group: AAI-2502M
Authors: Darhan Omirbay, Alisher Khairullin


Overview

Fine-tuned RuGPT-3 Large (760M parameters) on a synthetic corpus of 5,500 Russian business letter pairs using LoRA via transformers + peft. The model generates formal business letter replies from an incoming letter + instruction prompt.


Project Structure

variant12/
├── ainn_final_project (1).ipynb   # Full pipeline: data gen → training → eval
├── app.py                          # Streamlit demo app
├── data/
│   ├── train.json                  # 5,000 training pairs
│   ├── val.json                    # 250 validation pairs
│   └── test.json                   # 250 test pairs
├── lora_adapter/                   # Trained LoRA adapter (5k dataset)
├── lora_adapter_500/               # Experimental adapter (500 samples)
└── pyproject.toml

Dataset

5,500 synthetic Alpaca-style pairs generated with Python templates.

SplitSize
Train5,000
Val250
Test250

5 letter categories (equal distribution):

  • запрос_информации — information requests
  • жалоба — complaints
  • коммерческое_предложение — commercial proposals
  • уведомление — notifications
  • согласование — approvals

3 response styles per category: вежливое · краткое · настойчивое

Format (Alpaca-style):

{
  "instruction": "Составьте вежливый профессиональный ответ...",
  "input": "Уважаемые коллеги,\nПрошу предоставить...",
  "output": "Уважаемый(-ая) А.В. Петрова,\n\nБлагодарим...",
  "category": "запрос_информации",
  "style": "вежливое"
}

Model & Training

Base model: ai-forever/rugpt3large_based_on_gpt2 (760M params)
Method: LoRA (FP16) via peft + transformers
Training time: 71.7 minutes (Apple MPS)

LoRA Configuration

ParameterValue
lora_r8
lora_alpha16
lora_dropout0.05
Target modulesc_attn
Trainable params1,179,648 (0.15%) of 761M

Training Hyperparameters

ParameterValue
Epochs3
Learning rate2×10⁻⁴
Batch size (effective)16 (4 × grad_accum=4)
Max sequence length256
LR schedulercosine
PrecisionFP16

How to Run

1. Install dependencies

pip install transformers peft datasets accelerate torch streamlit
# or with uv:
uv sync

2. Launch the Streamlit demo

streamlit run app.py

The app loads the LoRA adapter from ./lora_adapter/ and provides an interactive UI to generate business letter replies.

3. Reproduce training / evaluation

Open ainn_final_project (1).ipynb and run all cells sequentially.


Expert Evaluation (30 test examples)

Evaluated on 30 samples from data/test.json covering all category × style combinations. Scoring is automated via a formal-marker rubric (see notebook).

CriterionMeanScale
Style (деловой стиль)4.501–5
Relevance (релевантность)4.571–5
No hallucinations (отсутствие галлюцинаций)4.771–5
Overall4.611–5

Complaints (жалоба) scored slightly lower (assertive emotional tone is harder to model with a 760M parameter base).


Inference Speed

Measured with 10 greedy-decoding runs on a fixed benchmark letter.

MetricValue
Avg latency~5–15 sec (CPU/MPS)
Tokens/secmeasured in notebook

Run the benchmark cell in the notebook to get exact numbers for your hardware.


Libraries


References

Contributors

DarkhanOmirbay/ainn-final

0

stars

2

commits

Jupyter Notebook

primary language

May 11, 2026

updated

README

Variant 12 — Fine-tuning LLM for Business Letters (Russian)

Subject: Artificial Intelligence and Neural Networks
Group: AAI-2502M
Authors: Darhan Omirbay, Alisher Khairullin


Overview

Fine-tuned RuGPT-3 Large (760M parameters) on a synthetic corpus of 5,500 Russian business letter pairs using LoRA via transformers + peft. The model generates formal business letter replies from an incoming letter + instruction prompt.


Project Structure

variant12/
├── ainn_final_project (1).ipynb   # Full pipeline: data gen → training → eval
├── app.py                          # Streamlit demo app
├── data/
│   ├── train.json                  # 5,000 training pairs
│   ├── val.json                    # 250 validation pairs
│   └── test.json                   # 250 test pairs
├── lora_adapter/                   # Trained LoRA adapter (5k dataset)
├── lora_adapter_500/               # Experimental adapter (500 samples)
└── pyproject.toml

Dataset

5,500 synthetic Alpaca-style pairs generated with Python templates.

SplitSize
Train5,000
Val250
Test250

5 letter categories (equal distribution):

  • запрос_информации — information requests
  • жалоба — complaints
  • коммерческое_предложение — commercial proposals
  • уведомление — notifications
  • согласование — approvals

3 response styles per category: вежливое · краткое · настойчивое

Format (Alpaca-style):

{
  "instruction": "Составьте вежливый профессиональный ответ...",
  "input": "Уважаемые коллеги,\nПрошу предоставить...",
  "output": "Уважаемый(-ая) А.В. Петрова,\n\nБлагодарим...",
  "category": "запрос_информации",
  "style": "вежливое"
}

Model & Training

Base model: ai-forever/rugpt3large_based_on_gpt2 (760M params)
Method: LoRA (FP16) via peft + transformers
Training time: 71.7 minutes (Apple MPS)

LoRA Configuration

ParameterValue
lora_r8
lora_alpha16
lora_dropout0.05
Target modulesc_attn
Trainable params1,179,648 (0.15%) of 761M

Training Hyperparameters

ParameterValue
Epochs3
Learning rate2×10⁻⁴
Batch size (effective)16 (4 × grad_accum=4)
Max sequence length256
LR schedulercosine
PrecisionFP16

How to Run

1. Install dependencies

pip install transformers peft datasets accelerate torch streamlit
# or with uv:
uv sync

2. Launch the Streamlit demo

streamlit run app.py

The app loads the LoRA adapter from ./lora_adapter/ and provides an interactive UI to generate business letter replies.

3. Reproduce training / evaluation

Open ainn_final_project (1).ipynb and run all cells sequentially.


Expert Evaluation (30 test examples)

Evaluated on 30 samples from data/test.json covering all category × style combinations. Scoring is automated via a formal-marker rubric (see notebook).

CriterionMeanScale
Style (деловой стиль)4.501–5
Relevance (релевантность)4.571–5
No hallucinations (отсутствие галлюцинаций)4.771–5
Overall4.611–5

Complaints (жалоба) scored slightly lower (assertive emotional tone is harder to model with a 760M parameter base).


Inference Speed

Measured with 10 greedy-decoding runs on a fixed benchmark letter.

MetricValue
Avg latency~5–15 sec (CPU/MPS)
Tokens/secmeasured in notebook

Run the benchmark cell in the notebook to get exact numbers for your hardware.


Libraries


References

Contributors

Languages

Jupyter Notebook

77.9%

Python

11.3%

TeX

10.8%