{"id":28625311,"url":"https://github.com/marwan116/model-composer","last_synced_at":"2026-04-28T01:33:03.852Z","repository":{"id":173791567,"uuid":"650428514","full_name":"marwan116/model-composer","owner":"marwan116","description":"Easily compose a model from a set of base models","archived":false,"fork":false,"pushed_at":"2023-06-18T23:19:23.000Z","size":174,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-06-12T08:11:27.609Z","etag":null,"topics":["data-science","machine-learning","neural-network","python","tensorflow"],"latest_commit_sha":null,"homepage":"https://model-composer.readthedocs.io/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/marwan116.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-06-07T03:51:39.000Z","updated_at":"2023-06-19T00:01:21.000Z","dependencies_parsed_at":null,"dependency_job_id":"99650fe2-8b1b-428c-aeb9-be5ce3dad3f3","html_url":"https://github.com/marwan116/model-composer","commit_stats":null,"previous_names":["marwan116/model-composer"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/marwan116/model-composer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marwan116%2Fmodel-composer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marwan116%2Fmodel-composer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marwan116%2Fmodel-composer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marwan116%2Fmodel-composer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/marwan116","download_url":"https://codeload.github.com/marwan116/model-composer/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marwan116%2Fmodel-composer/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32362781,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-27T20:07:02.737Z","status":"ssl_error","status_checked_at":"2026-04-27T20:07:00.910Z","response_time":128,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["data-science","machine-learning","neural-network","python","tensorflow"],"created_at":"2025-06-12T08:10:14.364Z","updated_at":"2026-04-28T01:33:03.846Z","avatar_url":"https://github.com/marwan116.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Model Composer\n\n\u003cbr\u003e\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## 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 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","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarwan116%2Fmodel-composer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarwan116%2Fmodel-composer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarwan116%2Fmodel-composer/lists"}