The xFusionCorp Industries ML platform team maintains a Cookiecutter template that new ML projects are generated from. A draft template exists at /root/code/mlops-template/, but it does not render. Correct the template and use it to generate a project.
-
A Cookiecutter template exists at
/root/code/mlops-template/. cookiecutter is installed system-wide. -
The corrected template must satisfy every one of the following:
-
The
cookiecutter.jsondeclares four variables:project_name(defaultmy-ml-project)author(defaultxFusionCorp)python_version(default3.11)ml_frameworkwith the choicessklearn,pytorch, andtensorflow
-
The generated
requirements.txtlogic:- Contains
scikit-learnwhenml_frameworkissklearn - Contains
torchwhenml_frameworkispytorch - Contains
tensorflowwhenml_frameworkistensorflow
- Contains
-
The generated
README.mdcontent:- Must reference both the
project_nameand theauthorfrom cookiecutter variables.
- Must reference both the
-
The template directory structure
{{cookiecutter.project_name}}/must contain:- Files:
README.mdandrequirements.txt - Directories:
data/,models/,src/, andtests/
- Files:
-
-
Review the existing template in the VS Code explorer and correct everything that prevents it from rendering.
-
Once the template renders, generate a project at
/root/code/churn-model/:cookiecutter /root/code/mlops-template/ -o /root/code/ --no-input project_name=churn-model ml_framework=sklearn
-
The generated project must contain a
requirements.txtlistingscikit-learnand aREADME.mdthat mentionsxFusionCorp.
This is a pretty interesting tool. We have to go through the official documentation to fix the issues properly. Like we have to understand how we can cheeck string matching conditions, nested if-else block, writing cookiecutter.json files configurations, etc. Let's see what we had to fix:
-
Let's open the
cookiecutter.jsonfile in editor. We can notice several issues like missing variables, wrong variable names, etc. -
Let's update with the correct config;
{ "project_name": "my-ml-project", "author": "xFusionCorp", "python_version": "3.11", "ml_framework": ["sklearn", "pytorch", "tensorflow"] } -
Let's open the
requirements.txtfile in editor and update according to this template: day 09 cookiecutter_requirements.txtwe have replaced
=with==to ensure string matching Added conditional ending clause. -
Updated
README.mdwith proper variable referance name. UpdatedAuthortoauthorto call actual variable. -
That's all. You can run the given command:
cookiecutter /root/code/mlops-template/ -o /root/code/ --no-input project_name=churn-model ml_framework=sklearn
If everything is done correctly, It will create the files properly. Otherwise you will get errors. Read them carefully and fix the further issues. Make sure all the directory exists, requirements.txt is created, and README.md updated before submitting the solution.
cookiecutter.jsonis the configuration file that declares the variables and their default values. It can also declare choices for variables.- In the template files, we can use Jinja2 templating syntax to reference the variables and write conditional logic. For example,
- To reference a variable:
{{ cookiecutter.variable_name }} - To write conditional logic we can use if else condition.