# tricktreat/diffusionner architecture

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

- Interactive diagram: https://gitdiagram.com/tricktreat/diffusionner
- Repository: https://github.com/tricktreat/diffusionner

## Overview

##### Project Type and Purpose
- This repository is a research/codebase for a diffusion-based Named Entity Recognition (NER) system, as described in your paper “DiffusionNER: Boundary Diffusion for Named Entity Recognition”. It implements both training (via forward and reverse diffusion processes on entity boundaries) and evaluation pipelines.
- The project integrates state-of-the-art transformer models (BERT, ALBERT, RoBERTa, XLM-RoBERTa) with custom diffusion components.

##### Analyzing the File Structure
- Key entry points:
- The main script (diffusionner.py) acts as the command-line driver to trigger training or evaluation.
- Additional scripts like args.py and config_reader.py manage command-line arguments and configuration parsing.
- Core Application Code in the “diffusionner” Directory:
- Contains modules for training (diffusionner_trainer.py, trainer.py), evaluation (evaluator.py), input reading (input_reader.py), and various submodules handling modeling (modeling_albert.py, modeling_bert.py, etc.), loss, sampling, and utility functions.
- “entities.py” likely encapsulates definitions for data entities or NER labels.
- Configuration Files:
- The “configs” folder holds different .conf files for each dataset (ACE2004, ACE2005, etc.) and evaluation setup.
- Supporting Tools:
- The “tools” folder includes scripts (e.g., ner2json.py) for data conversion and preprocessing, further supporting the main diffusion processes.
- Assets:
- The “assets” directory contains images (like overview.jpg) for documentation and visualization purposes.

##### Key Components
a. Entry & Configuration:
- Main entry script (diffusionner.py) which uses utilities (args.py, config_reader.py) and the config files from “configs”.
b. Data Ingestion & Preprocessing:
- Input reading and preprocessing are handled by modules like diffusionner/input_reader.py and tools such as context_convert.py and ner2json.py.
c. Model Architecture:
- Different modeling modules (modeling_bert.py, modeling_albert.py, etc.) indicate the usage of underlying transformer architectures integrated with your diffusion model approach.
d. Diffusion Process:
- Components for noise addition and reverse diffusion are implemented in parts like sampling.py, loss.py, and possibly lap.py.
e. Training Pipeline:
- Training modules (diffusionner_trainer.py and trainer.py) orchestrate the forward-noise addition and reverse denoising processes to learn entity boundaries.
f. Evaluation Pipeline:
- Evaluator module (evaluator.py) that uses “eval.conf” to run model evaluation post-training.
g. Utility & Helper Components:
- Utility functions in util.py and entities definitions support the core pipeline.

