cmn-ai


Namecmn-ai JSON
Version 0.1.0 PyPI version JSON
download
home_pageNone
SummaryA comprehensive machine learning library with utilities for vision, text, and tabular data
upload_time2025-08-12 15:35:55
maintainerNone
docs_urlNone
authorNone
requires_python>=3.13
licenseMIT
keywords deep-learning machine-learning tabular text vision
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # cmn_ai

> A high-performance machine learning library for accelerating AI, Deep Learning, and Data Science workflows

<p align="center">
  <img src="https://raw.githubusercontent.com/ImadDabbura/cmn_ai/main/logo.png" width="300" height="200" alt="cmn_ai logo">
</p>

<div align="center">

[![Python](https://img.shields.io/badge/python-3.13+-blue.svg)](https://www.python.org/downloads/)
[![PyPI version](https://img.shields.io/pypi/v/cmn_ai.svg)](https://pypi.org/project/cmn_ai/)
[![Downloads](https://img.shields.io/pypi/dm/cmn_ai.svg)](https://pypi.org/project/cmn_ai/)
[![Coverage](https://codecov.io/gh/imaddabbura/cmn_ai/branch/main/graph/badge.svg)](https://codecov.io/gh/imaddabbura/cmn_ai)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![Imports: isort](https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336)](https://pycqa.github.io/isort/)

[Installation](#installation) •
[Quick Start](#quick-start) •
[Documentation](https://imaddabbura.github.io/cmn_ai/) •
[Examples](#examples) •
[Contributing](#contributing)

</div>

## Overview

**cmn_ai** is a comprehensive Python machine learning library designed to accelerate AI, Deep Learning, and Data Science workflows. Built from extensive real-world experience, it provides robust, reusable components for PyTorch-based deep learning and scikit-learn compatible tabular data processing.

The library follows **Boyd's Law** — _speed of iteration beats quality of iteration_ — enabling rapid experimentation and faster delivery of machine learning solutions.

## Key Features

### 🚀 **Accelerated Development**

- Pre-built modules eliminate boilerplate code
- Flexible callback system for training customization
- Seamless integration with existing workflows

### 🎯 **Best Practices Built-In**

- Years of ML engineering experience distilled into reusable components
- Robust error handling and memory management
- Consistent APIs across all modules

### 🔧 **Framework Integration**

- **Deep Learning**: Built on PyTorch with flexible `Learner` architecture
- **Tabular ML**: Full scikit-learn `Pipeline` and `ColumnTransformer` compatibility
- **Visualization**: Integrated plotting utilities for models and data

### 📊 **Domain-Specific Tools**

- **Vision**: Computer vision utilities with `VisionLearner` and batch visualization
- **Text**: NLP preprocessing and dataset handling with `TextList`
- **Tabular**: EDA tools and scikit-learn compatible transformers

## Installation

### From PyPI (Recommended)

```bash
pip install cmn-ai
```

### Development Installation

```bash
git clone https://github.com/ImadDabbura/cmn_ai.git
cd cmn_ai
pip install poetry
poetry install
```

## Quick Start

### Deep Learning with Learner

```python
from cmn_ai.learner import Learner
from cmn_ai.callbacks.training import DeviceCallBack, Recorder

# Create a learner with callbacks
learner = Learner(model, dls, loss_func, opt_func, callbacks=[Recorder("lr")])
learner.add_callback(DeviceCallBack("cuda:0"))

# Train your model
learner.fit(epochs=10, lr=1e-3)
```

### Vision Tasks

```python
from cmn_ai.vision import VisionLearner

# Vision-specific learner with built-in utilities
vision_learner = VisionLearner(model, dls, loss_func)
vision_learner.show_batch()  # Visualize training data
vision_learner.fit(epochs=20, lr=1e-4)
```

### Tabular Data Processing

```python
import pandas as pd
from cmn_ai.tabular.preprocessing import DateTransformer
from sklearn.pipeline import Pipeline

# Scikit-learn compatible preprocessing
x = pd.DataFrame(
    pd.date_range(start=pd.to_datetime("1/1/2018"), end=pd.to_datetime("1/08/2018"))
)
tfm = DateTransformer(drop=False)
tfm.fit_transform(X_train, y_train)
```

## Core Architecture

### Learner System

The `Learner` class provides a flexible foundation for training deep learning models with:

- Exception-based callback system for fine-grained training control
- Automatic mixed precision support
- Built-in logging and metrics tracking
- Memory optimization utilities

### Callback Framework

Fine-grained training control through exception-based callbacks:

- `CancelBatchException`: Skip current batch
- `CancelStepException`: Skip optimizer step
- `CancelBackwardException`: Skip backward pass
- `CancelEpochException`: Skip current epoch
- `CancelFitException`: Stop training entirely

### Modular Design

```
cmn_ai/
├── learner.py          # Core Learner class
├── callbacks/          # Training callbacks
├── vision/            # Computer vision utilities
├── text/              # NLP processing tools
├── tabular/           # Traditional ML tools
├── utils/             # Core utilities
├── plot.py            # Visualization tools
└── losses.py          # Custom loss functions
```

## Examples

### Training Loop Customization

```python
from functools import partial
from cmn_ai.callbacks.schedule import BatchScheduler
from cmn_ai.callbacks.training import MetricsCallback, ProgressCallback
from torcheval.metrics import MulticlassAccuracy
import torch.optim as opt

sched = partial(opt.lr_scheduler.OneCycleLR, max_lr=6e-2, total_steps=100)
learner = Learner(model, dls, loss_func, opt_func)
learner.add_callbacks(
    [
        ProgressCallback(),
        BatchScheduler(sched),
        MetricsCallback(accuracy=MulticlassAccuracy(nm_classes=10)),
    ]
)

learner.fit(epochs=50, lr=1e-3)
```

### Custom Callback Creation

```python
from cmn_ai.callbacks import Callback


class CustomCallback(Callback):
    def after_batch(self):
        if self.loss < self.threshold:
            print(f"Threshold reached at batch {self.batch}")
```

## Documentation

**📖 [Full Documentation](https://imaddabbura.github.io/cmn_ai/)**

**TODO**:

- [ ] [API Reference](https://imaddabbura.github.io/cmn_ai/api/)
- [ ] [Tutorial Notebooks](https://imaddabbura.github.io/cmn_ai/tutorials/)
- [ ] [Advanced Usage](https://imaddabbura.github.io/cmn_ai/advanced/)

## Development

### Setup Development Environment

```bash
git clone https://github.com/ImadDabbura/cmn_ai.git
cd cmn_ai
poetry install
```

### Run Tests

```bash
# Full test suite
poetry run pytest

# With coverage
poetry run pytest --cov=cmn_ai

# Specific test file
poetry run pytest tests/test_learner.py
```

### Code Quality

```bash
# pre-commit will take care of all things formatting, linting, syntax errors,
# tests, etc.
pre-commit run --all-files
```

### Build Documentation

```bash
mkdocs serve    # Local development server
mkdocs build    # Build documentation
```

## Requirements

- **Python**: 3.13+
- **Core Dependencies**: PyTorch, scikit-learn, NumPy, pandas
- **Optional**: matplotlib, seaborn (for plotting)

## Roadmap

- [ ] Distributed training support
- [ ] Additional vision architectures
- [ ] Advanced NLP utilities
- [ ] AutoML capabilities
- [ ] Model deployment tools

## 🙌 Contributing

Contributions are what make the open-source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have suggestions for adding or removing projects, please fork the repo, make your changes, and create a pull request. You can also simply open an issue with the tag "enhancement".

**Stay tuned for contribution guidelines!**

## License

Licensed under the [Apache License 2.0](LICENSE).

## Citation

If you use cmn_ai in your research, please cite:

```bibtex
@software{cmn_ai,
  title={cmn_ai: A Machine Learning Library for Accelerated AI Workflows},
  author={Imad Dabbura},
  url={https://github.com/ImadDabbura/cmn_ai},
  year={2024}
}
```

---

<div align="center">
  <strong>Built with ❤️ for the ML community</strong>
</div>

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "cmn-ai",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.13",
    "maintainer_email": null,
    "keywords": "deep-learning, machine-learning, tabular, text, vision",
    "author": null,
    "author_email": "ImadDabbura <imad.dabbura@hotmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/d4/80/7e9d9f73b11d4c26abc0c5093745c185d16f298bd8af5527e14fd1db2212/cmn_ai-0.1.0.tar.gz",
    "platform": null,
    "description": "# cmn_ai\n\n> A high-performance machine learning library for accelerating AI, Deep Learning, and Data Science workflows\n\n<p align=\"center\">\n  <img src=\"https://raw.githubusercontent.com/ImadDabbura/cmn_ai/main/logo.png\" width=\"300\" height=\"200\" alt=\"cmn_ai logo\">\n</p>\n\n<div align=\"center\">\n\n[![Python](https://img.shields.io/badge/python-3.13+-blue.svg)](https://www.python.org/downloads/)\n[![PyPI version](https://img.shields.io/pypi/v/cmn_ai.svg)](https://pypi.org/project/cmn_ai/)\n[![Downloads](https://img.shields.io/pypi/dm/cmn_ai.svg)](https://pypi.org/project/cmn_ai/)\n[![Coverage](https://codecov.io/gh/imaddabbura/cmn_ai/branch/main/graph/badge.svg)](https://codecov.io/gh/imaddabbura/cmn_ai)\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n[![Imports: isort](https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336)](https://pycqa.github.io/isort/)\n\n[Installation](#installation) \u2022\n[Quick Start](#quick-start) \u2022\n[Documentation](https://imaddabbura.github.io/cmn_ai/) \u2022\n[Examples](#examples) \u2022\n[Contributing](#contributing)\n\n</div>\n\n## Overview\n\n**cmn_ai** is a comprehensive Python machine learning library designed to accelerate AI, Deep Learning, and Data Science workflows. Built from extensive real-world experience, it provides robust, reusable components for PyTorch-based deep learning and scikit-learn compatible tabular data processing.\n\nThe library follows **Boyd's Law** \u2014 _speed of iteration beats quality of iteration_ \u2014 enabling rapid experimentation and faster delivery of machine learning solutions.\n\n## Key Features\n\n### \ud83d\ude80 **Accelerated Development**\n\n- Pre-built modules eliminate boilerplate code\n- Flexible callback system for training customization\n- Seamless integration with existing workflows\n\n### \ud83c\udfaf **Best Practices Built-In**\n\n- Years of ML engineering experience distilled into reusable components\n- Robust error handling and memory management\n- Consistent APIs across all modules\n\n### \ud83d\udd27 **Framework Integration**\n\n- **Deep Learning**: Built on PyTorch with flexible `Learner` architecture\n- **Tabular ML**: Full scikit-learn `Pipeline` and `ColumnTransformer` compatibility\n- **Visualization**: Integrated plotting utilities for models and data\n\n### \ud83d\udcca **Domain-Specific Tools**\n\n- **Vision**: Computer vision utilities with `VisionLearner` and batch visualization\n- **Text**: NLP preprocessing and dataset handling with `TextList`\n- **Tabular**: EDA tools and scikit-learn compatible transformers\n\n## Installation\n\n### From PyPI (Recommended)\n\n```bash\npip install cmn-ai\n```\n\n### Development Installation\n\n```bash\ngit clone https://github.com/ImadDabbura/cmn_ai.git\ncd cmn_ai\npip install poetry\npoetry install\n```\n\n## Quick Start\n\n### Deep Learning with Learner\n\n```python\nfrom cmn_ai.learner import Learner\nfrom cmn_ai.callbacks.training import DeviceCallBack, Recorder\n\n# Create a learner with callbacks\nlearner = Learner(model, dls, loss_func, opt_func, callbacks=[Recorder(\"lr\")])\nlearner.add_callback(DeviceCallBack(\"cuda:0\"))\n\n# Train your model\nlearner.fit(epochs=10, lr=1e-3)\n```\n\n### Vision Tasks\n\n```python\nfrom cmn_ai.vision import VisionLearner\n\n# Vision-specific learner with built-in utilities\nvision_learner = VisionLearner(model, dls, loss_func)\nvision_learner.show_batch()  # Visualize training data\nvision_learner.fit(epochs=20, lr=1e-4)\n```\n\n### Tabular Data Processing\n\n```python\nimport pandas as pd\nfrom cmn_ai.tabular.preprocessing import DateTransformer\nfrom sklearn.pipeline import Pipeline\n\n# Scikit-learn compatible preprocessing\nx = pd.DataFrame(\n    pd.date_range(start=pd.to_datetime(\"1/1/2018\"), end=pd.to_datetime(\"1/08/2018\"))\n)\ntfm = DateTransformer(drop=False)\ntfm.fit_transform(X_train, y_train)\n```\n\n## Core Architecture\n\n### Learner System\n\nThe `Learner` class provides a flexible foundation for training deep learning models with:\n\n- Exception-based callback system for fine-grained training control\n- Automatic mixed precision support\n- Built-in logging and metrics tracking\n- Memory optimization utilities\n\n### Callback Framework\n\nFine-grained training control through exception-based callbacks:\n\n- `CancelBatchException`: Skip current batch\n- `CancelStepException`: Skip optimizer step\n- `CancelBackwardException`: Skip backward pass\n- `CancelEpochException`: Skip current epoch\n- `CancelFitException`: Stop training entirely\n\n### Modular Design\n\n```\ncmn_ai/\n\u251c\u2500\u2500 learner.py          # Core Learner class\n\u251c\u2500\u2500 callbacks/          # Training callbacks\n\u251c\u2500\u2500 vision/            # Computer vision utilities\n\u251c\u2500\u2500 text/              # NLP processing tools\n\u251c\u2500\u2500 tabular/           # Traditional ML tools\n\u251c\u2500\u2500 utils/             # Core utilities\n\u251c\u2500\u2500 plot.py            # Visualization tools\n\u2514\u2500\u2500 losses.py          # Custom loss functions\n```\n\n## Examples\n\n### Training Loop Customization\n\n```python\nfrom functools import partial\nfrom cmn_ai.callbacks.schedule import BatchScheduler\nfrom cmn_ai.callbacks.training import MetricsCallback, ProgressCallback\nfrom torcheval.metrics import MulticlassAccuracy\nimport torch.optim as opt\n\nsched = partial(opt.lr_scheduler.OneCycleLR, max_lr=6e-2, total_steps=100)\nlearner = Learner(model, dls, loss_func, opt_func)\nlearner.add_callbacks(\n    [\n        ProgressCallback(),\n        BatchScheduler(sched),\n        MetricsCallback(accuracy=MulticlassAccuracy(nm_classes=10)),\n    ]\n)\n\nlearner.fit(epochs=50, lr=1e-3)\n```\n\n### Custom Callback Creation\n\n```python\nfrom cmn_ai.callbacks import Callback\n\n\nclass CustomCallback(Callback):\n    def after_batch(self):\n        if self.loss < self.threshold:\n            print(f\"Threshold reached at batch {self.batch}\")\n```\n\n## Documentation\n\n**\ud83d\udcd6 [Full Documentation](https://imaddabbura.github.io/cmn_ai/)**\n\n**TODO**:\n\n- [ ] [API Reference](https://imaddabbura.github.io/cmn_ai/api/)\n- [ ] [Tutorial Notebooks](https://imaddabbura.github.io/cmn_ai/tutorials/)\n- [ ] [Advanced Usage](https://imaddabbura.github.io/cmn_ai/advanced/)\n\n## Development\n\n### Setup Development Environment\n\n```bash\ngit clone https://github.com/ImadDabbura/cmn_ai.git\ncd cmn_ai\npoetry install\n```\n\n### Run Tests\n\n```bash\n# Full test suite\npoetry run pytest\n\n# With coverage\npoetry run pytest --cov=cmn_ai\n\n# Specific test file\npoetry run pytest tests/test_learner.py\n```\n\n### Code Quality\n\n```bash\n# pre-commit will take care of all things formatting, linting, syntax errors,\n# tests, etc.\npre-commit run --all-files\n```\n\n### Build Documentation\n\n```bash\nmkdocs serve    # Local development server\nmkdocs build    # Build documentation\n```\n\n## Requirements\n\n- **Python**: 3.13+\n- **Core Dependencies**: PyTorch, scikit-learn, NumPy, pandas\n- **Optional**: matplotlib, seaborn (for plotting)\n\n## Roadmap\n\n- [ ] Distributed training support\n- [ ] Additional vision architectures\n- [ ] Advanced NLP utilities\n- [ ] AutoML capabilities\n- [ ] Model deployment tools\n\n## \ud83d\ude4c Contributing\n\nContributions are what make the open-source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.\n\nIf you have suggestions for adding or removing projects, please fork the repo, make your changes, and create a pull request. You can also simply open an issue with the tag \"enhancement\".\n\n**Stay tuned for contribution guidelines!**\n\n## License\n\nLicensed under the [Apache License 2.0](LICENSE).\n\n## Citation\n\nIf you use cmn_ai in your research, please cite:\n\n```bibtex\n@software{cmn_ai,\n  title={cmn_ai: A Machine Learning Library for Accelerated AI Workflows},\n  author={Imad Dabbura},\n  url={https://github.com/ImadDabbura/cmn_ai},\n  year={2024}\n}\n```\n\n---\n\n<div align=\"center\">\n  <strong>Built with \u2764\ufe0f for the ML community</strong>\n</div>\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A comprehensive machine learning library with utilities for vision, text, and tabular data",
    "version": "0.1.0",
    "project_urls": null,
    "split_keywords": [
        "deep-learning",
        " machine-learning",
        " tabular",
        " text",
        " vision"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "967f60af6be445b022abf753ff91266065ca5fabff03c0269664f6b1b4b09cb1",
                "md5": "2c7d73f85290cc8f5aee69206630be39",
                "sha256": "96c4e715eccd6d4a05d06f4a572e549a36b78fb622368131ceaea880575b92b1"
            },
            "downloads": -1,
            "filename": "cmn_ai-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "2c7d73f85290cc8f5aee69206630be39",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.13",
            "size": 72137,
            "upload_time": "2025-08-12T15:35:54",
            "upload_time_iso_8601": "2025-08-12T15:35:54.307713Z",
            "url": "https://files.pythonhosted.org/packages/96/7f/60af6be445b022abf753ff91266065ca5fabff03c0269664f6b1b4b09cb1/cmn_ai-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "d4807e9d9f73b11d4c26abc0c5093745c185d16f298bd8af5527e14fd1db2212",
                "md5": "1e2652fbeafb8ce1d12cd41de06a2b19",
                "sha256": "324bf76234b72c56a8c2827c4a986d5f7733c3ed82f9a12f8fc9d7840fd87a8c"
            },
            "downloads": -1,
            "filename": "cmn_ai-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "1e2652fbeafb8ce1d12cd41de06a2b19",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.13",
            "size": 462291,
            "upload_time": "2025-08-12T15:35:55",
            "upload_time_iso_8601": "2025-08-12T15:35:55.400128Z",
            "url": "https://files.pythonhosted.org/packages/d4/80/7e9d9f73b11d4c26abc0c5093745c185d16f298bd8af5527e14fd1db2212/cmn_ai-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-08-12 15:35:55",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "cmn-ai"
}
        
Elapsed time: 0.69727s