Metadata-Version: 2.4
Name: cognet-generative
Version: 0.1.0
Summary: COGNET V1: Concept Routing Graph Neural Network
Requires-Python: >=3.10
Description-Content-Type: text/markdown
Requires-Dist: torch>=2.0.0
Requires-Dist: torch-geometric>=2.3.0
Requires-Dist: transformers>=4.30.0
Requires-Dist: spacy>=3.5.0
Requires-Dist: datasets>=2.14.0
Requires-Dist: fastapi>=0.100.0
Requires-Dist: uvicorn>=0.23.0
Provides-Extra: dev
Requires-Dist: pytest>=7.0.0; extra == "dev"
Requires-Dist: black>=23.0.0; extra == "dev"

# COGNET V1

COGNET is a Concept Routing Graph Neural Network designed for complex reasoning over text. 

## Installation

You can install COGNET as a Python package. From the root directory:

```bash
pip install -e .
```

### Requirements
- Python >= 3.10
- PyTorch >= 2.0.0
- PyTorch Geometric >= 2.3.0
- Transformers, spaCy, datasets

You may need to download the spaCy model:
```bash
python -m spacy download en_core_web_sm
```

## Running the Pipelines

### 1. Minimal Working Pipeline (Training Sanity Check)
To test that the full forward and backward pass works on a dummy dataset:
```bash
python -m cognet.train --dummy
```

### 2. Full Training
To run the full training loop with checkpointing:
```bash
python -m cognet.train --train_size 1000 --val_size 200 --epochs 5 --batch_size 16
```

### 3. Ablation Experiment
To verify that SCR routing adds value compared to standard pooling:
```bash
python -m cognet.experiment --dummy
```
or on the real dataset:
```bash
python -m cognet.experiment --train_size 500 --val_size 100 --epochs 5
```

## Inference API Usage

You can use the `generate` method for simple yes/no text classification.

```python
from cognet import CognetModel

# Load a trained model
# model = CognetModel.load("./checkpoints/cognet_best.pt")

# Or create a new one
model = CognetModel()

answer = model.generate("Explain gravity")
print(f"Prediction: {answer}")
```

## Lightweight Deployment (FastAPI)

You can serve the model over an HTTP API using the provided FastAPI server.

1. Set the environment variable for your model checkpoint (optional):
```bash
export COGNET_MODEL_PATH="./checkpoints/cognet_best.pt"
```

2. Start the server:
```bash
uvicorn deployment.server:app --host 0.0.0.0 --port 8000
```

3. Make a request:
```bash
curl -X POST "http://127.0.0.1:8000/generate" \
     -H "Content-Type: application/json" \
     -d '{"text": "Is the sky blue?"}'
```
