# nagasai1918/ai-generated-tweet-detection-with-deep-learning architecture

> Architecture diagram of the GitHub repository nagasai1918/ai-generated-tweet-detection-with-deep-learning, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/nagasai1918/ai-generated-tweet-detection-with-deep-learning
- Repository: https://github.com/nagasai1918/ai-generated-tweet-detection-with-deep-learning

## Overview

This repository is a deep-learning classifier for distinguishing human-written from AI-generated tweets. The prediction workflow accepts text through a FastAPI endpoint, cleans and tokenizes it, loads the trained CNN–LSTM model, and returns a machine-generated probability and threshold-based label. A separate training workflow cleans labeled CSV data, builds FastText embeddings and the model, evaluates it, and saves model and tokenizer artifacts. The graph is based on the README and shown source excerpts; unsampled internals are not inferred.

Main entry points: [`ai-tweet-detection/src/train.py`](https://github.com/nagasai1918/ai-generated-tweet-detection-with-deep-learning/blob/main/ai-tweet-detection/src/train.py) (Training workflow), [`ai-tweet-detection/api/main.py`](https://github.com/nagasai1918/ai-generated-tweet-detection-with-deep-learning/blob/main/ai-tweet-detection/api/main.py) (FastAPI endpoint), [`ai-tweet-detection/src/predict.py`](https://github.com/nagasai1918/ai-generated-tweet-detection-with-deep-learning/blob/main/ai-tweet-detection/src/predict.py) (Tweet predictor), [`ai-tweet-detection/config.py`](https://github.com/nagasai1918/ai-generated-tweet-detection-with-deep-learning/blob/main/ai-tweet-detection/config.py) (Project settings)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_serving["Prediction service"]
  node_api["FastAPI endpoint<br/>[main.py]"]
  node_predict["Tweet predictor<br/>[predict.py]"]
end

subgraph group_preparation["Text preparation"]
  node_clean["Text cleaning<br/>[preprocess.py]"]
end

subgraph group_training["Model training"]
  node_trainer["Training workflow<br/>[train.py]"]
  node_embeddings["FastText embeddings<br/>[embeddings.py]"]
  node_model["CNN–LSTM model<br/>[model.py]"]
  node_evaluation["Model evaluation<br/>[evaluate.py]"]
end

subgraph group_artifacts["Settings and artifacts"]
  node_config["Project settings<br/>[config.py]"]
  node_artifacts_store["Model and tokenizer files<br/>[config.py]"]
end

node_user(("Tweet submitter"))

node_user -->|"submits tweet"| node_api
node_api -->|"requests score"| node_predict
node_predict -->|"cleans text"| node_clean
node_api -->|"returns label"| node_user
node_trainer -->|"loads cleaned data"| node_clean
node_trainer -->|"builds embeddings"| node_embeddings
node_trainer -->|"builds model"| node_model
node_trainer -->|"evaluates model"| node_evaluation
node_trainer -->|"saves model and tokenizer"| node_artifacts_store
node_predict -->|"loads model and tokenizer"| node_artifacts_store
node_trainer -->|"reads settings"| node_config
node_predict -->|"reads settings"| node_config
node_api -->|"reads threshold"| node_config

click node_api "https://github.com/nagasai1918/ai-generated-tweet-detection-with-deep-learning/blob/main/ai-tweet-detection/api/main.py"
click node_predict "https://github.com/nagasai1918/ai-generated-tweet-detection-with-deep-learning/blob/main/ai-tweet-detection/src/predict.py"
click node_clean "https://github.com/nagasai1918/ai-generated-tweet-detection-with-deep-learning/blob/main/ai-tweet-detection/src/preprocess.py"
click node_trainer "https://github.com/nagasai1918/ai-generated-tweet-detection-with-deep-learning/blob/main/ai-tweet-detection/src/train.py"
click node_embeddings "https://github.com/nagasai1918/ai-generated-tweet-detection-with-deep-learning/blob/main/ai-tweet-detection/src/embeddings.py"
click node_model "https://github.com/nagasai1918/ai-generated-tweet-detection-with-deep-learning/blob/main/ai-tweet-detection/src/model.py"
click node_evaluation "https://github.com/nagasai1918/ai-generated-tweet-detection-with-deep-learning/blob/main/ai-tweet-detection/src/evaluate.py"
click node_config "https://github.com/nagasai1918/ai-generated-tweet-detection-with-deep-learning/blob/main/ai-tweet-detection/config.py"
click node_artifacts_store "https://github.com/nagasai1918/ai-generated-tweet-detection-with-deep-learning/blob/main/ai-tweet-detection/config.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_api,node_predict toneBlue
class node_clean toneAmber
class node_trainer,node_embeddings,node_model,node_evaluation toneMint
class node_config,node_artifacts_store toneRose
class node_user toneIndigo
```

## Components

### Prediction service

- [FastAPI endpoint](https://github.com/nagasai1918/ai-generated-tweet-detection-with-deep-learning/blob/main/ai-tweet-detection/api/main.py): `ai-tweet-detection/api/main.py`
- [Tweet predictor](https://github.com/nagasai1918/ai-generated-tweet-detection-with-deep-learning/blob/main/ai-tweet-detection/src/predict.py): `ai-tweet-detection/src/predict.py`

### Text preparation

- [Text cleaning](https://github.com/nagasai1918/ai-generated-tweet-detection-with-deep-learning/blob/main/ai-tweet-detection/src/preprocess.py): `ai-tweet-detection/src/preprocess.py`

### Model training

- [Training workflow](https://github.com/nagasai1918/ai-generated-tweet-detection-with-deep-learning/blob/main/ai-tweet-detection/src/train.py): `ai-tweet-detection/src/train.py`
- [FastText embeddings](https://github.com/nagasai1918/ai-generated-tweet-detection-with-deep-learning/blob/main/ai-tweet-detection/src/embeddings.py): `ai-tweet-detection/src/embeddings.py`
- [CNN–LSTM model](https://github.com/nagasai1918/ai-generated-tweet-detection-with-deep-learning/blob/main/ai-tweet-detection/src/model.py): `ai-tweet-detection/src/model.py`
- [Model evaluation](https://github.com/nagasai1918/ai-generated-tweet-detection-with-deep-learning/blob/main/ai-tweet-detection/src/evaluate.py): `ai-tweet-detection/src/evaluate.py`

### Settings and artifacts

- [Project settings](https://github.com/nagasai1918/ai-generated-tweet-detection-with-deep-learning/blob/main/ai-tweet-detection/config.py): `ai-tweet-detection/config.py`
- [Model and tokenizer files](https://github.com/nagasai1918/ai-generated-tweet-detection-with-deep-learning/blob/main/ai-tweet-detection/config.py): `ai-tweet-detection/config.py`

### Other components

- **Tweet submitter**

## Connections

- Tweet submitter → FastAPI endpoint: submits tweet (evidence: `ai-tweet-detection/api/main.py`)
- FastAPI endpoint → Tweet predictor: requests score (evidence: `ai-tweet-detection/api/main.py`)
- Tweet predictor → Text cleaning: cleans text (evidence: `ai-tweet-detection/src/predict.py`)
- FastAPI endpoint → Tweet submitter: returns label (evidence: `ai-tweet-detection/api/main.py`)
- Training workflow → Text cleaning: loads cleaned data (evidence: `ai-tweet-detection/src/train.py`)
- Training workflow → FastText embeddings: builds embeddings (evidence: `ai-tweet-detection/src/train.py`)
- Training workflow → CNN–LSTM model: builds model (evidence: `ai-tweet-detection/src/train.py`)
- Training workflow → Model evaluation: evaluates model (evidence: `ai-tweet-detection/src/train.py`)
- Training workflow → Model and tokenizer files: saves model and tokenizer (evidence: `ai-tweet-detection/src/train.py`)
- Tweet predictor → Model and tokenizer files: loads model and tokenizer (evidence: `ai-tweet-detection/src/predict.py`)
- Training workflow → Project settings: reads settings (evidence: `ai-tweet-detection/src/train.py`)
- Tweet predictor → Project settings: reads settings (evidence: `ai-tweet-detection/src/predict.py`)
- FastAPI endpoint → Project settings: reads threshold (evidence: `ai-tweet-detection/api/main.py`)
