Overview#
The examples folder contains a complete machine-learning pipeline built with cinnamon. It is a good starting point to see how components and configurations work together in a real project.
The pipeline covers:
A
DataLoaderthat downloads and parses the IMDB dataset.Two
Processorcomponents — one for tf-idf features, one for label encoding.An
SVCModelwrapping scikit-learn’s SVC classifier.An
SVCBenchmarkthat wires everything together and evaluates the model.
All components are registered in the Registry and can be swapped independently.
Project layout#
examples/
components/
data_loader.py ← IMDBLoader
processor.py ← TfIdfProcessor, LabelProcessor
model.py ← SVCModel
benchmark.py ← SVCBenchmark
configurations/
data_loader.py ← IMDBLoaderConfig
processor.py ← TfIdfProcessorConfig, LabelProcessor registration
model.py ← SVCModelConfig
benchmark.py ← SVCBenchmarkConfig
demos/
demo_data_loader.py ← run IMDBLoader standalone
demo_benchmark.py ← run the full pipeline
Installation#
Install cinnamon and the example dependencies:
pip install "cinnamon-core[examples]"
Running the demos#
Run the full benchmark pipeline, from the repository root:
python -m examples.demos.demo_benchmark
Run only the data loader:
python -m examples.demos.demo_data_loader
Run them as modules, from the root rather than from inside examples. The
components are bound by their full import path, examples.components.benchmark.SVCBenchmark,
so the directory that has to be importable is the one holding examples.
Running python demos/demo_benchmark.py from inside examples fails with
ModuleNotFoundError: No module named 'examples' at the moment the first
component is built.
Both scripts call Registry.build() to discover and register all configurations
under the configurations/ folder before building the components.
Using these components in your own project#
You can reuse the example components and configurations from your own project by
pointing Registry.build() to the examples folder as an external directory:
from pathlib import Path
from cinnamon.registry import Registry
Registry.build(
directory=Path('.'), # your project
external_directories=[Path('path/to/examples')]
)
Once built, you can register configurations that reference the example keys:
from cinnamon.configuration import Configuration, Param
from cinnamon.registry import RegistrationKey, register_method
class CustomBenchmarkConfig(Configuration):
data_loader: RegistrationKey = Param(
RegistrationKey(name='data_loader', tags={'imdb'}, namespace='examples')
)
model: RegistrationKey = Param(
RegistrationKey(name='model', tags={'svc'}, namespace='examples')
)
@classmethod
@register_method(name='benchmark', tags={'custom'}, namespace='my_project',
component='components.CustomBenchmark', run_method='run')
def default(cls) -> 'CustomBenchmarkConfig':
return super().default()
Note
Make sure to install the example dependencies before importing example components,
otherwise the import will fail during Registry.build().