Skip to main content
Cookbook & Real-World Examples
Document Summarizer
Cookbook Blueprint

Document Summarizer

Fine-tune a long-context language model to distill complex technical reports and whitepapers into standardized, executive-ready key findings.

What You'll Build

  • A localized Qwen2.5-3B or 7B model tuned for structured 8K+ context processing.
  • Memory-optimized training utilizing FlashAttention-2 and gradient checkpointing on 12GB–16GB VRAM GPUs.
  • Evaluation suites that verify factual coverage, bullet-count constraints, and thesis statement clarity.
  • Instant local serving via Ollama for seamless internal document pipeline integration.

Step 1: Prepare Long-Form Training Data

Executive Brief Training Dataset

2 sample rows · JSONL format · CC-BY-4.0 · pre-validated for moro data build

Download .jsonl

Format training documents into structured prompt/response JSONL conversation pairs:

cat > doc_summaries.jsonl << 'EOF'
{"messages": [{"role": "system", "content": "You are an executive intelligence summarizer. Given a lengthy technical document, produce a structured executive brief with: 1) Thesis statement, 2) Key technical takeaways (3-5 bullets), and 3) Actionable recommendation."}, {"role": "user", "content": "Summarize the database latency report: During Q3, our primary PostgreSQL cluster experienced periodic latency spikes reaching 1,850ms during peak batch windows..."}, {"role": "assistant", "content": "**Thesis**: Database latency spikes and webhook cascading failures stem from unindexed ledger queries and lack of application-level connection pooling.

**Key Findings**:
- Latency spikes peaked at 1,850ms during batch processing windows.
- Unindexed queries exhausted the 800-connection database ceiling.
- Read replicas successfully offloaded analytics traffic.

**Recommendation**: Deploy PgBouncer connection pooling and add foreign key migration indexes."}]}
EOF
  

Step 2: Scaffolding & moro.yaml Long-Context Setup

moro init doc-summarizer --template document-summarizer
cd doc-summarizer
cp ../doc_summaries.jsonl data/raw/
  

In moro.yaml, expand the maximum sequence length and enable gradient checkpointing:

name: "doc-summarizer"
version: "1.0.0"

dataset:
  source: ./data/raw/doc_summaries.jsonl
  format: jsonl
  max_seq_length: 8192                # Extended 8K context window

model:
  base: "Qwen/Qwen2.5-3B-Instruct"
  quantization: "nf4"

training:
  learning_rate: 2.0e-4
  micro_batch_size: 1
  gradient_accumulation_steps: 16
  gradient_checkpointing: true        # Saves up to 60% activation memory
  auto_heal: true
  

Step 3: VRAM Hardware Recipe & Training

# 1. Compile long-form data
moro data build

# 2. Check pre-flight VRAM budget at 8192 sequence length
moro recipe suggest --model 3b --seq 8192

# 3. Start training run
moro train
  

Step 4: Executive Brief Evaluation Suite

cat > eval/summary_eval.yaml << 'EOF'
name: "summary-quality-suite"
tests:
  - id: "test_thesis_presence"
    prompt: "Summarize: [Technical Report Excerpt]"
    expected_keywords: ["**Thesis**:", "**Key Findings**:", "**Recommendation**:"]
EOF

moro eval run --checkpoint ./runs/best/ --suite eval/summary_eval.yaml
  

Step 5: Deploy to Ollama with Custom Context Ceiling

moro release export --run-id best --version v1.0.0 --quant Q4_K_M
moro release deploy --target ollama --version v1.0.0 --name doc-summarizer