# dulhara79/tcwpn_test architecture

> Architecture diagram of the GitHub repository dulhara79/tcwpn_test, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/dulhara79/tcwpn_test
- Repository: https://github.com/dulhara79/tcwpn_test

## Overview

TC-WPN is a clinical anxiety-risk research pipeline with a Hugging Face inference wrapper. Its main workflow builds a structured, patient-level cohort, applies index-time and blinding controls, prepares notes and patient-disjoint episodes, trains a prototypical model, and evaluates patient-level predictions. The tree also shows mechanism analysis and shallow baselines. Source excerpts document key model and data-handling behavior; links among unsampled modules are included only where the SOURCE INDEX names the relationship.

Main entry points: [`scripts/build_clean_cohort.py`](https://github.com/dulhara79/tcwpn_test/blob/main/scripts/build_clean_cohort.py) (Clean Cohort Run), [`scripts/train.py`](https://github.com/dulhara79/tcwpn_test/blob/main/scripts/train.py) (Model Training), [`src/tcwpn/sampler.py`](https://github.com/dulhara79/tcwpn_test/blob/main/src/tcwpn/sampler.py) (Episode Sampling), [`src/tcwpn/collate.py`](https://github.com/dulhara79/tcwpn_test/blob/main/src/tcwpn/collate.py) (Episode Collation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cohort["Cohort Preparation"]
  node_cohort_builder["Cohort Builder<br/>[cohort.py]"]
  node_clean_build["Clean Cohort Run"]
  node_indexing["Index-Time Protocol<br/>[indexing.py]"]
  node_splits["Patient Splits<br/>[splits.py]"]
  node_blinding["Cohort Blinding<br/>[blinding.py]"]
  node_tokenization["Note Tokenization<br/>[tokenize_cohort.py]"]
end

subgraph group_research["Model Research"]
  node_episode_sampling["Episode Sampling<br/>[sampler.py]"]
  node_batch_collation["Episode Collation<br/>[collate.py]"]
  node_training["Model Training<br/>[train.py]"]
  node_model["Prototypical Model<br/>[model.py]"]
end

subgraph group_analysis["Evaluation Analysis"]
  node_evaluator["Plan Evaluation<br/>[evaluation.py]"]
  node_metrics["Patient Metrics<br/>[metrics.py]"]
  node_delong["DeLong Statistics<br/>[delong.py]"]
  node_mechanism_analysis["Mechanism Analysis"]
  node_collapse_diagnosis["Collapse Diagnosis"]
  node_shallow_baselines["Shallow Baselines"]
end

subgraph group_serving["Hosted Inference"]
  node_deployment_model["Serving Model<br/>[model.py]"]
  node_serving_preprocess["Serving Preprocessing<br/>[preprocessing.py]"]
  node_inference_app["Inference API<br/>[app.py]"]
end

node_researcher(("Researcher"))
node_clinical_data[("Clinical Tables")]

node_researcher -->|"build cohort"| node_clean_build
node_clinical_data -.->|"reads tables"| node_clean_build
node_clean_build -->|"builds cohort"| node_cohort_builder
node_clean_build -->|"assigns splits"| node_splits
node_clean_build -.->|"applies protocol"| node_indexing
node_cohort_builder -->|"supports indexing"| node_indexing
node_researcher -.->|"prepare notes"| node_tokenization
node_researcher -.->|"blind cohort"| node_blinding
node_researcher -.->|"make episodes"| node_episode_sampling
node_episode_sampling -->|"provides indices"| node_batch_collation
node_researcher -->|"train model"| node_training
node_training -->|"optimizes"| node_model
node_training -->|"collates episodes"| node_batch_collation
node_training -->|"loads plans"| node_episode_sampling
node_researcher -.->|"evaluate plans"| node_evaluator
node_evaluator -->|"collates episodes"| node_batch_collation
node_evaluator -->|"runs inference"| node_model
node_researcher -.->|"score results"| node_metrics
node_metrics -->|"uses statistics"| node_delong
node_researcher -.->|"analyze mechanisms"| node_mechanism_analysis
node_mechanism_analysis -->|"uses model"| node_model
node_mechanism_analysis -->|"packs episodes"| node_batch_collation
node_researcher -.->|"diagnose collapse"| node_collapse_diagnosis
node_collapse_diagnosis -->|"uses model"| node_model
node_researcher -.->|"run baselines"| node_shallow_baselines
node_shallow_baselines -->|"loads plans"| node_episode_sampling
node_researcher -.->|"submit prediction"| node_inference_app
node_inference_app -->|"packs notes"| node_serving_preprocess
node_inference_app -->|"classifies query"| node_deployment_model

click node_cohort_builder "https://github.com/dulhara79/tcwpn_test/blob/main/src/tcwpn/cohort.py"
click node_clean_build "https://github.com/dulhara79/tcwpn_test/blob/main/scripts/build_clean_cohort.py"
click node_indexing "https://github.com/dulhara79/tcwpn_test/blob/main/src/tcwpn/indexing.py"
click node_splits "https://github.com/dulhara79/tcwpn_test/blob/main/src/tcwpn/splits.py"
click node_blinding "https://github.com/dulhara79/tcwpn_test/blob/main/src/tcwpn/blinding.py"
click node_tokenization "https://github.com/dulhara79/tcwpn_test/blob/main/scripts/tokenize_cohort.py"
click node_episode_sampling "https://github.com/dulhara79/tcwpn_test/blob/main/src/tcwpn/sampler.py"
click node_batch_collation "https://github.com/dulhara79/tcwpn_test/blob/main/src/tcwpn/collate.py"
click node_training "https://github.com/dulhara79/tcwpn_test/blob/main/scripts/train.py"
click node_model "https://github.com/dulhara79/tcwpn_test/blob/main/src/tcwpn/model.py"
click node_deployment_model "https://github.com/dulhara79/tcwpn_test/blob/main/deployment/huggingface/tc_wpn/model.py"
click node_serving_preprocess "https://github.com/dulhara79/tcwpn_test/blob/main/deployment/huggingface/tc_wpn/preprocessing.py"
click node_inference_app "https://github.com/dulhara79/tcwpn_test/blob/main/deployment/huggingface/app.py"
click node_evaluator "https://github.com/dulhara79/tcwpn_test/blob/main/src/tcwpn/evaluation.py"
click node_metrics "https://github.com/dulhara79/tcwpn_test/blob/main/src/tcwpn/metrics.py"
click node_delong "https://github.com/dulhara79/tcwpn_test/blob/main/src/tcwpn/delong.py"
click node_mechanism_analysis "https://github.com/dulhara79/tcwpn_test/blob/main/scripts/analyse_mechanisms.py"
click node_collapse_diagnosis "https://github.com/dulhara79/tcwpn_test/blob/main/scripts/diagnose_collapse.py"
click node_shallow_baselines "https://github.com/dulhara79/tcwpn_test/blob/main/scripts/run_shallow_baselines.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_cohort_builder,node_clean_build,node_indexing,node_splits,node_blinding,node_tokenization toneBlue
class node_episode_sampling,node_batch_collation,node_training,node_model,node_clinical_data toneAmber
class node_evaluator,node_metrics,node_delong,node_mechanism_analysis,node_collapse_diagnosis,node_shallow_baselines toneMint
class node_deployment_model,node_serving_preprocess,node_inference_app toneRose
class node_researcher toneIndigo
```

## Components

### Cohort Preparation

- [Cohort Builder](https://github.com/dulhara79/tcwpn_test/blob/main/src/tcwpn/cohort.py): `src/tcwpn/cohort.py`
- [Clean Cohort Run](https://github.com/dulhara79/tcwpn_test/blob/main/scripts/build_clean_cohort.py): `scripts/build_clean_cohort.py`
- [Index-Time Protocol](https://github.com/dulhara79/tcwpn_test/blob/main/src/tcwpn/indexing.py): `src/tcwpn/indexing.py`
- [Patient Splits](https://github.com/dulhara79/tcwpn_test/blob/main/src/tcwpn/splits.py): `src/tcwpn/splits.py`
- [Cohort Blinding](https://github.com/dulhara79/tcwpn_test/blob/main/src/tcwpn/blinding.py): `src/tcwpn/blinding.py`
- [Note Tokenization](https://github.com/dulhara79/tcwpn_test/blob/main/scripts/tokenize_cohort.py): `scripts/tokenize_cohort.py`

### Model Research

- [Episode Sampling](https://github.com/dulhara79/tcwpn_test/blob/main/src/tcwpn/sampler.py): `src/tcwpn/sampler.py`
- [Episode Collation](https://github.com/dulhara79/tcwpn_test/blob/main/src/tcwpn/collate.py): `src/tcwpn/collate.py`
- [Model Training](https://github.com/dulhara79/tcwpn_test/blob/main/scripts/train.py): `scripts/train.py`
- [Prototypical Model](https://github.com/dulhara79/tcwpn_test/blob/main/src/tcwpn/model.py): `src/tcwpn/model.py`

### Evaluation Analysis

- [Plan Evaluation](https://github.com/dulhara79/tcwpn_test/blob/main/src/tcwpn/evaluation.py): `src/tcwpn/evaluation.py`
- [Patient Metrics](https://github.com/dulhara79/tcwpn_test/blob/main/src/tcwpn/metrics.py): `src/tcwpn/metrics.py`
- [DeLong Statistics](https://github.com/dulhara79/tcwpn_test/blob/main/src/tcwpn/delong.py): `src/tcwpn/delong.py`
- [Mechanism Analysis](https://github.com/dulhara79/tcwpn_test/blob/main/scripts/analyse_mechanisms.py): `scripts/analyse_mechanisms.py`
- [Collapse Diagnosis](https://github.com/dulhara79/tcwpn_test/blob/main/scripts/diagnose_collapse.py): `scripts/diagnose_collapse.py`
- [Shallow Baselines](https://github.com/dulhara79/tcwpn_test/blob/main/scripts/run_shallow_baselines.py): `scripts/run_shallow_baselines.py`

### Hosted Inference

- [Serving Model](https://github.com/dulhara79/tcwpn_test/blob/main/deployment/huggingface/tc_wpn/model.py): `deployment/huggingface/tc_wpn/model.py`
- [Serving Preprocessing](https://github.com/dulhara79/tcwpn_test/blob/main/deployment/huggingface/tc_wpn/preprocessing.py): `deployment/huggingface/tc_wpn/preprocessing.py`
- [Inference API](https://github.com/dulhara79/tcwpn_test/blob/main/deployment/huggingface/app.py): `deployment/huggingface/app.py`

### Other components

- **Researcher**
- **Clinical Tables**

## Connections

- Researcher → Clean Cohort Run: build cohort (evidence: `scripts/build_clean_cohort.py`)
- Clinical Tables → Clean Cohort Run: reads tables
- Clean Cohort Run → Cohort Builder: builds cohort (evidence: `scripts/build_clean_cohort.py`)
- Clean Cohort Run → Patient Splits: assigns splits (evidence: `scripts/build_clean_cohort.py`)
- Clean Cohort Run → Index-Time Protocol: applies protocol
- Cohort Builder → Index-Time Protocol: supports indexing (evidence: `src/tcwpn/indexing.py`)
- Researcher → Note Tokenization: prepare notes
- Researcher → Cohort Blinding: blind cohort
- Researcher → Episode Sampling: make episodes
- Episode Sampling → Episode Collation: provides indices (evidence: `src/tcwpn/collate.py`)
- Researcher → Model Training: train model (evidence: `scripts/train.py`)
- Model Training → Prototypical Model: optimizes (evidence: `scripts/train.py`)
- Model Training → Episode Collation: collates episodes (evidence: `scripts/train.py`)
- Model Training → Episode Sampling: loads plans (evidence: `scripts/train.py`)
- Researcher → Plan Evaluation: evaluate plans
- Plan Evaluation → Episode Collation: collates episodes (evidence: `src/tcwpn/evaluation.py`)
- Plan Evaluation → Prototypical Model: runs inference (evidence: `src/tcwpn/evaluation.py`)
- Researcher → Patient Metrics: score results
- Patient Metrics → DeLong Statistics: uses statistics (evidence: `src/tcwpn/metrics.py`)
- Researcher → Mechanism Analysis: analyze mechanisms
- Mechanism Analysis → Prototypical Model: uses model (evidence: `scripts/analyse_mechanisms.py`)
- Mechanism Analysis → Episode Collation: packs episodes (evidence: `scripts/analyse_mechanisms.py`)
- Researcher → Collapse Diagnosis: diagnose collapse
- Collapse Diagnosis → Prototypical Model: uses model (evidence: `scripts/diagnose_collapse.py`)
- Researcher → Shallow Baselines: run baselines
- Shallow Baselines → Episode Sampling: loads plans (evidence: `scripts/run_shallow_baselines.py`)
- Researcher → Inference API: submit prediction
- Inference API → Serving Preprocessing: packs notes (evidence: `deployment/huggingface/app.py`)
- Inference API → Serving Model: classifies query (evidence: `deployment/huggingface/app.py`)
