When building an MLflow PyFunc wrapper for a text classification model, the system receives a raw string as input, which requires lowercasing and tokenization prior to prediction. Similarly, the model's direct output (an array of probabilities) needs conversion into a human-readable label string before being sent back to the user. Within the structure of the PyFunc class, where is the most appropriate place to implement these necessary data transformations?
Answer & explanation
Correct answer: C
WHY C is correct: In an MLflow PyFunc model, the predict() method is the single point of entry for every inference request. Pre-processing (lowercase, tokenize) should be applied first within predict() to transform raw input, then the model is called, then post-processing (array → label) should be applied to the model's output before the result is returned. This keeps the full input→output contract inside the PyFunc class.
WHY NOT A: __init__() runs once at object creation time. It is used to load artifacts, not to transform per-request data. Pre-processing cannot live there because it needs access to each individual inference input.
WHY NOT B: load_context() is called by MLflow once during model loading to set up resources such as loading custom files or initializing state. It is not called on each prediction request and cannot hold per-request transformations.
WHY NOT D: Splitting post-processing into a separate REST endpoint breaks the single-endpoint contract expected by model serving clients and fragment the inference pipeline across two network calls.