Databricks Generative AI Engineer Associate Question 186
Select 3You are tasked with deploying a machine learning model for sentiment analysis in Databricks. To improve the model's performance and usability, you decide to wrap it in a pyfunc model with custom pre- and post-processing logic. Which of the following steps are required to code and deploy this chain correctly?
- A
Define a Python class inheriting from
mlflow.pyfunc.PythonModeland implementload_contextandpredictmethods. - B
Write the pre-processing logic inside the
load_contextmethod and the post-processing logic inside thepredictmethod. - C
Package the model and additional dependencies using
conda.yamlorrequirements.txt. - D
Log the
pyfuncmodel to MLflow usingmlflow.pyfunc.log_model. - E
Directly deploy the
pyfuncmodel without testing the pre- and post-processing logic.
Show answer and explanation
Correct answers: A, C, D
Explanation
To code and deploy a pyfunc model with pre- and post-processing, you must define a Python class inheriting from mlflow.pyfunc.PythonModel, implement the load_context and predict methods, package necessary dependencies, and log the model in MLflow. Testing the model is essential, but the deployment process does not involve skipping this step.
- A. Correct.
Correct: To create a
pyfuncmodel, you must define a Python class inheriting frommlflow.pyfunc.PythonModeland implement theload_contextandpredictmethods, which are key entry points. - B. Incorrect.
Incorrect: The pre-processing logic should typically be included in the
predictmethod itself, asload_contextis primarily used for loading any required artifacts or resources. - C. Correct.
Correct: Additional dependencies required by the
pyfuncmodel should be specified in aconda.yamlorrequirements.txtfile to ensure a reproducible environment. - D. Correct.
Correct: Once the model with pre- and post-processing logic is implemented, it must be logged to MLflow using
mlflow.pyfunc.log_modelfor deployment. - E. Incorrect.
Incorrect: Testing the pre- and post-processing logic is a critical step to ensure the correctness and reliability of the deployed model.