
An engineering journey from successful notebooks to reliable, secure, observable, and maintainable Machine Learning systems.
Training a Machine Learning model is an important achievement. Deploying one that consistently delivers business value is a different engineering challenge. A model can look excellent in a notebook yet fail with changing data, unexpected inputs, or infrastructure limitations.
This second article in our Machine Learning series explores the transition from “I can train a model” to “I can build, evaluate, adapt, secure, deploy, observe, and maintain an ML system.” The central principle is simple: use the simplest model and architecture that reliably produce the required business value.
Previously in this series: Machine Learning for Productivity: Foundations and a Practical Learning Journey.
From a Notebook to an ML System
A notebook is excellent for exploration, but a production system must validate incoming data, handle failures, protect information, identify model versions, and monitor performance. Consider a model that prioritizes support tickets: predictive accuracy alone does not guarantee reliable integration into the support workflow. The model is one component of the solution—not the solution itself.
Underfitting: When the Model Is Too Simple
Underfitting occurs when a model cannot capture important patterns. A useful laboratory is to generate nonlinear data and fit a straight line, then compare it with a more flexible model. Poor performance on both training and validation data may indicate insufficient flexibility. ChatGPT can help design the demonstration, but the measurements (not the explanation) must support the conclusion.
Overfitting: When the Model Learns Too Much
Overfitting occurs when a model learns training-specific noise instead of generalizable patterns. Train decision trees at increasing depths and compare training and validation errors. A widening gap can indicate overfitting. An excellent training score is not proof of production readiness.
Understanding the Bias–Variance Trade-off
High bias commonly reflects overly restrictive assumptions; high variance reflects sensitivity to the training sample. These concepts help explain underfitting and overfitting, although neither diagnosis should rely on one metric alone. Aim for robust generalization under realistic operating conditions.
Parameters vs. Hyperparameters
Parameters, such as regression coefficients and neural-network weights, are learned during training. Hyperparameters, such as tree depth, regularization strength, or learning rate, are selected outside the usual parameter-learning process. Both affect model behavior, but they require different methods of evaluation.
Hyperparameter Optimization
GridSearchCV and RandomizedSearchCV evaluate candidate configurations; Optuna supports adaptive optimization. Repeatedly selecting models against the same validation data can itself overfit model selection. Preserve an untouched test set, or use nested cross-validation when justified. Compare gains against search cost.
Data Leakage: False Confidence
Leakage occurs when information unavailable at prediction time influences training or evaluation. A useful experiment deliberately scales a complete dataset before splitting, then contrasts it with a correctly constructed training-only preprocessing pipeline. Also inspect future-looking fields, duplicates, and related records crossing partitions. Excellent metrics from an invalid evaluation are not reliable evidence.
Pipelines and Reproducibility
Use scikit-learn Pipeline and ColumnTransformer to connect preprocessing and estimators while reducing leakage risk. Record dataset snapshots, code commits, dependency versions, random seeds, model configurations, and evaluation protocols. Seeds improve repeatability but do not guarantee identical outcomes on all hardware.
Imbalanced Data and Better Evaluation
For rare events, accuracy can be misleading. Inspect confusion matrices, precision, recall, F1, ROC curves, and precision–recall curves. Choose thresholds based on the cost of false positives and false negatives. For example, missing a critical failure may be more expensive than reviewing an extra alert. Always evaluate against the relevant business baseline.
Model Explainability
Feature importance and methods such as SHAP can help explain how input variables influence predictions under specific assumptions. These explanations support debugging and communication, but explainability is not causality: a feature associated with a prediction need not cause the outcome.
Learning Curves and Diagnostics
Learning curves show training and validation performance as training-set size changes. They help investigate whether additional data, different features, or model complexity might help. Treat the curves as clues and combine them with error analysis and controlled experiments.
Introduction to Hugging Face
Hugging Face provides models, datasets, tokenizers, tutorials, and libraries such as Transformers. Pretrained models accelerate experimentation, but licensing, provenance, security, hardware requirements, and task-specific evaluation remain essential.
Run and Compare Pretrained Models
Compare at least two pretrained models using the same task dataset and comparable conditions. Record model revision, hardware, memory, latency, inference settings, output quality, and repeated-run variability. A larger model may improve some outcomes while imposing higher costs; select according to requirements, not parameter count.
Understanding Transformers
Text is divided into tokens, mapped into embeddings, and processed with positional information through transformer blocks containing attention mechanisms. The model produces logits; a decoding strategy selects subsequent tokens. These components help explain context limits, generation variability, and resource consumption. Transformers extend ML, they do not replace simpler algorithms for every task.
Customize an Existing LLM: Qwen3 Laboratory
A practical laboratory can compare a base Qwen3 model with a local variant configured using persistent system instructions and inference parameters such as temperature, top-p, and context limits. Workflow: Base model → instructions → inference configuration → controlled evaluation → comparison. Such customization changes behavior at inference time; it does not train a new foundation model or modify weights. Consult Ollama documentation for supported local configuration options.
Behavioral Bias and Consistency Experiment
Compare multiple variants with different persistent instructions against the same evaluation set. Measure task accuracy when objectively measurable, instruction adherence, unsupported claims, consistency, latency, token usage, and human correction effort. Distinguish prompt-induced behavioral bias from bias encoded in training data and model weights. Repeat trials and record settings to make the comparison reproducible.
Fine-Tuning vs. Prompt Customization vs. RAG
Prompt customization changes instructions; inference settings affect decoding; workflow specialization changes application integration; and RAG supplies external information without changing model weights. Supervised fine-tuning (SFT) updates weights, while LoRA and QLoRA provide parameter-efficient adaptation approaches. Fine-tuning requires a dataset, evaluation, and resources. Start with the least costly method that meets the task.
Optional Educational Experiment: Small Transformer
Training a small transformer from scratch can clarify tokenization, embeddings, attention, loss functions, and optimization. It is an educational laboratory—not a competitive LLM or evidence that a new production-grade foundation model has been created. PyTorch tutorials and TensorFlow tutorials provide learning material.
Machine Learning Security
Threats include data poisoning, adversarial inputs, model extraction, untrusted dependencies, compromised model artifacts, and unsafe deserialization. Loading untrusted pickle-based files, including some joblib artifacts, can execute code. Verify provenance, artifact integrity, dependency versions, access controls, and secret handling. ChatGPT may help draft threat models, but security controls require independent review and testing.
Privacy and Data Governance
Document personal-data handling, provenance, permissions, retention, and model or dataset licenses. Anonymization and pseudonymization are not interchangeable: pseudonymized data can still be personal data. Governance should cover how information is collected, transformed, accessed, retained, and deleted.
Package and Serve a Model
A small model can be served behind a FastAPI endpoint with input validation, explicit model versions, timeouts, error handling, and authentication. joblib can serialize trusted scikit-learn artifacts, but never load untrusted files. ONNX may be useful for supported deployment scenarios.
Containers and Reproducibility
Docker and Podman package runtime dependencies, but containers alone do not ensure reproducibility. Pin dependencies, version images and model artifacts, scan vulnerabilities, avoid unnecessary privileges, and inject secrets securely. Maintain a tested rollback path.
Cloud Deployment: Architecture Before Provider
Compare deployment options against workload needs: CPU or GPU, synchronous or asynchronous inference, data sensitivity, availability, latency, and cost. Azure Machine Learning, Amazon SageMaker AI, and OCI Data Science are useful reference points. A lightweight scikit-learn model may need only a modest CPU service.
Observability: Understanding Production Behavior
Monitor latency, throughput, errors, resource usage, and service availability alongside input distributions, prediction distributions, model versions, and quality metrics when labels become available. For generative systems, track token usage and inference duration. Do not assume every model confidence score is a calibrated probability.
Data Drift and Concept Drift
Data drift means incoming input distributions change relative to a reference period. Concept drift means relationships between inputs and outcomes change. Simulate a distribution shift and observe quality degradation. Define investigation thresholds, retraining criteria, and human approval gates; drift detection alone does not prove retraining is needed.
MLOps: The Complete Lifecycle
MLOps coordinates data → experimentation → training → validation → registry → deployment → monitoring → retraining → governance. Track approved model versions and evidence, automate appropriate quality gates, and prepare rollback. MLflow is one resource for experiment tracking and model lifecycle practices. MLOps is broader than putting a notebook behind an API.
How ChatGPT Helps Across the Lifecycle
ChatGPT can explain bias–variance, propose controlled experiments, review pipelines, suggest leakage checks, compare tuning strategies, interpret errors, draft tests, assist threat modeling, and document incidents. It is a copilot, not an authority. Verify generated code, security recommendations, model behavior, and architecture against official documentation and measured results.
Cost, Productivity and Engineering Economics
Assess the baseline without ML, decision improvement, human time saved, correction effort, false-positive and false-negative costs, latency, training and inference costs, cloud expenses, maintenance, security, and reliability. A sophisticated model can be a poor investment if it introduces excessive operational burden. Choose the simplest model and architecture that reliably deliver the required value.
Putting Everything Together: End-to-End Architecture
A production request-prioritization system might use ingestion → validation → feature processing → inference → decision support → human review. Offline workflows handle training, evaluation, registry approval, and deployment; cross-cutting controls handle authentication, monitoring, provenance, rollback, and governance. A successful notebook proves an experiment worked under specific conditions—not that the complete system is ready for production.
Closing Perspective
Learning ML begins with algorithms and experiments; ML engineering adds architecture, security, operations, governance, and economics. Sometimes a linear model is enough; sometimes a pretrained model is justified; sometimes a deterministic rule is better than ML. The goal is not the most sophisticated model. It is the simplest reliable system that solves the problem and justifies its cost.
Official Learning Resources
Use these primary resources to reproduce experiments and verify implementation details. Documentation and course availability can change.
- scikit-learn User Guide
- Optuna Documentation
- Hugging Face Learn
- Hugging Face Transformers
- Qwen3 Repository
- Ollama Documentation
- PyTorch Tutorials
- TensorFlow Tutorials
- FastAPI Documentation
- MLflow Documentation
- Docker Documentation
- Podman Documentation
- ONNX
- Azure Machine Learning
- Amazon SageMaker AI
- OCI Data Science
Frequently Asked Questions
Is a successful notebook enough to deploy a Machine Learning model?
No. Production requires valid evaluation, data checks, security, versioning, serving, monitoring, and rollback.
Does changing a Qwen3 system prompt count as fine-tuning?
No. Persistent instructions can change inference-time behavior, but they do not modify the model weights.
How do I know whether my model is overfitting?
Compare training and validation performance using an appropriate split or cross-validation, then inspect learning curves and error patterns.
When should an ML system be retrained?
When evidence shows that performance or operating conditions justify retraining; drift alerts alone are not sufficient.
What is the most important production ML metric?
There is no universal metric. Select quality, latency, reliability, human effort, and cost measures that reflect the actual business decision.