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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
AI PROJECT ARCHIVE
|
| 2 |
+
Generated by Arch1tech - Or4cl3 AI Solutions
|
| 3 |
+
Archive Date: 2025-08-30T02:55:06.788Z
|
| 4 |
+
Files Count: 8
|
| 5 |
+
|
| 6 |
+
============================================================
|
| 7 |
+
INSTALLATION INSTRUCTIONS
|
| 8 |
+
============================================================
|
| 9 |
+
|
| 10 |
+
1. Extract all files to your project directory
|
| 11 |
+
2. Install dependencies: pip install -r requirements.txt
|
| 12 |
+
3. Follow the README.md for specific setup instructions
|
| 13 |
+
4. Run the main script or start the training process
|
| 14 |
+
|
| 15 |
+
============================================================
|
| 16 |
+
PROJECT FILES
|
| 17 |
+
============================================================
|
| 18 |
+
|
| 19 |
+
============================================================
|
| 20 |
+
FILE: train.py
|
| 21 |
+
TYPE: python
|
| 22 |
+
DESCRIPTION: Training script using Hugging Face Transformers.
|
| 23 |
+
============================================================
|
| 24 |
+
|
| 25 |
+
import torch
|
| 26 |
+
from transformers import AutoModelForSequenceClassification, Trainer, TrainingArguments, AutoTokenizer
|
| 27 |
+
from datasets import load_dataset
|
| 28 |
+
|
| 29 |
+
# Load dataset
|
| 30 |
+
dataset = load_dataset('glue', 'mrpc')
|
| 31 |
+
|
| 32 |
+
# Load pre-trained model and tokenizer
|
| 33 |
+
model_name = 'bert-base-uncased'
|
| 34 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
| 35 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 36 |
+
|
| 37 |
+
# Tokenize the dataset
|
| 38 |
+
def tokenize_function(examples):
|
| 39 |
+
return tokenizer(examples['sentence1'], examples['sentence2'], truncation=True)
|
| 40 |
+
|
| 41 |
+
tokenized_datasets = dataset.map(tokenize_function, batched=True)
|
| 42 |
+
|
| 43 |
+
# Training arguments
|
| 44 |
+
training_args = TrainingArguments(
|
| 45 |
+
output_dir='./results',
|
| 46 |
+
evaluation_strategy="epoch",
|
| 47 |
+
learning_rate=2e-5,
|
| 48 |
+
per_device_train_batch_size=16,
|
| 49 |
+
per_device_eval_batch_size=16,
|
| 50 |
+
num_train_epochs=3,
|
| 51 |
+
weight_decay=0.01,
|
| 52 |
+
)
|
| 53 |
+
|
| 54 |
+
# Trainer
|
| 55 |
+
trainer = Trainer(
|
| 56 |
+
model=model,
|
| 57 |
+
args=training_args,
|
| 58 |
+
train_dataset=tokenized_datasets['train'],
|
| 59 |
+
eval_dataset=tokenized_datasets['validation'],
|
| 60 |
+
)
|
| 61 |
+
|
| 62 |
+
# Train
|
| 63 |
+
trainer.train()
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
============================================================
|
| 67 |
+
FILE: model_config.json
|
| 68 |
+
TYPE: json
|
| 69 |
+
DESCRIPTION: Model configuration for training and inference.
|
| 70 |
+
============================================================
|
| 71 |
+
|
| 72 |
+
{ "model_type": "BERT", "pretrained": "bert-base-uncased", "num_labels": 2, "output_dir": "./results/" }
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
============================================================
|
| 76 |
+
FILE: requirements.txt
|
| 77 |
+
TYPE: text
|
| 78 |
+
DESCRIPTION: Python package dependencies.
|
| 79 |
+
============================================================
|
| 80 |
+
|
| 81 |
+
torch==1.12.1
|
| 82 |
+
transformers==4.12.3
|
| 83 |
+
datasets==1.14.1
|
| 84 |
+
fastapi==0.78.0
|
| 85 |
+
uvicorn==0.18.1
|
| 86 |
+
pydantic==1.9.0
|
| 87 |
+
numpy==1.21.2
|
| 88 |
+
pandas==1.3.3
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
============================================================
|
| 93 |
+
FILE: README.md
|
| 94 |
+
TYPE: markdown
|
| 95 |
+
DESCRIPTION: Comprehensive documentation with setup instructions.
|
| 96 |
+
============================================================
|
| 97 |
+
|
| 98 |
+
# CognoSphere Unified Multimodal Language Model (CSUMLM)
|
| 99 |
+
This repository provides the implementation of CSUMLM, a Python-based AI system for multimodal language tasks.
|
| 100 |
+
|
| 101 |
+
## Setup Instructions
|
| 102 |
+
1. Clone this repository.
|
| 103 |
+
2. Install the required packages using the command:
|
| 104 |
+
```bash
|
| 105 |
+
pip install -r requirements.txt
|
| 106 |
+
```
|
| 107 |
+
3. Run the training script:
|
| 108 |
+
```bash
|
| 109 |
+
python train.py
|
| 110 |
+
```
|
| 111 |
+
|
| 112 |
+
## Inference
|
| 113 |
+
To deploy the model for inference, run:
|
| 114 |
+
```bash
|
| 115 |
+
uvicorn api:app --reload
|
| 116 |
+
```
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
============================================================
|
| 120 |
+
FILE: data_processing.py
|
| 121 |
+
TYPE: python
|
| 122 |
+
DESCRIPTION: Script for data preparation and cleaning.
|
| 123 |
+
============================================================
|
| 124 |
+
|
| 125 |
+
import pandas as pd
|
| 126 |
+
from sklearn.model_selection import train_test_split
|
| 127 |
+
|
| 128 |
+
def preprocess_data(file_path):
|
| 129 |
+
# Load data
|
| 130 |
+
df = pd.read_csv(file_path)
|
| 131 |
+
# Data cleaning steps
|
| 132 |
+
df = df.dropna()
|
| 133 |
+
|
| 134 |
+
# Split into train and test sets
|
| 135 |
+
train, test = train_test_split(df, test_size=0.2)
|
| 136 |
+
train.to_csv('train.csv', index=False)
|
| 137 |
+
test.to_csv('test.csv', index=False)
|
| 138 |
+
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
============================================================
|
| 142 |
+
FILE: api.py
|
| 143 |
+
TYPE: python
|
| 144 |
+
DESCRIPTION: FastAPI deployment endpoint for inference.
|
| 145 |
+
============================================================
|
| 146 |
+
|
| 147 |
+
from fastapi import FastAPI
|
| 148 |
+
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
| 149 |
+
import torch
|
| 150 |
+
|
| 151 |
+
app = FastAPI()
|
| 152 |
+
|
| 153 |
+
# Load model and tokenizer
|
| 154 |
+
model = AutoModelForSequenceClassification.from_pretrained('bert-base-uncased')
|
| 155 |
+
tokenizer = AutoTokenizer.from_pretrained('bert-base-uncased')
|
| 156 |
+
|
| 157 |
+
@app.post('/predict/')
|
| 158 |
+
async def predict(text: str):
|
| 159 |
+
inputs = tokenizer(text, return_tensors='pt')
|
| 160 |
+
outputs = model(**inputs)
|
| 161 |
+
predictions = torch.argmax(outputs.logits, dim=1)
|
| 162 |
+
return {'predictions': predictions.tolist()}
|
| 163 |
+
|
| 164 |
+
|
| 165 |
+
============================================================
|
| 166 |
+
FILE: Dockerfile
|
| 167 |
+
TYPE: dockerfile
|
| 168 |
+
DESCRIPTION: Docker container configuration.
|
| 169 |
+
============================================================
|
| 170 |
+
|
| 171 |
+
FROM python:3.8-slim
|
| 172 |
+
|
| 173 |
+
WORKDIR /app
|
| 174 |
+
|
| 175 |
+
COPY requirements.txt ./
|
| 176 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 177 |
+
|
| 178 |
+
COPY . ./
|
| 179 |
+
|
| 180 |
+
CMD ["uvicorn", "api:app", "--host", "0.0.0.0", "--port", "8000", "--reload"]
|
| 181 |
+
|
| 182 |
+
|
| 183 |
+
============================================================
|
| 184 |
+
FILE: test_model.py
|
| 185 |
+
TYPE: python
|
| 186 |
+
DESCRIPTION: Unit tests for model validation.
|
| 187 |
+
============================================================
|
| 188 |
+
|
| 189 |
+
import pytest
|
| 190 |
+
from fastapi.testclient import TestClient
|
| 191 |
+
from api import app
|
| 192 |
+
|
| 193 |
+
def test_prediction():
|
| 194 |
+
client = TestClient(app)
|
| 195 |
+
response = client.post('/predict/', json={'text': 'Hello, world!'})
|
| 196 |
+
assert response.status_code == 200
|
| 197 |
+
assert 'predictions' in response.json()
|
| 198 |
+
|
| 199 |
+
|