# xiaochr/llm-aes architecture

> Architecture diagram of the GitHub repository xiaochr/llm-aes, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-07). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/xiaochr/llm-aes
- Repository: https://github.com/xiaochr/llm-aes

## Overview

##### Project Type and Purpose
- This is a research-oriented Python codebase implementing and evaluating a dual-process Automated Essay Scoring (AES) pipeline.
- It explores both a “fast” scoring module (e.g., BERT or other light models) and a “slow” LLM-based module (GPT-3.5/4, LLaMA3), along with human–AI co-grading experiments.

##### File-Structure Analysis
- Top-level scripts:
- BERT_baseline.py – baseline fast-module using BERT
- train_fast_module.py – training script for the “fast” scorer
- finetune_slow_module.py – fine-tunes LLaMA3 (self-hosted)
- finetune_gpt.py – fine-tunes or primes GPT-3.5/GPT-4 via API
- inference_slow_module.py – orchestration of retrieval + LLM inference
- gpt_score_asap1.py / gpt_score_student.py – zero/few-shot scoring with GPT on ASAP or private dataset
- retrieval.py – KNN or embedding-based prompt example retrieval
- dataset_info.py – dataset loading, preprocessing, metadata
- Resources and materials:
- img/ – example figure of dual-process framework
- materials/ – IRB paperwork

##### README Insights
- Architecture revolves around dual-process theory: a fast, lightweight model and a slow, high-quality LLM.
- Uses public ASAP and private Chinese Student English Essay datasets (via HuggingFace).
- Evaluates zero-shot, few-shot, and supervised fine-tuning, plus a human co-grading experiment.

a. Main Components
1) Data Sources
– Public ASAP dataset (HuggingFace)
– Private CSEE dataset
2) Preprocessing Layer
– dataset_info.py
3) Retrieval Service
– retrieval.py (embeddings store, k-NN lookup)
4) Fast Module (Lightweight AES)
– BERT_baseline.py
– train_fast_module.py
5) Slow Module (LLM-based AES)
– finetune_slow_module.py (LLaMA3)
– finetune_gpt.py (GPT-3.5/4 API)
– inference_slow_module.py
6) Evaluation & Scoring Scripts
– gpt_score_asap1.py
– gpt_score_student.py
7) Human–AI Co-Grading Experiment
– Combination of model outputs + human annotators

b. Interactions and Data Flow
- Data Sources → Preprocessing → (1) Fast Module training & inference → Fast Score
- Data Sources → Preprocessing → Retrieval → Slow Module fine-tuning & inference → Slow Score + Explanations + Confidence
- Slow & Fast Scores are compared, aggregated, or presented to human graders for the co-grading study.
- Evaluation scripts consume model outputs and ground-truth labels for metrics.

c. Architectural Patterns
– Pipeline pattern: clear separation of data ingestion, preprocessing, model training, and inference.
– Dual-process/multi-agent: lightweight vs. heavyweight scoring engines.
– Retrieval-augmented generation for few-shot prompts.
– Modular scripts rather than a monolith—each step is a standalone component.