##### Architectural Patterns & Design Principles
- Modular design: Each major functionality—modeling, training, evaluation, and utility handling—is encapsulated in separate submodules.
- Separation of Concerns: Clearly demarcated roles (data preprocessing, model definition, training, evaluation) aid in maintainability.
- Configuration-based control: Using external config files helps in flexibly switching between datasets and experimental setups without changing the code.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Entry & Configuration
    subgraph "Entry & Configuration"
        A["diffusionner.py"]:::config
        B["args.py"]:::config
        C["config_reader.py"]:::config
        D["configs"]:::config
    end

    %% Data Ingestion & Preprocessing
    subgraph "Data Ingestion & Preprocessing"
        E["input_reader.py"]:::data
        F["context_convert.py"]:::data
        G["ner2json.py"]:::data
    end

    %% Modeling & Diffusion
    subgraph "Modeling & Diffusion"
        %% Transformer Modeling Modules
        H["modeling_bert.py"]:::transformer
        I["modeling_albert.py"]:::transformer
        J["modeling_roberta.py"]:::transformer
        K["modeling_xlm_roberta.py"]:::transformer
        L["models.py"]:::transformer
        %% Diffusion Components
        M["sampling.py"]:::diffusion
        N["loss.py"]:::diffusion
        O["lap.py"]:::diffusion
        P["matcher.py"]:::diffusion
    end

    %% Training Pipeline
    subgraph "Training Pipeline"
        Q["diffusionner_trainer.py"]:::training
        R["trainer.py"]:::training
    end

    %% Evaluation Pipeline
    subgraph "Evaluation Pipeline"
        S["evaluator.py"]:::evaluation
    end

    %% Utility & Helper Components
    subgraph "Utility & Helper"
        T["util.py"]:::utility
        U["entities.py"]:::utility
    end

    %% Connections
    A -->|"initiates"| E
    D -->|"providesConfig"| E
    F -->|"dataConversion"| E
    G -->|"dataConversion"| E
    C -->|"parsesConfig"| Q
    E -->|"preprocessedData"| Q
    Q -->|"orchestrates"| R
    R -->|"trainsUsing"| H
    R -->|"trainsUsing"| I
    R -->|"trainsUsing"| J
    R -->|"trainsUsing"| K
    R -->|"trainsUsing"| L
    R -->|"diffusion"| M
    R -->|"diffusion"| N
    R -->|"diffusion"| O
    R -->|"diffusion"| P
    R -->|"evaluates"| S
    T -->|"supports"| Q
    U -->|"definesEntities"| Q
    T -->|"supports"| S
    U -->|"definesEntities"| S

    %% Styles
    classDef config fill:#ADD8E6,stroke:#000,stroke-width:1px;
    classDef data fill:#90EE90,stroke:#000,stroke-width:1px;
    classDef transformer fill:#FFA500,stroke:#000,stroke-width:1px;
    classDef diffusion fill:#FFD700,stroke:#000,stroke-width:1px;
    classDef training fill:#F08080,stroke:#000,stroke-width:1px;
    classDef evaluation fill:#D3D3D3,stroke:#000,stroke-width:1px;
    classDef utility fill:#9370DB,stroke:#000,stroke-width:1px;

    %% Click Events for Entry & Configuration
    click A "https://github.com/tricktreat/diffusionner/blob/main/diffusionner.py"
    click B "https://github.com/tricktreat/diffusionner/blob/main/args.py"
    click C "https://github.com/tricktreat/diffusionner/blob/main/config_reader.py"
    click D "https://github.com/tricktreat/diffusionner/tree/main/configs/"

    %% Click Events for Data Ingestion & Preprocessing
    click E "https://github.com/tricktreat/diffusionner/blob/main/diffusionner/input_reader.py"
    click F "https://github.com/tricktreat/diffusionner/blob/main/tools/context_convert.py"
    click G "https://github.com/tricktreat/diffusionner/blob/main/tools/ner2json.py"

    %% Click Events for Modeling & Diffusion
    click H "https://github.com/tricktreat/diffusionner/blob/main/diffusionner/modeling_bert.py"
    click I "https://github.com/tricktreat/diffusionner/blob/main/diffusionner/modeling_albert.py"
    click J "https://github.com/tricktreat/diffusionner/blob/main/diffusionner/modeling_roberta.py"
    click K "https://github.com/tricktreat/diffusionner/blob/main/diffusionner/modeling_xlm_roberta.py"
    click L "https://github.com/tricktreat/diffusionner/blob/main/diffusionner/models.py"
    click M "https://github.com/tricktreat/diffusionner/blob/main/diffusionner/sampling.py"
    click N "https://github.com/tricktreat/diffusionner/blob/main/diffusionner/loss.py"
    click O "https://github.com/tricktreat/diffusionner/blob/main/diffusionner/lap.py"
    click P "https://github.com/tricktreat/diffusionner/blob/main/diffusionner/matcher.py"

    %% Click Events for Training Pipeline
    click Q "https://github.com/tricktreat/diffusionner/blob/main/diffusionner/diffusionner_trainer.py"
    click R "https://github.com/tricktreat/diffusionner/blob/main/diffusionner/trainer.py"

    %% Click Events for Evaluation Pipeline
    click S "https://github.com/tricktreat/diffusionner/blob/main/diffusionner/evaluator.py"

    %% Click Events for Utility & Helper Components
    click T "https://github.com/tricktreat/diffusionner/blob/main/diffusionner/util.py"
    click U "https://github.com/tricktreat/diffusionner/blob/main/diffusionner/entities.py"
```
