# czyssrs/convfinqa architecture

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

- Interactive diagram: https://gitdiagram.com/czyssrs/convfinqa
- Repository: https://github.com/czyssrs/convfinqa

## Overview

##### Main Components of the System
- Data Sources: Although not directly part of the code directory, the README explains that the project uses JSON datasets (train, dev, test files in both conversation and turn level formats). Represent these as “Dataset (Conversation & Turn Level)” components.
- Finqanet Retriever:
- Contains key files: Main.py, Model.py, Test.py, config.py, and various utility files.
- Handles both training and inference for retrieving the relevant information from the datasets.
- Uses external dependencies (PyTorch and Hugging Face Transformers).
- Finqanet Generator:
- Contains files like Convert.py, Main.py, Model_new.py, Test.py, config.py, and related utility files.
- Converts the outputs from the retriever into training inputs for the generator model.
- Also supports training and inference of the generation model.
- Shared Utilities:
- A separate “utils” folder exists, indicating common functions possibly used by both retriever and generator.
- External Services & Libraries:
- The system relies on PyTorch and Huggingface Transformers.
- Workflow Scripts:
- There are shell scripts (e.g., run_model.sh) included in both retriever and generator folders. They signify the execution triggers for training and inference.

##### Relationships and Data Flow
- Finally, from the “Finqanet Generator”, show flows both to a training process component and an inference output component.
- Additionally, highlight that both modules depend on configuration files that guide model training/inference (for example, config.py in each module).

##### Detail Architectural Patterns and Design Principles
- The design exhibits separation of concerns: the retriever and generator modules have dedicated directories and functionalities.
- Usage of configuration files and script-based execution for modularity and easy adaptation of parameters.
- That the shared utilities folder signals a DRY (Don’t Repeat Yourself) principle by centralizing common functions.

##### Specific Technologies and Dependencies
- Python for core development.
- PyTorch 1.7.1 and Huggingface Transformers 4.4.2 for model implementation.
- You may also include that the dataset is in JSON format and structured for conversation and turn-level processing.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Dataset and External Sources
    subgraph "Dataset and External Sources"
        DS("Dataset (Conversation & Turn Level)"):::external
        EXT("PyTorch & HF Transformers"):::external
    end

    %% Finqanet Retriever Module
    subgraph "Finqanet Retriever"
        R_Main("Main"):::retriever
        R_Model("Model"):::retriever
        R_Test("Test"):::retriever
        R_Config("Configuration"):::retriever
        R_Utils("Utilities"):::retriever
        R_Finqa("Finqa Utils"):::retriever
        R_Run("Run Script"):::retriever
    end

    %% Intermediate Output
    subgraph "Intermediate Output"
        IO("Retrieval Output"):::intermediate
    end

    %% Finqanet Generator Module
    subgraph "Finqanet Generator"
        G_Convert("Data Conversion"):::generator
        G_Main("Main"):::generator
        G_Model("Model"):::generator
        G_Test("Test"):::generator
        G_Config("Configuration"):::generator
        G_Utils("Utilities"):::generator
        G_Finqa("Finqa Utils"):::generator
        G_Support("Supporting Files"):::generator
        G_Run("Run Script"):::generator
    end

    %% Shared Utilities
    subgraph "Shared Utilities"
        SU("General Utilities"):::utils
    end

    %% Data Flow Connections
    DS -->|"raw_JSON_input"| R_Main
    DS --> R_Utils
    R_Config --- R_Main
    R_Main -->|"retrieval_output"| IO
    R_Model --> IO
    R_Run --> R_Main
    IO -->|"converted_data"| G_Convert
    G_Config --- G_Convert
    G_Convert -->|"training_data"| G_Main
    G_Model --> G_Main
    G_Run --> G_Main
    G_Main -->|"inference_result"| End["Output"]
    EXT --- R_Main
    EXT --- G_Main

    %% Utilities Dependencies
    R_Utils --- SU
    R_Finqa --- SU
    R_Utils --- R_Finqa
    G_Utils --- SU
    G_Finqa --- SU
    G_Utils --- G_Finqa

    %% Click Events for Finqanet Retriever
    click R_Main "https://github.com/czyssrs/convfinqa/blob/main/code/finqanet_retriever/Main.py"
    click R_Model "https://github.com/czyssrs/convfinqa/blob/main/code/finqanet_retriever/Model.py"
    click R_Test "https://github.com/czyssrs/convfinqa/blob/main/code/finqanet_retriever/Test.py"
    click R_Config "https://github.com/czyssrs/convfinqa/blob/main/code/finqanet_retriever/config.py"
    click R_Utils "https://github.com/czyssrs/convfinqa/blob/main/code/finqanet_retriever/utils.py"
    click R_Finqa "https://github.com/czyssrs/convfinqa/blob/main/code/finqanet_retriever/finqa_utils.py"
    click R_Run "https://github.com/czyssrs/convfinqa/blob/main/code/finqanet_retriever/run_model.sh"

    %% Click Events for Finqanet Generator
    click G_Convert "https://github.com/czyssrs/convfinqa/blob/main/code/finqanet_generator/Convert.py"
    click G_Main "https://github.com/czyssrs/convfinqa/blob/main/code/finqanet_generator/Main.py"
    click G_Model "https://github.com/czyssrs/convfinqa/blob/main/code/finqanet_generator/Model_new.py"
    click G_Test "https://github.com/czyssrs/convfinqa/blob/main/code/finqanet_generator/Test.py"
    click G_Config "https://github.com/czyssrs/convfinqa/blob/main/code/finqanet_generator/config.py"
    click G_Utils "https://github.com/czyssrs/convfinqa/blob/main/code/finqanet_generator/utils.py"
    click G_Finqa "https://github.com/czyssrs/convfinqa/blob/main/code/finqanet_generator/finqa_utils.py"
    click G_Support "https://github.com/czyssrs/convfinqa/blob/main/code/finqanet_generator/constant_list.txt"
    click G_Support "https://github.com/czyssrs/convfinqa/blob/main/code/finqanet_generator/operation_list.txt"
    click G_Run "https://github.com/czyssrs/convfinqa/blob/main/code/finqanet_generator/run_model.sh"

    %% Click Event for Shared Utilities
    click SU "https://github.com/czyssrs/convfinqa/blob/main/code/utils/general_utils.py"

    %% Styling
    classDef external fill:#f9f,stroke:#333,stroke-width:2px;
    classDef retriever fill:#bbf,stroke:#003399,stroke-width:2px;
    classDef generator fill:#bfb,stroke:#006600,stroke-width:2px;
    classDef utils fill:#ffb,stroke:#996600,stroke-width:2px;
    classDef intermediate fill:#ffd,stroke:#cc9900,stroke-width:2px;
```
