Name | model-composer JSON |
Version |
0.3.0
JSON |
| download |
home_page | |
Summary | Easily compose a model ensemble from your machine learning models |
upload_time | 2023-06-18 23:11:07 |
maintainer | |
docs_url | None |
author | Marwan Sarieddine |
requires_python | >=3.8,<3.12 |
license | MIT |
keywords |
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# Model Composer
<br>
[![PyPI version shields.io](https://img.shields.io/pypi/v/model-composer.svg)](https://pypi.org/project/model-composer/)
[![PyPI license](https://img.shields.io/pypi/l/model-composer.svg)](https://pypi.python.org/pypi/)
[![PyPI pyversions](https://img.shields.io/pypi/pyversions/model-composer.svg)](https://pypi.python.org/pypi/model-composer/)
[![Downloads](https://pepy.tech/badge/model-composer/month)](https://pepy.tech/project/model-composer)
[![Downloads](https://pepy.tech/badge/model-composer)](https://pepy.tech/project/model-composer)
## Motivation
This use-case prompted the development of `model-composer`:
- You have two tensorflow models, one trained on weekday data and one trained on weekend data
- You would like to compose a single tensorflow model that can be used to generate predictions for any day of the week.
- You want the composed model to be natively defined in tensorflow - i.e. a single "computational graph" that can be easily loaded and used to make predictions.
- You want a single composed model becasuse:
- It is easier to maintain than having to implement the logic to compose the models in every service that needs to make predictions.
- It ensures the performance of the composed model will remain consistent with a native tensorflow model of a similar complexity.
- It is easier to deploy a single model than multiple models
## Documentation
The official documentation is hosted on ReadTheDocs: https://model-composer.readthedocs.io/
## Install
Using pip:
```
pip install model-composer
```
### Extras
Make use of extras to install the model composer implementations that you need:
```bash
pip install model-composer[tensorflow] # compose tensorflow models
pip install model-composer[cloudpathlib] # load models from cloud storage
pip install model-composer[all] # all extras
```
## Quick start
Declare your composed model in a yaml file which defines the components and how they should be composed.
```yaml title="example.yaml"
name: "ride_share_pricing"
components:
- name: weekday_model
path: weekday_model.tf
type: tensorflow
where:
input: is_weekday
operator: eq
value: true
- name: weekend_model
path: weekend_model.tf
type: tensorflow
where:
input: is_weekday
operator: eq
value: false
```
Each component needs to have the following properties:
- `name`: The name of the component model
- `path`: The path to the component model on disk
- `type`: The type of the component model.
- `where`: The condition at which the component model should be used.
We build the weekend model and save it to disk.
```python
import tensorflow as tf
# Build the weekend model
weekend_model = tf.keras.Sequential([
tf.keras.layers.Input(shape=(1,), name="distance"),
tf.keras.layers.Dense(1, name="price")
])
weekend_model.compile(optimizer="adam", loss="mse")
weekend_model.fit(
x={"distance": tf.convert_to_tensor([10, 20], dtype=tf.float32)},
y=tf.convert_to_tensor([10, 20], dtype=tf.float32),
epochs=10
)
weekend_model.save("weekend_model.tf")
```
We build the weekday model and save it to disk.
```python
# Build the weekday model
weekday_model = tf.keras.Sequential([
tf.keras.layers.Input(shape=(1,), name="distance"),
tf.keras.layers.Dense(1, name="price")
])
weekday_model.compile(optimizer="adam", loss="mse")
weekday_model.fit(
x={"distance": tf.convert_to_tensor([10, 20], dtype=tf.float32)},
y=tf.convert_to_tensor([5, 10], dtype=tf.float32),
epochs=10
)
# Save the models
weekday_model.save("weekday_model.tf")
```
We can now build our composed model from the example yaml spec.
```python
import tensorflow as tf
from model_composer import TensorflowModelComposer
composed_model = TensorflowModelComposer().from_yaml("example.yaml")
assert isinstance(composed_model, tf.keras.Model)
composed_model.save("composed_model.tf")
loaded_model = tf.keras.models.load_model("composed_model.tf")
composed_model.predict({
"is_weekday": tf.convert_to_tensor([True, False], dtype=tf.bool),
"distance": tf.convert_to_tensor([10, 20], dtype=tf.float32)
})
```
## Roadmap
- Support for more ML frameworks:
- PyTorch
- Scikit-learn
Raw data
{
"_id": null,
"home_page": "",
"name": "model-composer",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.8,<3.12",
"maintainer_email": "",
"keywords": "",
"author": "Marwan Sarieddine",
"author_email": "sarieddine.marwan@gmail.com",
"download_url": "",
"platform": null,
"description": "# Model Composer\n\n<br>\n\n[![PyPI version shields.io](https://img.shields.io/pypi/v/model-composer.svg)](https://pypi.org/project/model-composer/)\n[![PyPI license](https://img.shields.io/pypi/l/model-composer.svg)](https://pypi.python.org/pypi/)\n[![PyPI pyversions](https://img.shields.io/pypi/pyversions/model-composer.svg)](https://pypi.python.org/pypi/model-composer/)\n[![Downloads](https://pepy.tech/badge/model-composer/month)](https://pepy.tech/project/model-composer)\n[![Downloads](https://pepy.tech/badge/model-composer)](https://pepy.tech/project/model-composer)\n\n\n## Motivation\n\nThis use-case prompted the development of `model-composer`:\n\n- You have two tensorflow models, one trained on weekday data and one trained on weekend data\n- You would like to compose a single tensorflow model that can be used to generate predictions for any day of the week.\n- You want the composed model to be natively defined in tensorflow - i.e. a single \"computational graph\" that can be easily loaded and used to make predictions.\n- You want a single composed model becasuse:\n - It is easier to maintain than having to implement the logic to compose the models in every service that needs to make predictions.\n - It ensures the performance of the composed model will remain consistent with a native tensorflow model of a similar complexity.\n - It is easier to deploy a single model than multiple models\n\n## Documentation\n\nThe official documentation is hosted on ReadTheDocs: https://model-composer.readthedocs.io/\n\n## Install\n\nUsing pip:\n\n```\npip install model-composer\n```\n\n### Extras\n\nMake use of extras to install the model composer implementations that you need:\n\n```bash\npip install model-composer[tensorflow] # compose tensorflow models\npip install model-composer[cloudpathlib] # load models from cloud storage\npip install model-composer[all] # all extras\n```\n\n## Quick start\n\nDeclare your composed model in a yaml file which defines the components and how they should be composed.\n\n```yaml title=\"example.yaml\"\nname: \"ride_share_pricing\"\ncomponents:\n - name: weekday_model\n path: weekday_model.tf\n type: tensorflow\n where:\n input: is_weekday\n operator: eq\n value: true\n - name: weekend_model\n path: weekend_model.tf\n type: tensorflow\n where:\n input: is_weekday\n operator: eq\n value: false\n```\n\nEach component needs to have the following properties:\n\n- `name`: The name of the component model\n- `path`: The path to the component model on disk\n- `type`: The type of the component model.\n- `where`: The condition at which the component model should be used.\n\nWe build the weekend model and save it to disk.\n\n```python\nimport tensorflow as tf\n\n# Build the weekend model\nweekend_model = tf.keras.Sequential([\n tf.keras.layers.Input(shape=(1,), name=\"distance\"),\n tf.keras.layers.Dense(1, name=\"price\")\n])\n\nweekend_model.compile(optimizer=\"adam\", loss=\"mse\")\n\nweekend_model.fit(\n x={\"distance\": tf.convert_to_tensor([10, 20], dtype=tf.float32)},\n y=tf.convert_to_tensor([10, 20], dtype=tf.float32),\n epochs=10\n)\nweekend_model.save(\"weekend_model.tf\")\n```\n\nWe build the weekday model and save it to disk.\n\n```python\n# Build the weekday model\nweekday_model = tf.keras.Sequential([\n tf.keras.layers.Input(shape=(1,), name=\"distance\"),\n tf.keras.layers.Dense(1, name=\"price\")\n])\n\nweekday_model.compile(optimizer=\"adam\", loss=\"mse\")\n\nweekday_model.fit(\n x={\"distance\": tf.convert_to_tensor([10, 20], dtype=tf.float32)},\n y=tf.convert_to_tensor([5, 10], dtype=tf.float32),\n epochs=10\n)\n\n# Save the models\nweekday_model.save(\"weekday_model.tf\")\n```\n\nWe can now build our composed model from the example yaml spec.\n\n```python\nimport tensorflow as tf\nfrom model_composer import TensorflowModelComposer\n\ncomposed_model = TensorflowModelComposer().from_yaml(\"example.yaml\")\n\nassert isinstance(composed_model, tf.keras.Model)\n\ncomposed_model.save(\"composed_model.tf\")\n\nloaded_model = tf.keras.models.load_model(\"composed_model.tf\")\n\ncomposed_model.predict({\n \"is_weekday\": tf.convert_to_tensor([True, False], dtype=tf.bool),\n \"distance\": tf.convert_to_tensor([10, 20], dtype=tf.float32)\n})\n```\n\n## Roadmap\n\n- Support for more ML frameworks:\n - PyTorch\n - Scikit-learn\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Easily compose a model ensemble from your machine learning models",
"version": "0.3.0",
"project_urls": null,
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "f021c9bc04ff94bd1b1473c28deec523154e06621ee036774fbeb26d8b07e6dd",
"md5": "365e344569e45f9d5cd22769fba437bd",
"sha256": "088c80242de963d1f781b34487c727ec546cf648d79ce5ea2ff234c1e50a80a7"
},
"downloads": -1,
"filename": "model_composer-0.3.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "365e344569e45f9d5cd22769fba437bd",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8,<3.12",
"size": 11509,
"upload_time": "2023-06-18T23:11:07",
"upload_time_iso_8601": "2023-06-18T23:11:07.166079Z",
"url": "https://files.pythonhosted.org/packages/f0/21/c9bc04ff94bd1b1473c28deec523154e06621ee036774fbeb26d8b07e6dd/model_composer-0.3.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-06-18 23:11:07",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "model-composer"
}