d. Key Technologies
– Python 3.x, PyTorch or HuggingFace Transformers for model training
– OpenAI API for GPT-3.5/GPT-4 calls
– Local LLaMA3 checkpoints for slow-module fine-tuning
– HuggingFace Datasets for data loading
– FAISS or similar for retrieval embeddings

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data Layer
    subgraph "Data Sources"
        direction TB
        ASAP["ASAP Dataset<br/>(HuggingFace)"]:::data
        CSEE["CSEE Dataset"]:::data
    end

    %% Preprocessing
    Preproc["Preprocessing<br/>(dataset_info.py)"]:::data
    click Preproc "https://github.com/xiaochr/llm-aes/blob/main/dataset_info.py"

    ASAP -->|"raw text"| Preproc
    CSEE -->|"raw text"| Preproc

    %% Retrieval Service
    Retrieval["Retrieval Service<br/>(retrieval.py)"]:::data
    click Retrieval "https://github.com/xiaochr/llm-aes/blob/main/retrieval.py"
    Preproc -->|"embeddings"| Retrieval

    %% Fast Module
    subgraph "Fast Module (Lightweight AES)" 
        direction TB
        FastTrain["Fast Model Trainer<br/>(train_fast_module.py)"]:::fast
        FastInfer["Fast Inference<br/>(BERT_baseline.py)"]:::fast
    end
    click FastTrain "https://github.com/xiaochr/llm-aes/blob/main/train_fast_module.py"
    click FastInfer "https://github.com/xiaochr/llm-aes/blob/main/BERT_baseline.py"

    Preproc -->|"tokenized tensors"| FastTrain
    FastTrain -->|"fast model artifact"| FastInfer
    Preproc -->|"tokenized tensors"| FastInfer
    FastInfer -->|"fast score"| FastScore["Fast Score"]:::fastScore

    %% Slow Module
    subgraph "Slow Module (LLM-based AES)"
        direction TB
        LlamaFT["LLaMA3 Fine-tuning<br/>(finetune_slow_module.py)"]:::slow
        GPTFT["GPT-3.5/4 Fine-tuning<br/>(finetune_gpt.py)"]:::slow
        SlowInfer["Slow Inference<br/>(inference_slow_module.py)"]:::slow
    end
    click LlamaFT "https://github.com/xiaochr/llm-aes/blob/main/finetune_slow_module.py"
    click GPTFT "https://github.com/xiaochr/llm-aes/blob/main/finetune_gpt.py"
    click SlowInfer "https://github.com/xiaochr/llm-aes/blob/main/inference_slow_module.py"

    Preproc -->|"preprocessed data"| LlamaFT
    Preproc -->|"preprocessed data"| GPTFT
    LlamaFT -->|"model checkpoint"| SlowInfer
    GPTFT -->|"API prompts"| SlowInfer
    Retrieval -->|"k-NN examples"| SlowInfer
    SlowInfer -->|"slow score + explanation"| SlowScore["Slow Score"]:::slowScore

    %% External Dependencies
    subgraph "External Services"
        direction TB
        HF["HuggingFace Datasets"]:::external
        OpenAI["OpenAI API"]:::external
        LLaMAStore["Local LLaMA3 Store"]:::external
    end
    HF --> Preproc
    OpenAI --> GPTFT
    LLaMAStore --> LlamaFT

    %% Evaluation & Scoring
    subgraph "Evaluation & Human–AI Co-Grading" 
        direction TB
        EvalASAP["Eval ASAP Zero/Few-Shot<br/>(gpt_score_asap1.py)"]:::eval
        EvalStu["Eval Student Essays<br/>(gpt_score_student.py)"]:::eval
        HumanLoop["Human–AI Co-Grading"]:::human
    end
    click EvalASAP "https://github.com/xiaochr/llm-aes/blob/main/gpt_score_asap1.py"
    click EvalStu "https://github.com/xiaochr/llm-aes/blob/main/gpt_score_student.py"

    FastScore --> EvalASAP
    SlowScore --> EvalASAP
    EvalASAP -->|"metrics"| HumanLoop

    FastScore --> EvalStu
    SlowScore --> EvalStu
    EvalStu -->|"metrics"| HumanLoop

    %% Documentation & Resources
    subgraph "Documentation & Materials"
        direction TB
        README["README.md"]:::doc
        IMG["Dual-Process Framework Illustration<br/>(img/)"]:::doc
        Materials["IRB & Study Materials<br/>(materials/)"]:::doc
    end
    click README "https://github.com/xiaochr/llm-aes/blob/main/README.md"
    click IMG "https://github.com/xiaochr/llm-aes/tree/main/img/"
    click Materials "https://github.com/xiaochr/llm-aes/tree/main/materials/"

    %% Legend (Optional)
    classDef data fill:#cce5ff,stroke:#333,stroke-width:1px;
    classDef fast fill:#d4edda,stroke:#333,stroke-width:1px;
    classDef slow fill:#fff3cd,stroke:#333,stroke-width:1px;
    classDef fastScore fill:#b8e6b8,stroke:#333,stroke-width:1px;
    classDef slowScore fill:#ffe899,stroke:#333,stroke-width:1px;
    classDef external fill:#e2e3e5,stroke:#333,stroke-width:1px;
    classDef eval fill:#f0e6ff,stroke:#333,stroke-width:1px;
    classDef human fill:#e5ccff,stroke:#333,stroke-width:1px;
    classDef doc fill:#f8f9fa,stroke:#333,stroke-width:1px;
```
