# boostcampaitech5/level3_nlp_finalproject-nlp-12 architecture

> Architecture diagram of the GitHub repository boostcampaitech5/level3_nlp_finalproject-nlp-12, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/boostcampaitech5/level3_nlp_finalproject-nlp-12
- Repository: https://github.com/boostcampaitech5/level3_nlp_finalproject-nlp-12

## Overview

##### Main Components

a. Data Pipeline Components:
- Data Generation & Processing Layer
- Synthetic data generation flow
- Data preprocessing pipelines
- EDA components
- Both single-turn and multi-turn dialogue processing

b. Model Architecture:
- Base Model Layer (KULLM-Polyglot-Ko-12.8B)
- QLoRA Fine-tuning Layer
- Model Training Pipeline
- Inference Pipeline

c. Server Architecture:
- Frontend (React-based)
- Backend (Python/Flask)
- API Layer
- Database Connection

##### Component Relationships

**[Data Processing] → [Model Layer] → [Server Layer] → [Client Layer]**

Key flows to highlight:
##### Data Flow
- Raw data → Preprocessing → Training data
- Training data → Fine-tuning → Trained model
- User input → Model inference → Response

##### Service Flow
- Client request → Backend API → Model inference → Response formatting → Client display

##### Specific Implementation Details

Technical elements:
- QLoRA implementation with 4-bit quantization
- LangChain integration points
- Prompt template processing
- Evaluation pipeline (G-Eval and Human Evaluation)

##### Detailed Component Breakdown

**Data Layer:**
- Data Generation Scripts
- Preprocessing Pipeline
- EDA Tools
- Prompt Templates

**Model Layer:**
- KULLM-Polyglot-Ko-12.8B Base
- QLoRA Fine-tuning
- LangChain Integration
- Inference Engine

**Server Layer:**
- Flask Backend
- API Endpoints
- Database Connector
- Response Formatter

**Client Layer:**
- React Frontend
- Chat Interface
- State Management
- User Input Handler

##### Additional Elements

Supporting components:
- Configuration management
- Environment settings
- Evaluation pipelines
- Monitoring and logging

##### Key Technical Specifications

- Model parameters (12.8B)
- QLoRA specifications
- API endpoints
- Data volume indicators

Remember to use the project's actual directory structure to inform the component relationships, particularly the separation between finetuning, server, and data processing components as shown in the file tree.

This system design should help developers understand both the high-level architecture and the specific implementation details of the MyMary chatbot service.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Define styles
    classDef data fill:#3498db,stroke:#2980b9,color:white
    classDef model fill:#2ecc71,stroke:#27ae60,color:white
    classDef server fill:#e67e22,stroke:#d35400,color:white
    classDef client fill:#9b59b6,stroke:#8e44ad,color:white
    classDef config fill:#95a5a6,stroke:#7f8c8d,color:white

    %% Data Processing Layer
    subgraph DataLayer["Data Processing Layer"]
        DataGen["Data Generation"]:::data
        DataPrep["Data Preprocessing"]:::data
        EDA["EDA Components"]:::data
        PromptTemp["Prompt Templates"]:::data
    end

    %% Model Layer
    subgraph ModelLayer["Model Architecture Layer"]
        BaseModel["KULLM-Polyglot-Ko-12.8B"]:::model
        QLoRA["QLoRA Fine-tuning"]:::model
        Training["Training Pipeline"]:::model
        Inference["Inference Engine"]:::model
        LangChain["LangChain Integration"]:::model
    end

    %% Server Layer
    subgraph ServerLayer["Server Layer"]
        Flask["Flask Backend"]:::server
        API["API Endpoints"]:::server
        DB["Database Connector"]:::server
        ResponseFormat["Response Formatter"]:::server
    end

    %% Client Layer
    subgraph ClientLayer["Client Layer"]
        React["React Frontend"]:::client
        ChatUI["Chat Interface"]:::client
        StateManage["State Management"]:::client
        InputHandler["User Input Handler"]:::client
    end

    %% Configuration
    Config["Configuration Management"]:::config
    Eval["Evaluation Pipeline"]:::data

    %% Relationships
    DataGen --> DataPrep
    DataPrep --> Training
    EDA --> DataPrep
    PromptTemp --> Training
    PromptTemp --> Inference

    BaseModel --> QLoRA
    QLoRA --> Training
    Training --> Inference
    LangChain --> Inference

    Inference --> API
    API --> Flask
    Flask --> DB
    Flask --> ResponseFormat

    ResponseFormat --> React
    React --> ChatUI
    ChatUI --> StateManage
    StateManage --> InputHandler
    InputHandler --> API

    Config --> ModelLayer
    Config --> ServerLayer
    Eval --> Training

    %% Click events
    click DataGen "https://github.com/boostcampaitech5/level3_nlp_finalproject-nlp-12/blob/main/data/generate_data.py"
    click DataPrep "https://github.com/boostcampaitech5/level3_nlp_finalproject-nlp-12/blob/main/data/data_process_notebooks/preprocess.ipynb"
    click EDA "https://github.com/boostcampaitech5/level3_nlp_finalproject-nlp-12/tree/main/data/eda"
    click PromptTemp "https://github.com/boostcampaitech5/level3_nlp_finalproject-nlp-12/tree/main/data/prompt"
    click Training "https://github.com/boostcampaitech5/level3_nlp_finalproject-nlp-12/blob/main/finetuning/train.py"
    click Inference "https://github.com/boostcampaitech5/level3_nlp_finalproject-nlp-12/blob/main/finetuning/inference.py"
    click LangChain "https://github.com/boostcampaitech5/level3_nlp_finalproject-nlp-12/blob/main/finetuning/langchain_inference.ipynb"
    click Flask "https://github.com/boostcampaitech5/level3_nlp_finalproject-nlp-12/blob/main/server/backend/app.py"
    click API "https://github.com/boostcampaitech5/level3_nlp_finalproject-nlp-12/blob/main/server/backend/mary.py"
    click DB "https://github.com/boostcampaitech5/level3_nlp_finalproject-nlp-12/blob/main/server/backend/models.py"
    click React "https://github.com/boostcampaitech5/level3_nlp_finalproject-nlp-12/blob/main/server/frontend/src/App.js"
    click InputHandler "https://github.com/boostcampaitech5/level3_nlp_finalproject-nlp-12/blob/main/server/frontend/src/message.js"
    click Config "https://github.com/boostcampaitech5/level3_nlp_finalproject-nlp-12/blob/main/finetuning/config.yaml"
    click Eval "https://github.com/boostcampaitech5/level3_nlp_finalproject-nlp-12/blob/main/data/data_process_notebooks/evaluation.ipynb"
```
