A PyTorch training loop utility
Project description
Cognixis
Cognixis is a Python package that provides a set of utilities for building and training regression models using PyTorch. It includes functionality for creating a regression model using a Transformer Encoder, preparing data, and training the model on provided datasets. This package aims to streamline the process of implementing regression tasks with neural networks, focusing on ease of use and flexibility.
Installation
To install Cognixis, you can clone the repository and install the dependencies manually or use a pip install if available.
git clone https://github.com/yourusername/cognixis.git
cd cognixis
pip install -r requirements.txt
Usage
Once installed, you can use the package to import the Regression class, its components (Encoder, DataGenerator, Trainer), and various utilities for model training and evaluation.
Importing the Package
from cognixis import regression
Creating a Regression Model
You can create a regression model by initializing the Encoder class:
Initialize Encoder for regression task
input_dim = 10 # Number of input features
output_dim = 1 # Number of output dimensions (single value)
model = regression.Encoder(input_dim, output_dim)
Preparing the Data
You can prepare your dataset using the DataGenerator class, which will split the data into training and testing sets and load it into PyTorch DataLoader objects:
# Example numpy arrays for X (features) and y (targets)
import numpy as np
X = np.random.randn(1000, 10) # 1000 samples, 10 features
y = np.random.randn(1000) # 1000 target values
# Initialize DataGenerator
data_generator = regression.DataGenerator(X, y)
# Access DataLoaders for training and testing
train_loader = data_generator.train_loader
test_loader = data_generator.test_loader
Training the Model
You can use the Trainer class to train your model on the dataset:
import torch.optim as optim
import torch.nn as nn
# Define loss function and optimizer
criterion = nn.MSELoss() # Mean Squared Error Loss for regression
optimizer = optim.Adam(model.parameters(), lr=0.001)
# Initialize the Trainer
trainer = regression.Trainer(model, optimizer, criterion, device="cpu")
# Train the model
train_losses = trainer.train(train_loader, num_epochs=50)
Evaluating the Model
Once the model is trained, you can evaluate it on the test dataset:
# Evaluate the model
test_loss = trainer.evaluate(test_loader)
Example: Full Workflow
Here is a complete example that shows how to train and evaluate a model:
from cognixis import regression
import numpy as np
import torch.optim as optim
import torch.nn as nn
# Generate random dataset
X = np.random.randn(1000, 10)
y = np.random.randn(1000)
# Initialize DataGenerator
data_generator = regression.DataGenerator(X, y)
# Create a model instance
input_dim = 10
output_dim = 1
model = regression.Encoder(input_dim, output_dim)
# Define loss function and optimizer
criterion = nn.MSELoss()
optimizer = optim.Adam(model.parameters(), lr=0.001)
# Initialize Trainer
trainer = regression.Trainer(model, optimizer, criterion, device="cpu")
# Train the model
train_losses = trainer.train(data_generator.train_loader, num_epochs=50)
# Evaluate the model
test_loss = trainer.evaluate(data_generator.test_loader)
Utilities
Model Summary
You can get a summary of your model using the summary function:
from cognixis import summary
# Get model summary
model_summary = summary(model, input_shape=(1, 10), depth=2) # Example input shape
print(model_summary)
Displaying the Source Code of the Train Function You can also view the source code of the train function:
from cognixis import train_code
# Display the train function source code
train_code()
License This project is licensed under the MIT License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cognixis-0.1.8.tar.gz.
File metadata
- Download URL: cognixis-0.1.8.tar.gz
- Upload date:
- Size: 5.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0eca6c752f1abfd4fb86f99700494d8f59d90d64b1a61ee0d747610ccceb1969
|
|
| MD5 |
f25ccc30c0b4bf343671fdb5fb2db8dc
|
|
| BLAKE2b-256 |
439709f7cc6d714ff6605ef828b04485fb4e416569e45e1d0b04a99af02d68f9
|
File details
Details for the file cognixis-0.1.8-py3-none-any.whl.
File metadata
- Download URL: cognixis-0.1.8-py3-none-any.whl
- Upload date:
- Size: 5.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
54b6e9b5adae5c33e48c5e90b4eb533b5aa3bd99e8a3bd25a0be6eceb1723d2a
|
|
| MD5 |
39e3e90d3b8cceac34a056c30a96d11a
|
|
| BLAKE2b-256 |
69283239c6fb0f31af0589c119aa2e5b3a7b14543d0394dcfb81e1e641c6da9a
|