# Artificial Intelligence Wiki

A repository of machine learning, data science, and artificial intelligence (AI) terms for individuals and businesses.

Whether you're looking to explore new concepts or brush up on your terminology, this wiki offers up-to-date information on key topics in data science, machine learning, and deep learning.

Not sure where to start? Check out our definition of [MLOps](/wiki/machine-learning-operations-mlops) to discover a modern approach to model training and deployment.

## What is Artificial Intelligence (AI)?

Artificial Intelligence is an umbrella term for a range of concepts and technologies that allow machines to exhibit human-like capabilities.  Some common implementations include self-driving cars, human-impersonating chatbots, and facial recognition apps.  A few recent breakthroughs have led to applications that don't just mimic human intelligence but go well above and beyond, performing tasks that are otherwise impossible for humans.

AI dates back to the 1950s and has been through several boom and bust cycles.  Over the past few years, we've seen tremendous resurgence in investment and excitement in AI due to the culmination of three key ingredients:&#x20;

1. Abundant and cheap parallel computation with **GPUs**
2. Growing **data** sets and collection techniques
3. Advancements in underlying algorithms -- especially the advent of a neural network-based approach called **Deep Learning**

![Source: NVIDIA](/files/-LvD0gbfAKEIMXcVxdqQ)

AI powers applications used by hundreds of millions of people every day.  Businesses are using AI to perform an almost infinite number of tasks, from implementing recommender systems for e-commerce apps to diagnosing cancer.

### Barriers to AI Adoption

AI is in its infancy and as an early-stage technology it is rapidly changing and challenging to implement.  To gain more widespread adoption, AI needs to overcome a number of hurdles.  These obstacles generally fall into two primary areas:

1. A lack of best practices ([MLOps](/wiki/machine-learning-operations-mlops)) across the entire model lifecycle
2. Infrastructure complexity inherent in developing and productionizing models

Today, Data Scientists only spend around 25% of their time developing models -- the other 75% of their time is spent managing tooling and infrastructure. &#x20;

> *"The biggest barrier to AI adoption is an infrastructure and tooling problem, not an algorithm problem."*\
> \-- Dillon Erb, Paperspace CEO

These are the challenges that end-to-end AI platforms like [**Paperspace**](https://paperspace.com) were built to solve. &#x20;

## Artificial Intelligence + Paperspace

Paperspace enables teams to quickly develop, track, and deploy machine learning models from concept to production.  The platform provides **infrastructure automation** and **model lifecycle management** with organization-wide visibility, reproducibility, and governance as first-class citizens.&#x20;

**For AI Engineers**, Paperspace provides the freedom to use familiar tools. Since Paperspace provides DevOps support and resource orchestration, teams can focus on training algorithms and creating business value.&#x20;

**For organizations**, Paperspace reduces project costs by streamlining hardware resources and data science team productivity.  The Kubernetes-native platform provides a unified ML hub that maximizes speed to deployment and time-to-value.


# Accuracy and Loss

**Accuracy** and **Loss** are the two most well-known and discussed [metrics](/wiki/metrics-in-machine-learning) in machine learning.&#x20;

![Source: Microsoft](/files/-LvH9eRozs1jmP8COBcX)

### Accuracy&#x20;

Accuracy is a method for measuring a classification model’s performance. It is typically expressed as a percentage.  Accuracy is the count of predictions where the predicted value is equal to the true value.  It is binary (true/false) for a particular sample.  Accuracy is often graphed and monitored during the training phase though the value is often associated with the overall or final model accuracy.  Accuracy is easier to interpret than loss.

### Loss

A loss function, also known as a cost function, takes into account the probabilities or uncertainty of a prediction based on how much the prediction varies from the true value. This gives us a more nuanced view into how well the model is performing.&#x20;

Unlike accuracy, loss is not a percentage — it is a summation of the errors made for each sample in training or validation sets.  Loss is often used in the training process to find the "best" parameter values for the model (e.g. weights in neural network). During the training process the goal is to minimize this value.

The most common loss functions are **log loss** and **cross-entropy loss** (which yield the same result when calculating error rates between 0 and 1), as well as **mean squared error**, and **likelihood loss.**&#x20;

Unlike accuracy, loss may be used in both classification and regression problems.

### **Relationship Between Accuracy and Loss**

Most of the time we would observe that accuracy increases with the decrease in loss -- but this is not always the case. Accuracy and loss have different definitions and measure different things.  They often appear to be inversely proportional but there is no mathematical relationship between these two metrics.


# Activation Function

In a neural network, an activation function normalizes the input and produces an output which is then passed forward into the subsequent layer.  Activation functions add non-linearity to the output which enables neural networks to solve non-linear problems.  In other words, a neural network without an activation function is essentially just a [linear regression](/wiki/linear-regression) model.&#x20;

### Activation Function Types

Common activation functions include **Linear**, **Sigmoid**, **Tanh**, and **ReLU** but there are many others.

![](/files/-LvO3qs2RImYjpBE8vln)


# AI Chips for Training and Inference

![The Google TPU, a new breed of AI chips](/files/-LvJUC8Z_r0N8N9ily5Q)

### GPUs

GPU (Graphics Processing Unit) chips were originally developed for rendering 3D graphics onscreen.  Nevertheless, GPUs have proved optimal for specialized computational tasks due to their ability to perform parallel computation in a way that CPUs may not.

How are GPUs different from CPUs?  CPUs perform serial tasks very fast but with very little parallelism. A mid-range CPU may have a handful of cores and a mid-range GPU will have several thousand. GPU cores are much slower/less powerful but run in parallel.  The parallelism of GPUs are optimal for neural networks because of the kind of math that is performed: Sparse matrix multiplication. &#x20;

GPUs were popularized in the ML community after discoveries in 2009 and 2012 during which researchers co-opted NVIDIA GPUs and an NVIDIA library called CUDA to train an image recognition model orders of magnitude faster than was previously possible.&#x20;

Anecdote: GPUs were also popularized in cryptocurrency mining for the same reason -- they can substantially outpace CPUs in tasks that benefit from parallel computation.

NVIDIA shares the GPU market with AMD but NVIDIA dominates the ML segment of the market because of the CUDA (and later on, cuDNN) libraries which have gained widespread usage.

### Are CPUs Used at all in AI?

For performance reasons, CPUs are not optimal for training models. That said, CPUs are often used to perform inference as GPUs are over-tuned for the task.

### AI Accelerators: ASICs & FPGAs

Although GPUs are much faster than CPUs for training ML models, they still contain features that are irrelevant to the ML user. Irrelevant capabilities include computing physics engines, shaders, and 3D environments.  As a result, several purpose-built AI chips are currently under development by tech giants and startups alike:

* FPGAs (field-programmable gate array) are purpose-built but generic enough to accommodate multiple types of tasks, from encryption to encoding. Example: Microsoft Brainwave
* ASICs (application-specific integrated circuit) are typically designed for a single, specific task.  Example: [Google TPU](/wiki/tensor-processing-unit-tpu).

Other examples include: Intel Nervana, Cerebras, Graphcore, SambaNova, Wave Computing, Groq, etc.

### Edge Devices

To deal with latency-sensitive applications or devices that may experience intermittent or no connectivity, models can also be deployed to edge devices.&#x20;

Smartphones and other chips like the Google Edge TPU are examples of very small AI chips use for ML.  They typically perform only the inference side of ML due to their limited power/performance.  Environments might include deployment within a driverless car, robot, or IoT device.

## AI Chips + Gradient

Gradient supports GPUs and CPUs natively in both the hosted and customer-managed environments.  Gradient recently announced upcoming support for the Intel Nervana chip. Other chips will most likely be supported in the future.

#### Related materials

{% embed url="<https://docs.paperspace.com/gradient/instances/instance-types>" %}


# Artifacts

Artifacts is common ML term used to describe the output created by the training process.&#x20; The output could be a fully trained model, a model checkpoint (for resuming training later), or simply a file created during the training process such as an image generated while training a [Generative Adversarial Network](/wiki/generative-adversarial-network-gan) (GAN). &#x20;

In the case of a Deep Learning model, the model artifacts are the trained weights stored in a binary format.

## Artifacts + Gradient

Gradient makes artifact management seamless and intuitive.  Anything saved in the `/artifacts` directory will be automatically captured in Gradient as an [artifact](https://docs.paperspace.com/gradient/data/storage#artifact-storage).  Model artifacts are automatically captured when saved to the `/models` directory.

#### Related Materials

{% embed url="<https://docs.paperspace.com/gradient/data/storage#artifact-storage>" %}


# Artificial General Intelligence (AGI)

### What is Artificial General Intelligence?

The form of AI that exists today is considered *narrow AI.* It is adept at solving specific tasks limited to specific domains but it cannot be extended to perform tasks in other domains easily (see [Transfer Learning](/wiki/transfer-learning))*.*&#x20;

In contrast, Artificial General Intelligence represents an advanced version of AI capable of performing  general tasks often associated with human intelligence.  This requires a combination of flexible "thinking" and adaptability -- it also requires the ability to reason and the concept of memory.

### Does AGI Exist Today?

AGI does not exist yet. Today it is merely a field of study and a popular topic in science fiction.  Many experts believe we are a decade or so away from AGI assuming current investment does not dissipate.  In terms of research trajectories, many believe that [Reinforcement Learning](/wiki/supervised-unsupervised-and-reinforcement-learning#reinforcement-learning) is a viable path towards AGI.  There are several organizations that are actively working to "solve" AGI such as OpenAI and DeepMind. &#x20;

### Impact on society

AI has already made a tremendous impact on society. Yet AI remains constrained in such a way that the need for human labor is still necessary even in fields with a high degree of automation and AI.  Overall, the number of jobs has actually increased in many industries impacted by AI.  This is due in part to a phenomenon called the *Automation Paradox*.  Here's a great snippet from the [Atlantic](https://www.theatlantic.com/business/archive/2016/01/automation-paradox/424437/) on the rise of AI in the legal industry:

> Take the legal industry as an example. Computers are taking over some of the work of lawyers and paralegals, and they’re doing a better job of it. For over a decade, computers have been used to sort through corporate documents to find those that are relevant to lawsuits. This process — called “discovery” in the profession — can run up millions of dollars in legal bills, but electronic methods [can erase the vast majority of those costs](https://www.lexisnexis.com/applieddiscovery/NewsEvents/PDFs/200511_DDEE_LegalLandscape.pdf). Moreover, the computers are often more accurate than humans: In one [study](https://www.lexisnexis.com/applieddiscovery/NewsEvents/PDFs/200511_DDEE_LegalLandscape.pdf), software correctly found 95 percent of the relevant documents, while humans identified only 51 percent."

Many believe that AGI will have a much greater impact than the impact of the form of narrow AI we have today.  If AGI truly does render human labor obsolete the impact would be profound—with vast societal ramifications.  Rising fears of massive unemployment have led to the discussion of Universal Basic Income (UBI) which would provide regular payments to everyone in society.  It is important to note that there are many positive potential outcomes and that these types of fears are often misplaced.  Several predictions of the impact of automation and AI that exist today have been proven false (eg the legal discovery example above).  Societal shifts at this scale are endlessly complex, often counter-intuitive, and generally difficult to theorize. &#x20;


# AUC (Area under the ROC Curve)

![Source: Data Science Central](/files/-LvHDdtKiSfM4WORukWK)

AUC is one of the most important [evaluation metrics](/wiki/metrics-in-machine-learning) for measuring the performance of any classification model. It is a performance measurement for a classification problem at various thresholds settings.&#x20;

The ROC Curve measures how accurately the model can distinguish between two things (e.g. determine if the subject of an image is a dog or a cat). AUC measures the entire two-dimensional area underneath the ROC curve. This score gives us a good idea of how well the classifier will perform.

AUC is related to another evaluation metric called the [Confusion Matrix](/wiki/confusion-matrix).&#x20;


# Automated Machine Learning (AutoML)

Applied AI can be time-consuming, resource-intensive, and challenging. Automated Machine Learning (AutoML) seeks to automate the many cumbersome and repetitive steps of the machine learning pipeline to make it easier to apply machine learning methods to real-world business problems.&#x20;

These are the typical steps that can be automated after the target variable and [evaluation metric](/wiki/metrics-in-machine-learning) criteria have been determined:

1. **Data pre-processing**
2. **Data partitioning**
3. **Feature extraction**
4. **Algorithm selection**
5. **Training**
6. **Tuning**
7. **Ensembling**&#x20;
8. **Deployment**
9. **Monitoring**

AutoML generally speaking is defined as the process of selecting the combination of algorithm and parameters that collectively produce the best performing model automatically. &#x20;

AutoML is a technology that people with limited machine learning expertise (sometimes referred to as *Citizen Data Scientists*) can leverage to produce state-of-the-art models.  Some AutoML tools are “drag-and-drop” or "no code" in that the user can simply upload a dataset and get a trained model. Other more advanced tools are used to free data scientists from the burden of repetitive and time-consuming tasks such as pipeline design and hyperparameter optimization -- but require expertise in machine learning. &#x20;

AutoML leverages [transfer learning](/wiki/transfer-learning), neural architecture search, and other toolsets to determine the best performing model.


# CI/CD for Machine Learning

CI/CD is a software design concept that refers to the combined practices of continuous integration and continuous deployment of applications.  CI refers to building an application and CD refers to deploying it. The concept implies that there is automation around these processes.

![](/files/-LvHFK4Vdkeg2tHWPS8a)

**How is this relevant to ML?**  At a high-level, CI/CD as a great analogy for how ML teams will develop and deploy models in the future.  The current system is messy and ad hoc with no standards or best practices in place. By applying CI/CD methodology, ML teams can be more streamlined and scientific in their approach.

![](/files/-LvHF7ZxOpPjHBWlvhZq)

## CI/CD for Machine Learning + Gradient

Gradient pioneered the concept of CI/CD for machine learning.  The platform is designed to provide this functionality out of the box with [GradientCI](https://gradient.paperspace.com/gradientci) and an [SDK](https://docs.paperspace.com/gradient/gradient-python-sdk/gradient-python-sdk) for constructing advanced pipelines. Here’s a more in-depth blog post on the topic:

{% embed url="<https://blog.paperspace.com/ci-cd-for-machine-learning-ai/>" %}


# Comparison of ML Frameworks

There are several popular frameworks for DNNs and classical ML.  All widely used frameworks are open source. Most but not all support GPU acceleration.

## Deep Learning frameworks

<div align="left"><img src="/files/-LwEmD_aNkyWXiVQpETt" alt=""></div>

**TensorFlow** (by Google): Offers training, distributed training, and inference (TensorFlow Serving) as well as other capabilities such as TFLite (mobile, embedded), Federated Learning (compute on end-user device, share learnings centrally), TensorFlow\.js, (web-native ML), TFX for platform etc.  TensorFlow is widely adopted, especially in enterprise/production-grade ML.  <br>

<div align="left"><img src="/files/-LwEly1m45zmV1d031Y4" alt=""></div>

**Keras** (also by Google): A higher-level wrapper around TensorFlow and other frameworks such as R and CNTK, which form the “backend” to Keras in this context.<br>

<div align="left"><img src="/files/-LwEmWqI7I47OMlGZkFE" alt=""></div>

**PyTorch** (by Facebook): An easy-to-use framework known for rapid prototyping. Facebook recently merged Caffe2 into the PyTorch project to support productionalizing and serving PyTorch-based models. PyTorch is especially popular in the research community.<br>

<div align="left"><img src="/files/-LwEmujRrD-Vz1qdZAT0" alt=""></div>

**Fast.ai** (by Fast.ai team): A library that sits on top of PyTorch to simplify and accelerate deep learning training.  Fast.ai is very new and its full reach is not yet known.<br>

<div align="left"><img src="/files/-LwEnY1FCCyLJfI8MEF2" alt=""></div>

**Microsoft Cognitive Toolkit\*** (by Microsoft): A framework focused on large-scale production deployments.  The community is small relative to other frameworks.\
\* Formerly **CNTK**<br>

<div align="left"><img src="/files/-LwEns_zopfPOTbBo-Pz" alt=""></div>

**MXNet** (by Apache but associated with Amazon): An open source deep learning framework focused on large-scale production deployments.  MXNet is popular at Microsoft, Intel, and Amazon but not in the research community.<br>

<div align="left"><img src="/files/-LwEoAL68gMOyAWyA1QJ" alt=""></div>

**Gluon** (by Amazon and Microsoft): An attempt to create a Keras-like API layer for MXNet and CNTK.  Gluon is not very popular.  <br>

<div align="left"><img src="/files/-LwEoTBvKk2XYgD5061x" alt=""></div>

**Chainer** (by a Japanese company called Preferred Networks):  A deep learning framework that is popular in Japan and supported by tech giants such as IBM, NVIDIA, AWS, and Intel. That said, the Chainer community is relatively small.<br>

<div align="left"><img src="/files/-LwEokOc4jGcUZ6RBU3e" alt=""></div>

**PaddlePaddle** (by Baidu): A scalable deep learning platform originally developed for use on Baidu products that is focused on large-scale production deployments.  The PaddlePaddle community is relatively small.<br>

<div align="left"><img src="/files/-LwEp01Oku5oreNKuUz0" alt=""></div>

**Deeplearning4j** (by Konduit, related to Eclipse): A deep learning programming library built for companies that need support for Java and Scala.  The community is relatively small.<br>

<div align="left"><img src="/files/-LwEpa3U9HKE0EedkEWZ" alt=""></div>

**Caffe** & **Caffe2** (by UC Berkeley): A deep learning framework that is especially suited to image classification and image segmentation. Caffe is not popular anymore but Facebook created a successor called Caffe2 which was recently merged into PyTorch.

## ML frameworks&#x20;

These frameworks are mostly used for “Classical ML” rather than Deep Learning:&#x20;

<div align="left"><img src="/files/-LwEpu9rwWgVsSseffNt" alt=""></div>

**XGBoost**: An open-source library built for one of the most common machine learning algorithms, [gradient boosting](/wiki/gradient-boosting). The community is very large.<br>

<div align="left"><img src="/files/-LwEq8nntcxnljDRUZuO" alt=""></div>

**Scikit-learn**: A machine learning library that provides algorithms for many standard machine learning tasks such as clustering, regression, classification, dimensionality reduction, and more. The community is very large.

## Libraries

Other popular machine learning libraries are typically used when preparing data for later use in ML frameworks. These include:&#x20;

* NumPy (arrays & linear algebra library)
* SciPy (scientific computing library)
* Pandas (data extraction & preparation)
* Matplotlib (plotting & data visualization)


# Confusion Matrix

![](/files/-LvHIIphhNcOOkLBgk9j)

A confusion matrix, typically represented as a table, is a popular [evaluation metric](/wiki/metrics-in-machine-learning) used to **describe the performance of a classification model** (or "classifier").  The table compares predicted and actual values.  The basic components of the table are as follows:

* **True positives (TP):** The prediction was yes, and the true value is yes
* **True negatives (TN):** The prediction was no, and the true value is no
* **False positives (FP):** The prediction was yes, but the true value was no
* **False negatives (FN):** The prediction was no, but the the true value is yes

### Related Metrics

The confusion matrix is closely related to other metrics like Precision, Recall/Sensitivity, Specificity, and F1 Score. Those definitions are as follows:

| **Metric**         | **Formula**           | **Definition**                                        |
| ------------------ | --------------------- | ----------------------------------------------------- |
| Accuracy           | (TP+TN)/(TP+TN+FP+FN) | Percentage of total items classified correctly        |
| Precision          | TP/(TP+FP)            | How accurate the positive predictions are             |
| Recall/Sensitivity | TP/(TP+FN)            | True positive rate (eg to asses false positive rate)  |
| Specificity        | TN/(TN+FP)            | True negative rate (eg to assess false negative rate) |
| F1 score           | 2TP/(2TP+FP+FN)       | A weighted average of precision and recall            |


# Containers

![](/files/-LvOG4k3uFKDVoAjohIO)

Containers are lightweight, secure, and portable environments designed for developing, testing, and hosting software applications.  Containers run on top of VMs or bare-metal servers and were pioneered by  a company called [Docker](https://www.docker.com/resources/what-container).  They have recently become popular in the ML industry.

Container **orchestration** is dominated by Kubernetes, an open source system for automating and scaling application deployment.&#x20;

Container **registries** are where containers are hosted.  Examples include DockerHub and Amazon ECR.

A Docker file is a set of instructions (software packages to include) in a Docker image.  Deploying applications using Docker containers is straightforward.

* Build: Create an image from a Docker file
* Push: Save image in a registry
* Run: Application can be run anywhere
* Pull: Download containers from a registry

Docker tags specify a version e.g. `username/image_name:tag_name`&#x20;

## Containers + Gradient

Gradient can run any Docker container (for Notebooks, Experiments, Jobs, and Deployments) hosted on a public or private container registry.

Gradient maintains a list of [containers](https://docs.paperspace.com/gradient/notebooks/notebook-containers) pre-loaded with various up-to-date ML frameworks, libraries, drivers, and more.

Gradient also includes a way to build containers from a Dockerfile without any expertise in Docker itself.&#x20;

### Related Material

{% embed url="<https://docs.paperspace.com/gradient/notebooks/notebook-containers/building-a-custom-container>" %}


# Convergence

![Source: Stanford](/files/-LvHS7f9OSX0EwNd4h-f)

A machine learning model reaches convergence when it achieves a state during training in which [loss](/wiki/accuracy-and-loss#loss) settles to within an error range around the final value.  In other words, a model converges when additional training will not improve the model.


# Convolutional Neural Network (CNN)

![Source: Towards Data Science](/files/-LvHSjfW_yCbwBPotco2)

A Convolutional Neural Network (CNN), sometimes referred to as a ConvNet, is the most well-known image recognition and classification algorithm.  CNNs were one of the key innovations that led to the deep neural network renaissance in computer vision, which is a subset of machine learning. &#x20;

A typical CNN consists of a combination of convolutional, pooling, and dense layers.

### Run a CNN sample project from the ML Showcase!

{% embed url="<https://ml-showcase.paperspace.com/projects/classifying-clothing-images-with-fashion-mnist>" %}


# Datasets and Machine Learning

Training data used in machine learning can take many forms, including images, MRI scans, text, CSV/tabular data (e.g., database queries), audio recordings, geospatial data (e.g., radar or vector), logs, time-series data (e.g., stock trades), binaries or computer applications, video frames, and many more.

The most common providers of data in machine learning are AWS S3, Snowflake, Redshift, AWS EBS, BigQuery, and on-premise file systems.

## Data Sources

There are several types of storage relevant to ML, though not all interface directly with ML pipelines. These include file systems, object storage, databases, and data warehouses/data lakes.

### **File Systems**

File systems have been around forever and are the most familiar type of storage since every laptop uses a file system. File systems are compatible with all ML frameworks and are easy to use but have limitations that are exacerbated at scale. File systems at large companies are often distributed (e.g. Ceph, Gluster).&#x20;

Network-attached storage (NAS) refers to a shared file system that is accessible by multiple users or compute nodes concurrently.

### **Object Storage**&#x20;

Objects are organized in buckets and are a relatively new type of storage popular in web apps. Object storage systems may be scaled massively and are very common in DevOps and web services. Objects also contain associated metadata.

AWS S3 is the most common/well-known object-store and is used to host datasets for training.&#x20;

### **Databases**

Although databases do not interface directly with ML pipelines, many datasets originate from a database. A dataset must be extracted from a database and stored in a file system or object store such as S3 for training. &#x20;

Common relational databases include Postgres and MySQL, common unstructured or NoSQL databases include MongoDB and CouchDB, and common time series databases include InfluxDB and Prometheus.

### **Data Warehouses & Data Lakes**

Data warehouses are used to store petabyte-scale data that companies collect from various sources. Databases are not used as a direct dataset source for training. &#x20;

A dataset must be extracted from the Data Lake or Data Warehouse and stored in a file system or an object store such as S3 for training.&#x20;

## Train, Test, & Validation Sets Explained

It is standard practice to partition data into two or three data sets: training, test, and sometimes validation, which is recommended. All three should randomly sample a larger body of data.&#x20;

**Training dataset**: The sample of data used to train the model. The model *learns* from this data.

**Validation dataset**: The sample of data used to evaluate the model during development to see how the model performs on new data. This dataset is also used while tuning model [hyperparameters](/wiki/hyperparameter-optimization). During the hyperparameter tuning phase, the model *sees* this data, but does it not *learn* from the data since hyperparameters are not learnable parameters. The validation set is primarily used to to avoid [overfitting](/wiki/overfitting-vs-underfitting) to the training data.

**Test dataset**: The holdout sample of data that is used to evaluate the final model after training and tuning are complete.&#x20;

![ Source: Andrew Ng's Machine Learning Coursera class ](/files/-LvCFnxKOTOnDWBSY7sk)

It is recommended to use a curated approach to creating these datasets, not necessarily just a random split. This is to ensure that the data being tested against represents new real-world data the model will see in the future.

## Public Datasets

These are large (typically labeled) datasets made available for public consumption and are often the starting point for developing a model. There are many famous public datasets such as [MNIST](/wiki/mnist), ImageNet, CIFAR-10, MS COCO, Sentiment140, IMDB, LSUN, and more. Many come from academia and some come from industry.


# Data Science vs Machine Learning vs Deep Learning

### TL;DR

* Data Science is used to **find insight** in data
* Machine Learning models **make predictions**
* Deep Learning can **take actions** autonomously (e.g. drive a car)

### Data Science

Data science is the process of manually extracting insight from data using the basic principles and techniques of statistical analysis. This includes basic tasks like finding p values and confidence intervals. Though fairly complex answers/findings may be derived from this process, these methods follow a specific set of hand-crafted instructions and the complexity and accuracy of the results are fundamentally limited. &#x20;

In classical terms, a data scientist’s role is focused on analytics, forecasting, visualization, and reporting with the goal of informing business decisions.  Since data science evolved as an extension of big data analytics, traditional tools included SAS, SQL, R, Scala, etc.&#x20;

Today, however, the role of the data scientist has evolved to encompass both ML and DL (which are quite different in terms of the expertise required and daily activity).  Companies still require basic analysis, dashboards, reporting, and queries -- all of which are still developed by data scientists. The end result is that the role can and does mean different things at different companies (or even different things at the same company).

### Machine Learning

Machine learning algorithms parse data, learn from it without human guidance, and then apply that learning to make informed decisions.  Machine learning performs well on small datasets and does not require high-end processing on GPUs since execution time is minimal.&#x20;

Machine learning requires careful understanding of input features. Feature engineering as a whole is a taxing, menial, and error-prone process with a lot of human involvement.  One benefit of certain ML algorithms is that their output is interpretable (e.g. logistic regression, decision tree) but this does not apply to all algorithms (e.g. SVM, XGBoost are almost impossible to interpret). &#x20;

Popular ML algorithms include: Linear Regression, Logistic Regression, SVMs, Nearest Neighbor, Decision Trees, Random Forests, PCA, Naive Bayes Classifier, K-Means Clustering, and Gradient-boosting trees.

### Deep Learning

Deep learning is an artificial neural network-based approach loosely modeled on the human brain -- namely the biological neural networks found in the neocortex where thinking occurs. &#x20;

![](/files/-LvCRB25E7CBwcAbTRCp)

Deep learning is technically defined as a machine learning model with more than one hidden layer. Artificial neural networks (ANNs) require at least three layers: input (features), hidden, and output (prediction).  DL algorithms can find much more complex and nuanced patterns than ML algorithms and can operate on almost any type of data.

> The hierarchy of concepts allows the computer to learn complicated concepts by building them out of simpler ones.  If we draw a graph showing how these concepts are built on top of each other, the graph is deep and has many layers. For this reason, we call this approach to AI deep learning.

Deep learning models can find much higher-level or abstract representations of data than machine learning models. For example, if we want to determine whether the subject of an image is a dog or a cat, a DL algorithm accomplishes this by extracting the low-level features such as the edges contained in raw pixels, then composes those edges into shapes, then infers a slightly more abstract concept of a nose and eyes from those shapes, and then from there proceeds to recognize the highly abstract concept of a face.&#x20;

An often-cited benefit of deep learning models is their ability to perform automatic feature extraction from raw data.  A few downsides are the intensive training time, the need for lots of data, and the lack of interpretability.&#x20;

Ultimately, ML and DL models operate on the same principle: if you feed an algorithm enough data, the machine can analyze it and predict patterns.  There is one key difference that matters at scale: due to their somewhat simplistic architecture, the accuracy of ML algorithms will begin to plateau at a certain point regardless if more training data is available. Conversely, the more data you feed a DL model, the more accurately the machine will recognize patterns. &#x20;

As a result, a DL model has the potential to yield a model with a higher degree of accuracy. Larger networks (that take longer to train) can further improve accuracy. There are diminishing returns at a certain point but this is a key selling point -- especially for companies with lots and lots of data, which in today's world is more the standard than the exception. If you’re Walmart, a 1% improvement of model accuracy in a recommender system could lead to many millions of dollars of additional revenue.  <br>

![](https://lh6.googleusercontent.com/L4wC5XJ-nsLV3pXqNvKTPB8bXx4-NYeFBXuToFiaM-7scsmJrQ8We8RHEZGa_yy2XHVmhRKOSZwKjhzLPKyLXdxcKuGQkUh1tndvimGYfBofExdrzW60QTfyZUmpYwRTCOPsBLQN)

Without data, you can't have machine learning. The machine learning process relies on huge amounts of data for training.  This step of preparing data has led to the creation of a field called Data Engineering which is becoming a key, independent function of large organizations.


# Distributed Training (TensorFlow, MPI, & Horovod)

Distributed training enables training workloads to scale-up beyond the capacity of a single compute instance. Model training is performed across multiple instances, often called “workers,” and training time can decrease dramatically.  Distributed training therefore helps tighten the feedback loop between training and evaluation, enabling data scientists to iterate more quickly.

The two most common types of distributed training are MPI/[Horovod](https://eng.uber.com/horovod/), a multi-framework tool from Uber, and Distributed TensorFlow, a TensorFlow-specific tool from Google.

## Distributed Training + Gradient

Gradient provides first-class support for distributed training with both Distributed TensorFlow and MPI.  With Gradient, you can run large-scale distributed training with almost no changes to your code. Here's a snippet of code showing the parameters of a distributed training experiment:

```bash
gradient experiments run multinode \
  --name multiEx \
  --projectId <your-project-id> \
  --experimentType GRPC \
  --workerContainer tensorflow/tensorflow:1.13.1-gpu-py3 \
  --workerMachineType K80 \
  --workerCommand "python mnist.py" \
  --workerCount 2 \
  --parameterServerContainer tensorflow/tensorflow:1.13.1-gpu-py3 \
  --parameterServerMachineType K80 \
  --parameterServerCommand "python mnist.py" \
  --parameterServerCount 1 \
  --workspaceUrl https://github.com/Paperspace/mnist-sample.git \
  --modelType Tensorflow
```

Here's a GitHub [repo](https://github.com/Paperspace/mnist-sample) with a sample project.

### Related Material

{% embed url="<https://docs.paperspace.com/gradient/experiments/run-experiments-cli#creating-a-multinode-experiment-using-the-cli>" %}


# Generative Adversarial Network (GAN)

Generative Adversarial Networks (GANs) were introduced in 2014 by Ian Goodfellow and are a fast-growing area in deep neural networks that can be used to generate realistic images, speech, prose, and more. &#x20;

Presented here is an image of a GAN-generated person who does not otherwise exist:

![A fake image of a person generated by https://thispersondoesnotexist.com/](/files/-LvHkYYHLpCClkz-qjqq)

> *“\[GANs are] the most interesting idea in the last 10 years in Machine Learning*” -- Yann LeCun

### Architecture

GANs are composed of two networks:

* **Generator:** creates new synthetic data (e.g. an image) that tricks the discriminator into believing the fake data is authentic
* **Discriminator:** evaluates samples passed from the generator and attempts to discern if the data (e.g. image) belongs to the training dataset, meaning it's authentic, or if it was generated, meaning it's fake

#### Steps in a GAN &#x20;

![Source: becominghuman.ai](/files/-LvHl81wIkgffbYlOoli)

1. The generator creates a fake sample
2. A generate (fake) sample is fed into the discriminator alongside a real sample taken from the training dataset
3. The discriminator returns a prediction with a probability from 0 - 1 with 0 being definitely fake and 1 being definitely authentic


# Epochs, Batch Size, & Iterations

In most cases, it is not possible to feed all the training data into an algorithm in one pass. This is due to the size of the dataset and memory limitations of the compute instance used for training. There is some terminology required to better understand how data is best broken into smaller pieces. &#x20;

An **epoch** elapses when an entire dataset is passed forward and backward through the neural network exactly one time.  If the entire dataset cannot be passed into the algorithm at once, it must be divided into **mini-batches**.  **Batch size** is the total number of training samples present in a single min-batch.  An **iteration** is a single gradient update (update of the model's weights) during training.  The number of iterations is equivalent to the number of batches needed to complete one epoch. &#x20;

So if a dataset includes 1,000 images split into mini-batches of 100 images, it will take 10 iterations to complete a single epoch.

### What is the right number of epochs? &#x20;

During each pass through the network, the weights are updated and the curve goes from [underfitting](/wiki/overfitting-vs-underfitting), to optimal, to [overfitting](/wiki/overfitting-vs-underfitting).  There is no magic rule for choosing the number of epochs — this is a [hyperparameter](/wiki/hyperparameter-optimization) that must be determined before training begins.

### What is the right batch size?

Like the number of epochs, batch size is a [hyperparameter](/wiki/hyperparameter-optimization) with no magic rule of thumb.  Choosing a batch size that is too small will introduce a high degree of variance (noisiness) within each batch as it is unlikely that a small sample is a good representation of the entire dataset.  Conversely, if a batch size is too large, it may not fit in memory of the compute instance used for training and it will have the tendency to [overfit](/wiki/overfitting-vs-underfitting) the data.  It's important to note that batch size is influenced by other hyperparameters such as learning rate so the *combination* of these hyperparameters is as important as batch size itself.

A common heuristic for batch size is to use the square root of the size of the dataset. However this is a hotly debated topic.


# ETL

![](/files/-LvJV37-QZqgqfnReYtP)

ETL is an acronym for Extract, Transform, Load.  It refers to taking data from one or multiple sources such as a database, transforming it in some way as needed, and loading it into a data warehouse.


# Features, Feature Engineering, & Feature Stores

### Machine Learning Features and Feature Engineering

Features are individual independent variables that act as inputs in a machine learning system.  Features are properties of a problem for which we would like to predict results. In simplistic terms, one column of a data set can be considered to be one feature.  In a more real-world scenario, you would obtain training features from existing features using a method known as “feature engineering.”

### Feature Store

Model-driven organizations are beginning to store features centrally in what has recently been termed a feature store.  A feature store is a data management layer (the output of a data lake) that allows data scientists and data engineers to share and discover features.&#x20;

Feature stores enable highly curated and consistent training datasets for machine learning. This layer aids in implementing full traceability along with compliance and scalability from data source to final outcome. The term was originally coined by Uber with the introduction of its Michelangelo machine learning platform. &#x20;


# Gradient Boosting

![Source: Hands-On Machine Learning with R](/files/-Lw70EB_T-Y3OCO-L_4o)

Gradient boosting (derived from the term *gradient boosting machines*) is a popular supervised machine learning technique for regression and classification problems that aggregates an ensemble of weak individual models to obtain a more accurate final model. &#x20;

Gradient boosting is a unique ensemble method since it involves identifying the shortcomings of weak models and incrementally or sequentially building a final ensemble model using a [loss function](/wiki/accuracy-and-loss#loss) that is optimized with [gradient descent](/wiki/gradient-descent).  Decision trees are typically the weak learners in gradient boosting and consequently, the technique is sometimes referred to as *gradient tree boosting*. &#x20;

![](/files/-Lw70ZzNl5AgerhBsp-v)

[XGBoost](/wiki/comparison-of-ai-frameworks#ml-frameworks) is a very popular gradient boosting framework that is fast, uses some clever tricks to obtain more accurate results, and is easy to parallelize. &#x20;


# Gradient Descent

![Source: O'Reilly Media](/files/-LvHmoeDavPzU-wiLw_a)

Gradient descent is an iterative optimization algorithm used in machine learning to minimize a [loss function](/wiki/accuracy-and-loss#loss).

The loss function describes how well the model will perform given the current set of parameters (weights and biases) and gradient descent is used to find the *best* set of parameters. This is achieved by taking the partial derivative at a given point and then iteratively traversing the search space in the negative direction of the function gradient. &#x20;

As the loss function improves, the parameters of a model (weights) are updated until it reaches the optimal point which is the **minima** of the loss function (the weights are updated in proportion to the derivative of the error). The two key aspects of Gradient descent are a) the direction to move and b) the size of the step (learning rate, discussed below).

![Gradient Descent in action](/files/-Lw6lSr3sxuY0gzJBEB9)

Gradient descent is used when the model parameters cannot be calculated using straightforward math (e.g., linear algebra) and must be searched for using an optimization algorithm.

There are several variants of gradient descent including **batch**, **stochastic**, and **mini-batch**. &#x20;

There are also several optimization algorithms including momentum, adagrad, nesterov accelerated gradient, RMSprop, adam, etc. Here is a [blog post](https://blog.paperspace.com/intro-to-optimization-momentum-rmsprop-adam/) that covers the differences between these algorithms.&#x20;

Gradient descent has a parameter called **learning rate** which represents the size of the steps taken as that network navigates the curve in search of the valley. If the learning rate is too high, the network may overshoot the minimum. If it's too low, the training will take too long and may never reach the minimum, or else get stuck in local minima.&#x20;

![Source: Rohith Gandhi / Towards Data Science](/files/-Lw6lH-WAYaxFcXq03Fq)

Check out the in-depth explanation of Gradient Descent in this [blog post](https://blog.paperspace.com/intro-to-optimization-in-deep-learning-gradient-descent/).


# Hyperparameter Optimization

### Introduction

Hyperparameter optimization (sometimes called hyperparameter search, sweep, or tuning) is a technique to fine-tune a model to improve its final accuracy.&#x20;

Common hyperparameters include the number of hidden layers, learning rate, [activation function](/wiki/activation-function), and number of [epochs](/wiki/epoch). There are various methods for searching the various permutations for the best possible outcome. Examples include grid search, random search, and Bayesian methods.

### What is a Hyperparameter?

A model hyperparameter is a configuration that is external to the model whose value cannot be estimated from data. Since it is not possible to know the best value for a model hyperparameter on a given problem, the hyperparameter optimization process needs to iterate through the various possible permutations. We may use rules of thumb, copy values used on other problems, or search for the best value by trial and error.&#x20;

## Hyperparameter Tuning with [Hyperopt](http://hyperopt.github.io/hyperopt/) <a href="#how-it-works" id="how-it-works"></a>

Hyperopt is a method for searching through a hyperparameter space. For example, it can use the Tree-structured Parzen Estimator (TPE) algorithm, which intelligently explores the search space while narrowing down to the best estimated parameters.

It is thus a good method for meta-optimizing a neural network. Whereas a neural network is an optimization problem that is tuned using gradient descent methods, hyperparameters cannot be tuned using gradient descent methods.&#x20;

That's where Hyperopt shines -- it's useful not only for tuning hyperparameters like learning rate, but also for tuning more sophisticated parameters in a flexible way. Hyperopt can change the number of layers of different types, the number of neurons in one layer or another, or even the type of layer to use at a certain place in the network given an array of choices -- each of which may have nested, tunable hyperparameters.

It is more efficient to randomly search through values and intelligently narrow the search space, rather than looping on fixed sets of hyperparameter values. This kind of Oriented Random Search is Hyperopt's strength, as opposed to a simpler Grid Search where hyperparameters are pre-established with fixed-step increases. Random Search for Hyperparameter Optimization has proven to be such an effective search technique that it's no surprise that the paper detailing this technique is among the most cited of all deep learning papers.&#x20;

If you want to learn more about Hyperopt, you'll probably want to watch the video below, made by the creator of Hyperopt:

{% embed url="<https://youtu.be/Mp1xnPfE4PY>" %}

## Hyperparameter Optimization + Gradient

Gradient offers powerful hyperparameter tuning out of the box, something very difficult to implement on your own. At a bare minimum, you need a mechanism to orchestrate serial/parallel training runs, a central data repository to sync results, and have some way of measuring and exploring the output. Gradient uses TensorBoard for model comparison and Hyperopt on the backend.


# Interpretability

![Source: Interpretable Machine Learning by Christoph Molnar](/files/-LvO4gn82n6KzUH8b4Dm)

Interpretability, often used interchangeably with *explainability*, is the degree to which a model's predictions can be explained in straightforward human terms.&#x20;

Deep neural networks are typically "opaque" due to their inherent complexity and can be difficult to decipher. By contrast, many classical machine learning algorithms are interpretable (e.g. linear regression, logistic regression, decision trees) though this is not always the case — SVM and XGBoost are notably difficult to interpret.

### The Importance of **Model Interpretability**

The importance of interpretability is relative.  For Netflix, if a prediction goes awry and a poor recommendation is made, aside from a monetary loss, the consequence is minimal.  In this case, the "risk" incurred by deploying predictive models is easily outweighed by the benefit.  But what about when machine learning is used to diagnose patients or determine credit worthiness?  In these cases, explainability is not only important, it may be a regulatory concern -- especially in heavily regulated industries such as banking, medicine, and insurance.

There are several open source projects focused on this topic such as **DeepLIFT** and **LIME**.


# Jupyter Notebooks

![](/files/-LvHdWVlYJo3mLe1f-8y)

Jupyter Notebooks are popular a development and training environment which have become the de-facto integrated development environment (IDE) for data science and machine learning.

Jupyter Notebooks are wildly popular but it's worth noting there are some drawbacks compared to working in a traditional IDE:

* Versioning notebooks is challenging.  The code itself lives in the Notebook, not a source code management (SCM) system like Git/GitHub.  This means you don’t get the benefits of merging, branching, and diffing code.
* Distributed training is not possible without a custom setup. &#x20;
* Live collaboration is non-existent. Jupyter is not designed to have multiple users work in the same Notebook or on the same code concurrently.  Notebooks may be forked but there is no off-the-shelf way to merge forks down the road.

As a result, some view Jupyter Notebooks solely as a tool for prototyping, analysis, and exploration.

There are, however a few examples of notebooks used in large-scale production pipelines such as those at [Netflix](https://medium.com/netflix-techblog/notebook-innovation-591ee3221233). &#x20;

## Jupyter Notebooks + Gradient

Notebooks are a core component of the Gradient platform.  Gradient offers a one-click Jupyter Notebook environment that is fully compatible with any existing Notebook and runs on a wide range of instances without any infrastructure management. &#x20;

There is a [free GPU and CPU instance available for Jupyter Notebooks](https://gradient.paperspace.com/free-gpu) which makes them very popular in the research community.  Learn more [here](https://gradient.paperspace.com/free-gpu). &#x20;

Notebooks can easily be shared publicly to collaborate on ML projects like GitHub repositories.  The [ML Showcase](https://ml-showcase.paperspace.com/) is a curated list of Jupyter Notebook-based projects that can be easily forked and edited. &#x20;

Gradient supports both Jupyter Lab (the newest version) and Jupyter Notebooks (the older version).


# Kubernetes

![](/files/-LvOF_13FB4XUd5RQW_L)

### Introduction&#x20;

Kubernetes (sometimes abbreviated as K8s) is an open source general-purpose container orchestration system initially developed by Google for running and managing [containerized workloads and services](/wiki/containers).  Historically, this meant deploying and scaling web applications but recently, the ML community has co-opted the technology to serve as the underlying orchestration layer for training and deploying ML models. &#x20;

Kubernetes has recently exploded in popularity and even though it is a very new and relatively immature project, thousands of organizations have invested in the technology to manage their public cloud or on-premise deployments.  Companies either deploy their own Kubernetes cluster or used managed cloud services such as EKS on AWS.

### Relationship to Machine Learning

Kubernetes provides the raw ingredients of an ML platform but Kubernetes itself is not suitable for ML practitioners.  It’s endlessly complicated and designed to be deployed and managed by DevOps teams.  Gradient is an “ML layer” that runs on top of Kubernetes and targets Data Scientists. &#x20;See below for more information.

### Benefits of Kubernetes

Kubernetes can run on any infrastructure which facilitates multi-cloud adoption and applications portability. &#x20;

Kubernetes has gained widespread adoption and is supported by a vast community so it gets more powerful every day. There is also a growing ecosystem of tools that are integrating with or building on top of Kubernetes.

## Kubernetes + Gradient

Gradient is built on top of Kubernetes. This provides multi-cloud capability, interoperability with Kubernetes plugins, and robust scheduling and resource management. &#x20;


# Linear Regression

![Source: Wikipedia ’Linear Regression’](/files/-Lw6knp2_7o5GuRQ3uYi)

Linear regression is an algorithm (belonging to both statistics and machine learning) that models the relationship between two or more variables by fitting a linear equation to a dataset.  Independent variables are the features (input data) and dependent variables are the target (what you are trying to predict). &#x20;

The technique is very simple and can be represented by this familiar equation:

![](/files/-Lw6reDg0_e8LuhuCJSF)

However, this is typically written slightly differently in machine learning:

![](/files/-Lw6utnYPHwHu1RxZtdz)

Or for a more advanced model with multiple features:

![](/files/-Lw6v80B-XE72FhKq2YQ)

Where:

* *y* is the predicted label
* *b* is the bias (the intercept)
* *w1* is the coefficient or weight of the first feature (weight = *m* or slope)
* *x1* is a feature (an input)<br>

Like [logistic regression](/wiki/logistic-regression), [gradient descent](/wiki/gradient-descent) is typically used to optimize the values of the coefficients (each input value or column) by iteratively minimizing the loss of the model during training. &#x20;

**Mean squared error** and **mean absolute error** are common [loss functions](/wiki/accuracy-and-loss#loss) for linear regression.

**Regularization** is a technique used to prevent [overfitting ](/wiki/overfitting-vs-underfitting)by penalizing signals that provide too much explanatory power to a single feature. &#x20;

### Linear vs Logistic Regression

**Linear regression** predictions are continuous (e.g. test scores from 0-100).

**Logistic regression** predictions classify items where only specific values or classes are allowed (e.g. binary classification or multiclass classification). The model provides a probability score (confidence) with each prediction.


# Logistic Regression

![Source: Technology of Computing](/files/-LwAVc1EdfmPMge5dlYC)

Logistic regression is a machine learning algorithm used for classification problems.  The term logistic is derived from the cost function (logistic function) which is a type of **sigmoid function** known for its characteristic S-shaped curve.  A logistic regression model predicts probability values which are mapped to two (binary classification) or more (multiclass classification) classes.

![Source: Analytics India Magazine](/files/-LwAYhg8-OqxqG7aWKhN)

![Formula of a sigmoid function](/files/-LwAgUAGfE21Zw1J-gnb)

Where:

* 1 = the curve's maximum value
* *S(z)*  = output between 0 and 1 (probability estimate)
* *z* = the input
* *e* = base of natural log (also known as Euler's number)

In multiclass classification with logistic regression, a **softmax function** is used instead of the sigmoid function. &#x20;

Like [linear regression](/wiki/linear-regression), [gradient descent](/wiki/gradient-descent) is typically used to optimize the values of the coefficients (each input value or column) by iteratively minimizing the loss of the model during training. &#x20;

The **decision boundary** is the acceptable threshold at which a probability can be mapped to a discrete class e.g. pass/fail or vegan/vegetarian/omnivore. &#x20;

The cost function in logistic regression is more complex than linear regression. For example, mean squared error would yield a non-convex function with many local minimums, making it difficult to optimize with gradient descent. **Cross entropy**, also called **log loss** is the cost function used with logistic regression.

**Regularization** is a technique used to prevent [overfitting ](/wiki/overfitting-vs-underfitting)by penalizing signals that provide too much explanatory power to a single feature.  Regularization is extremely important in logistic regression.

[Accuracy](/wiki/accuracy-and-loss#accuracy), a [model evaluation metric](/wiki/metrics-in-machine-learning), is used to measure how accurate a model's predictions are -- this is expressed as the number of true classifications divided by the total.

### Linear vs Logistic Regression

**Linear regression** predictions are continuous (e.g. test scores from 0-100).

**Logistic regression** predictions classify items where only specific values or classes are allowed (e.g. binary classification or multiclass classification). The model provides a probability score (confidence) with each prediction.


# Long Short-Term Memory (LSTM)

{% hint style="success" %}
We recommend reading the [RNN article](/wiki/recurrent-neural-network-rnn) before diving in to LSTMs.
{% endhint %}

Long Short Term Memory networks (LSTMs) are a special kind of recurrent neural network ([RNN](/wiki/recurrent-neural-network-rnn)) capable of learning long-term dependencies in sequence data.  LSTMs were created to overcome the inability to retain information for long periods of time, which is an inherent limitation in RNNs.

The following image illustrates the structure of a vanilla RNN:

![](/files/-LwEhQdx0Va-2e4jfI7q)

LSTMs have four activation functions which are used to save pertinent information to be used in later stages of training. &#x20;

![Source: Christopher Olah](/files/-LwEhdQALBJdxHUv2J3J)

The horizontal line running across the cells illustrates the **cell state**, a channel for information to flow across the entire chain.  The cell state can be updated if the information is deemed pertinent (regulated by gates in each cell).  With this novel refinement to RNNs, LSTMs were explicitly designed to capture, retain, and re-use key information over long sequences. &#x20;


# Machine Learning Operations (MLOps)

## What Is MLOps?

Machine Learning Operations (MLOps) is a set of practices that provide determinism, scalability, agility, and governance in the model development and deployment pipeline.

**Simplified model deployment -** Data scientists use a variety of languages, frameworks, tools, and IDEs. With MLOps, ML teams can develop models using the interface, framework, and language that makes the most sense for the task at hand.  For example, transitioning from a prototype model in a Jupyter Notebook to a large-scale hyperparameter sweep should be trivial.

**Accelerate model training -** The machine learning training process is computational complex and time intensive.  Data scientists need access to on-demand compute and storage resources so they can iterate faster in the training phase. With MLOps, training phase is infrastructure agnostic, scalable, and minimizes complexity for the data scientist.

**Purpose-built model monitoring -** Tools and techniques used to monitor traditional software are not suitable for machine learning. MLOps provides purpose-built monitoring systems designed for machine learning. The key [model-specific](/wiki/metrics-in-machine-learning) metrics must be tracked to gauge and compare performance of deployed models. Realtime alerting on important signals like model drift is also critical.

**Model life cycle management -** Models are not static assets.  They are constantly retrained on new data and improved over time.  Tooling these updates become a burden as teams scale up and begin to juggle multiple models and contributors.  MLOps provides a unified hub for tracking the lineage and performance as new models are developed and rolled-out to production.  &#x20;

**Model governance -** Data, models, and other resources need to be tightly controlled to prevent undesirable changes and to ensure regulatory compliance where applicable. MLOps provides centralized access control, traceability, and audit logs to minimize risk and ensure regulatory compliance.

### Multi-cloud

Enterprises are increasingly opting for a *multi-cloud* approach to leverage various resources across environments and decrease vendor lock-in. They require enhanced development capabilities with greater flexibility across multiple cloud and on-prem environments to suit their specific workflow needs.&#x20;

## Why Is MLOps Important?

Developing and deploying machine learning models turns out to be a slow process. The tools lack automation, collaboration is difficult, and workflows are difficult to scale.  Ultimately, the time it takes to move from concept to production and deliver business value is a major hurdle in the industry.  That’s why we need good MLOps that are designed to standardize and streamline the lifecycle of ML in production.

### An Analogy

DevOps as a practice ensures that the software development and IT operations lifecycle is efficient, well documented, scalable, and easy to troubleshoot. MLOps incorporates these practices to deliver machine learning applications and services at high velocity. This new paradigm is useful as a way for enterprises to overcome the many challenges of training and deploying models into production.

## MLOps + Gradient

Gradient from [Paperspace](https://machine-learning.paperspace.com/wiki/www.paperspace.com/gradient) offers agile ML tooling and methodology across multi-cloud, on-premise, and hybrid environments — without the need for DevOps or any manual configuration. &#x20;

Gradient abstracts infrastructure and provides robust reproducibility and determinism.  For the first time, data scientists can operate without a dependence on SREs or software teams to handle tasks like managing a Kubernetes cluster, ingesting data, and pipelining.  When ML teams can operate with full autonomy and own the entire stack, they are much more efficient and agile.


# Managing Machine Learning Models

## Managing Models with a Model Catalog

A *model catalog* (commonly referred to as a *model store*) is a collection of private models in development and models that are deployed to production.  A model catalog helps store, version, analyze, and deploy machine learning models.&#x20;

## Model Zoo

A model zoo is a collection of pre-trained models ready to be deployed.  Models can either be deployed directly or re-refitted to a new dataset with [transfer learning](/wiki/transfer-learning).&#x20;

## Managing Models + Gradient

Gradient provides both a model catalog and model zoo for working with private and public models.  Gradient brings a shared [model repository](https://docs.paperspace.com/gradient/models/about) to organizations of any scale which reduces tedious tasks and can accelerate adoption of machine learning throughout an entire organization.&#x20;


# ML Showcase

Discover and run the latest ML models

![Browse, search and filter projects in the ML Showcase](/files/-LvJ4gGeOonKDpLUIqqT)

The [ML Showcase](https://ml-showcase.paperspace.com/) is a curated collection of interactive machine learning projects that can be forked and edited.  The showcase, curated by [Paperspace](https://machine-learning.paperspace.com/wiki/www.paperspace.com), offers a number of the latest machine learning and deep learning templates.

{% embed url="<https://ml-showcase.paperspace.com/>" %}

Gradient offers a [free GPU and CPU instance for machine learning](https://gradient.paperspace.com/free-gpu) prototyping.  Learn more [here](https://gradient.paperspace.com/free-gpu).


# Metrics in Machine Learning

In the context of machine learning, a metric is any number that we care about.  An *objective* is a specific type of metric that a machine learning system attempts  to optimize.

## Technical Metrics

[Accuracy](/wiki/accuracy-and-loss) is the most common (and easy to understand) metric but tracking only accuracy will paint an incomplete picture of how your model is performing.  There are several other well-established metrics that provide deeper insight into model performance. &#x20;

Metrics are often specific to the type of machine learning problem or model. Important and widely adopted metrics include: Accuracy, [Loss](/wiki/accuracy-and-loss#loss), [Confusion Matrix](/wiki/confusion-matrix), [AUC (Area Under ROC curve)](/wiki/auc-area-under-the-roc-curve), Mean Absolute Error (MAE), Root Mean Square Error (RMSE), and R Square.

## Correlating to Business Metrics

Machine learning metrics are often directly correlated to business metric. One example would be assigning a dollar value to *false positives* in a classification model.  Here's a great [example](https://medium.com/airbnb-engineering/fighting-financial-fraud-with-targeted-friction-82d950d8900e) of how AirBnB measures the performance of their fraud prediction algorithm in dollars.


# Machine Learning Models Explained

![Source: becominghuman.ai](/files/-LvJChz-OpOFlobU-jSo)

## What Is a model?

The output from model training may be used for inference, which means making predictions on new data. A model is a distilled representation of what a machine learning system has learned.  Machine learning models are akin to mathematical functions -- they take a request in the form of input data, make a prediction on that input data, and then serve a response.

In [**supervised**](/wiki/supervised-unsupervised-and-reinforcement-learning#supervised) and [**unsupervised**](/wiki/supervised-unsupervised-and-reinforcement-learning#unsupervised) machine learning, the model describes the signal in the noise or the pattern detected from the training data.&#x20;

In [**reinforcement learning**](/wiki/supervised-unsupervised-and-reinforcement-learning#reinforcement-learning), the model describes the best possible course of action given a specific situation.

The final set of trainable parameters (the information the model contains) depends on the specific type of model -- in deep neural networks, a model is the final state of the trained [weights](/wiki/weights-and-biases) of the network, in regression it contains coefficients, and in decision trees it contains the split locations.

## Algorithms

#### Neural Networks

There are many different types of models such as [GANs](/wiki/generative-adversarial-network-gan), [LSTMs](/wiki/long-short-term-memory-lstm) & [RNNs](/wiki/recurrent-neural-network-rnn), [CNNs](/wiki/convolutional-neural-network-cnn), Autoencoders, and [Deep Reinforcement Learning](/wiki/supervised-unsupervised-and-reinforcement-learning#reinforcement-learning) models. Deep neural networks are used for object detection, speech recognition and synthesis, image processing, style transfer, and machine translation, and can replace most classical machine learning algorithms (see below). This modern method can learn extremely complex patterns and is especially successful on unstructured datasets such as images, video, and audio. &#x20;

#### **Ensemble Methods**

Ensemble techniques like [Random Forests](/wiki/random-forest) and [Gradient Boosting](/wiki/gradient-boosting) can achieve superior performance over classical machine learning techniques by aggregating weaker models and learning non-linear relationships. &#x20;

#### Classical Machine Learning&#x20;

Popular ML algorithms include: linear regression, logistic regression, SVMs, nearest neighbor, decision trees, PCA, naive Bayes classifier, and k-means clustering. Classical machine learning algorithms are used for a wide range of applications.&#x20;

## Types of Supervised Learning Models

### Classification <a href="#binary-classification-model" id="binary-classification-model"></a>

Deep neural networks, classification trees (ensembles), and logistic regression (classical machine learning) are all used to perform regression tasks.

**Popular use cases:**

&#x20;Spam filtering, language detection, a search of similar documents, sentiment analysis, recognition of handwritten characters, and fraud detection.

**Binary Classification Goal:** Predict a binary outcome.

#### Examples <a href="#examples-of-binary-classification-problems" id="examples-of-binary-classification-problems"></a>

* "Is this email spam or not spam?"
* "Is this user fraudulent or not?"
* "Is this picture a cat or not?"

**Multi-class Classification Goal:** Predict one out of two or more discrete outcomes.

#### Examples <a href="#examples-of-multiclass-problems" id="examples-of-multiclass-problems"></a>

* "Which genre does this user prefer?"
* "Is this mail is spam or important or a promotion?"
* "Is this picture a cat or a dog or a fox?"

### Regression <a href="#regression-model" id="regression-model"></a>

Deep neural networks, regression trees (ensembles), and linear regression (classical machine learning) are all used to perform regression tasks.&#x20;

**Popular use cases:**&#x20;Forecasting stock prices, predicting sales volume, etc.

**Goal:** Predict a numeric value.&#x20;

#### Examples <a href="#examples-of-regression-problems" id="examples-of-regression-problems"></a>

* "What will the temperature be in NYC tomorrow?"
* "What is the price of house in this specific neighborhood?"

## Types of Unsupervised Learning models

### Neural Networks

Deep neural network architectures such as autoencoders and GANs can be applied to a wide variety of unsupervised learning problems.&#x20;

### Clustering (Classical ML) <a href="#regression-model" id="regression-model"></a>

**Popular use cases:**For customer segmentation, labeling data, detecting anomalous behavior, etc.

**Popular algorithms:** K-means, Mean-Shift, DBSCAN

**Goal:** Group similar things together.&#x20;

#### Examples <a href="#examples-of-regression-problems" id="examples-of-regression-problems"></a>

* "Cluster different news articles into different types of news"

### Association Rule (Classical ML)

**Popular use cases:**&#x20;Helping stores cross-sell products, uncovering how items are related or complementary, and understanding which symptoms are likely to co-occur in a patient (comorbidity).

**Popular algorithms:** Apriori, Euclat, FP-growth

**Goal:** Infer patterns (associations) in data.&#x20;

#### Examples <a href="#examples-of-regression-problems" id="examples-of-regression-problems"></a>

* "If you bought a phone, you are likely to buy a phone case."

### Dimensionality Reduction (Classical ML)&#x20;

**Popular use-cases:** Recommender systems, topic modeling, modeling semantics, document search, face recognition, and anomaly detection.&#x20;

**Popular algorithms:** Principal Component Analysis (PCA), Singular Value Decomposition (SVD), Latent Dirichlet Allocation (LDA), Latent Semantic Analysis (LSA, pLSA, GLSA), and t-SNE.&#x20;

**Goal:** To generalize data and distill the relevant information.&#x20;

#### Examples <a href="#examples-of-regression-problems" id="examples-of-regression-problems"></a>

* "Intelligently group and combine similar features into higher-level abstractions."

## Types of Reinforcement Learning Models

**Popular use-cases:** Robotic motion, recommender systems, autonomous transport, text mining, trade execution in finance, and optimization for treatment policies in healthcare.

**Popular algorithms:** Q-Learning, SARSA, DQN, A3C

**Goal:** Perform complex tasks without training data.

#### Examples <a href="#examples-of-regression-problems" id="examples-of-regression-problems"></a>

* "Robotic motion control learned by trial and error."

{% hint style="info" %}
**Imitation Learning** is an exciting area in Reinforcement Learning, designed to overcome some of the challenges or shortcomings inherent in Reinforcement Learning techniques. These techniques are often used together.&#x20;
{% endhint %}


# Model Deployment (Inference)

Once a model is trained, it is typically deployed as an online API endpoint as part of a web service or to make batch predictions.  To deal with latency-sensitive applications or devices that may experience intermittent or no connectivity, models can also be deployed to edge devices to be embedded as a component within an iPhone app, deployed within a driverless car, robot, IoT device, or wherever the model is needed.

Models are deployed to customer facing applications in the case of an ecommerce site that makes realtime product recommendations, or to internal services in the case of a company that performs realtime financial forecasting, sentiment analysis, or risk management.

Deployed models should be monitored in terms of infrastructure health (e.g. requests, response time, and load), [model drift and decay](/wiki/model-drift-and-decay) (where the live model performance degrades on new, unseen data or the underlying assumptions about the data change), and other performance criteria.  &#x20;

In the case of a web service, a model may need to be autoscaled based on requests and/or load. &#x20;

**Frameworks and runtimes**: In a basic scenario, a model can be deployed as a traditional web server with something like Flask.  In a more sophisticated environment, inferencing will happen in an optimized ML-specific model-serving framework such as TensorFlow Serving, Clipper, TensorRT, or Seldon.

**Server:** Most model-serving frameworks are based on [REST](/wiki/rest-and-grpc) though TensorFlow Serving and TensorRT offer [gRPC](/wiki/rest-and-grpc) endpoints which are fussier but more performant. &#x20;

**Canary rollouts, blue-green deployments, multi-armed bandit, & A/B testing**: These methods are not specific to machine learning, but they deal with how models are rolled out to production to catch errors, perform tests, and find the best performing model.

There is no de-facto standard or even established best practices for deploying, managing, and monitoring models in any of these scenarios.

## Inference + Gradient

Gradient from [Paperspace](https://machine-learning.paperspace.com/wiki/www.paperspace.com/gradient) streamlines model deployment:

* Any framework/runtime is supported as well as both gRPC and HTTP inference endpoints
* Models can be deployed to a wide variety of CPU and GPU instance types
* Single or multiple instances are supported with out-of-the-box load balancing
* Both basic auth (username & password) and JWT auth are supported
* Autoscaling and monitoring of endpoints are available

### Related Material

{% embed url="<https://docs.paperspace.com/gradient/deployments/about>" %}


# Model Drift & Decay

Model drift and decay are concepts that describe the process during which the performance of a model deployed to production degrades on new, unseen data or the underlying assumptions about the data change.

These are important [metrics](/wiki/metrics-in-machine-learning) to track once models are deployed to production.  Models must be regularly re-trained on new data.  This is referred to as *refitting* the model. This can be done either on a periodic basis, or, in an ideal scenario, retraining can be triggered when the performance of the model degrades below a certain pre-defined threshold.


# Model Training

Training is where a machine learning system finds the ideal parameters of a model on its own.  In the most common scenario ([supervised learning](/wiki/supervised-unsupervised-and-reinforcement-learning#supervised) with labeled training data), the model learns these parameters directly from the training data. &#x20;

{% hint style="info" %}
While training data is used to find optimal parameters of the model, the object of machine learning is to find the best set of parameters that produces accurate outcomes on new, unseen data, not training data.
{% endhint %}

The ML community has converged on terms like “jobs” and “experiments” to describe the iterative model-training process where each job or experiment represents a new iteration. This is similar to a code commit in software development. Generally speaking, this process involves executing code written locally in an IDE or [Jupyter Notebook](/wiki/jupyter-notebooks) remotely on a GPU or CPU instance (or cluster of instances in the case of distributed training).

## Training + Gradient

![](/files/-Lvujqu4POattHYjRSi0)

Gradient from [Paperspace](https://machine-learning.paperspace.com/wiki/www.paperspace.com/gradient) provides an interface to track model training and deployment.

[Experiments](https://gradient.paperspace.com/experiments) structure your machine learning projects with automatic versioning, tagging, and life-cycle management. Experiments include hyperparameter search, distributed training, a Git integration, and infrastructure automation (job scheduling, unified logs, cluster management, and more).&#x20;

Gradient also includes a Jupyter Notebook integration where a GPU-enabled Jupyter Notebook can be launched from your browser in seconds. [Gradient Notebooks](https://gradient.paperspace.com/notebooks) are fully-managed and do not require any setup or management of servers or dependencies. &#x20;

Choose from a wide variety of templates that include all the frameworks, libraries, and drivers you need for machine learning. Customer dependencies can be installed in any notebook and dependencies are persistent across sessions. &#x20;


# MNIST

Download and learn about the classic MNIST dataset

![](/files/-Lvg7Fj0FIdVfziJHILk)

Short for “Modified National Institute of Standards and Technology," MNIST is the canonical database of labeled images of handwritten digits from 0 through 9.  MNIST is often used in sample projects as a sort of "hello world" for machine learning.  It is also used frequently as a performance benchmark. &#x20;

The dataset has a training set of 60,000 examples, and a test set of 10,000 examples which are available from this [page](http://yann.lecun.com/exdb/mnist/).

## MNIST + Gradient

MNIST is available in the [Public Datasets Repository](https://docs.paperspace.com/gradient/data/public-datasets-repository) which is provided for free in Gradient.  These datasets are automatically mounted to every Notebook and Experiment.


# Overfitting vs Underfitting

![Source: Sagar Sharma / Towards Data Science](/files/-LvNoby-llz4QzAK15nL)

These terms describe two opposing extremes which both result in poor performance. &#x20;

**Overfitting** refers to a model that was trained too much on the particulars of the training data (when the model learns the noise in the dataset).  A model that is overfit will not perform well on new, unseen data.  Overfitting is arguably the most common problem in applied machine learning and is especially troublesome because a model that appears to be highly accurate will actually perform poorly in the wild.

**Underfitting** typically refers to a model that has not been trained sufficiently. This could be due to insufficient training time or a model that was simply not trained properly.  A model that is underfit will perform poorly on the training data as well as new, unseen data alike.

Both underfitting and overfitting will yield poor performance -- the sweet spot is in between these two extremes.  As the number of training iterations increases, the parameters of the model are updated and the curve goes from underfitting to optimal to overfitting. &#x20;

The optimal state is is referred to as **generalization**. This is where the model performs well on both training data and new data not seen during the training process.


# Random Forest

![Source: TIBCO](/files/-LwB8NgwITY4LMRiQ0Sp)

Random forests are an ensemble learning technique that combines multiple **decision trees** into a forest or final model of decision trees that ultimately produces more accurate and stable predictions. &#x20;

Random forests operate on the principle that a large number of trees operating as a committee (forming a strong learner) will outperform a single constituent tree (a weak learner).  This is akin to the requirement in statistics to have a sample size large enough to be statistically relevant. Some individual trees may be wrong but as long as the individual trees are not making completely random predictions, their aggregate will form an approximation of the underlying data.

![Source: CitizenNet](/files/-LwBDkxf97yNSDh99KuN)

**Bagging** is the algorithmic technique used in the random forest scenario. This, we may recall, differs from the [Gradient Boosting](/wiki/gradient-boosting) technique. Bagging trains individual decision trees on random samples of subsets of the dataset to reduce correlation.  A benefit of bagging over boosting is that bagging can be performed in parallel while boosting is a sequential operation.

Individual decision trees are prone to [overfitting](/wiki/overfitting-vs-underfitting) and have a tendency to learn the noise in the dataset.  Random Forests take an average of multiple trees -- so as long as the individual decision trees are not correlated, this strategy reduces overfitting and sensitivity to noise in the dataset. &#x20;


# Recurrent Neural Network (RNN)

![Source: Missing Link](/files/-LwEZT8zd07mLDuaQZwy)

Recurrent Neural Networks (RNNs) are a type of artificial neural network that has a chain-like structure especially well-suited to operate on sequences and lists.  RNNs are applied to a wide variety of problems where text, audio, video, and time series data is present. This may include speech recognition, detection of stock trading patterns, analysis of DNA sequences, language modeling, translation, image captioning, and more.

### How RNNs Differ from Vanilla Feed-forward Networks

Regular feed-forward networks such as [CNNs](/wiki/convolutional-neural-network-cnn) only consider the current input. Consequently, they do not have any memory about what happened in the past.  Therefore, they have trouble predicting what comes next in a sequence. &#x20;

RNNs differ in that they retain information about the input previously received.  They are networks with feedback loops that allow information to persist -- a trait that is analogous to short-term memory.  This sequential memory is preserved in the recurrent network’s **hidden state** vector and represents the context based on the prior inputs and outputs.  Unlike a feed-forward network, the same input may produce different outputs depending on the preceding inputs. &#x20;

### Shortcomings of RNNs

RNNs are inherently deficient at retaining information over long periods of time due to the infamous vanishing gradient problem in back-propagation.  For example, a name of a character at the start of a paragraph of text may be forgotten towards the end.  [LSTMs](/wiki/long-short-term-memory-lstm) were invented to solve this problem -- they can discern key information, retain it over long periods of time, and then use this information when necessary much later on in the sequence. &#x20;

The concept is illustrated in the image below. The amount of color present in each step of the sequence reveals the pieces of information that persist over time.

![Source: Michael Nguyen / Learned Vector](/files/-LwEYrFhW40cJiMAf226)


# Reproducibility in Machine Learning

Machine learning is said to be experiencing a reproducibility crisis. What does this mean?

> *A 2016 “Nature”* [*survey*](https://www.nature.com/news/1-500-scientists-lift-the-lid-on-reproducibility-1.19970) *demonstrated that more than 70% of researchers have tried and failed to reproduce another scientist’s experiments, and more than half have failed to reproduce their own experiments*. -- Sam Charrington, TWiML

As heuristics are replaced by models, the focus of the machine learning community has shifted away from factors like [explainability](/wiki/interpretability) and reproducibility towards matters of raw performance as measured by [evaluation metrics](/wiki/metrics-in-machine-learning).  As a result, many machine learning models are either not reproducible or are difficult to reproduce.  This is largely the result of a lack of [best-practices](/wiki/machine-learning-operations-mlops) (what we called [**MLOps**](/wiki/machine-learning-operations-mlops)) in machine learning today.

### Determinism

Retraining an existing model with the same hyperparameters and dataset does not always reproduce the same result.  This seems counterintuitive -- why is this?  There are several factors that contribute to non-determinism:

* **Initialization of layer weights:** It is common practice to set initial weights to a non-zero value.  These need to be captured to reproduce the same results. &#x20;
* **Dataset shuffling:** Datasets are often randomly shuffled at initialization so this is a fairly obvious root cause of non-determinism.  However even if the model is set to use a fixed range of the dataset (e.g. the last 20%), the contents of this set will not be consistent across training runs. Shuffling within the training dataset affects the order of samples and therefore the way the model learns as it iterates over these samples.
* **Randomness in hidden layers:** Many neural network-based architectures include layers with deliberate randomness. Dropout is a common example used to prevent overfitting.
* **Updates to ML frameworks, libraries, & drivers:** Updates to ML libraries and even GPU drivers can lead to subtly different behavior across iterations.
* **Hardware used during the training process:** The specific combination of GPU and CPU can produce different results.  This is the result of several factors including the way GPUs handle floating-point calculations and CPUs handle multi-threading.

### Making Machine Learning Reproducible

At a high-level, the first step in making machine learning more reproducible involves capturing all of the core primitives (hyperparameters, code commit, and dataset) and metadata (outlined above) associated with the training process.

Beyond capturing the basic components in the machine learning system, the path towards reproducible ML can be thought of as a philosophical shift away from ad-hoc methodologies to a more deterministic way of working. &#x20;

By adopting mature practices found in software engineering and DevOps, machine learning can evolve to achieve improved resiliency and predictability.  **Versioning** and **continuous integration** are an integral part many software workflows, and transposing these concepts to machine learning will streamline many processes.

Finally, organization-wide visibility and collaboration are also essential.  Due to a lack of available tools, data scientists often work in siloed environments and don't have access to shared notebooks, code, and parameters. &#x20;

A unified hub for tracking all models in development, testing/QA, and production is a must-have for any ML team -- especially as the number of data scientists, models, and complexity of models increases.

## Reproducibility + Gradient

Gradient from [Paperspace](https://machine-learning.paperspace.com/wiki/www.paperspace.com/gradient) automatically tags each entity (e.g. training inputs, parameters of deployed models, etc.) with a unique identifier.  Versioning and continuous integration are first-class citizens in the unified [CI/CD for machine learning](/wiki/ci-cd-for-machine-learning).

![](/files/-Lvv5LGaRJ8K1RfxrREA)

[MLOps](/wiki/machine-learning-operations-mlops) is another modern approach to machine learning that is deeply embedded in the Gradient platform.


# REST and gRPC

Most model-serving frameworks are based on REST.  TensorFlow Serving and TensorRT offer gRPC endpoints which are fussier but more performant.

## Benefits of REST

* **Stateless -** No client context is stored on the server between requests
* **Self-contained -** All information that is needed to service a request is packaged with the request itself
* **Flexible -** REST is programming language agnostic, has universal browser and language support, and supports a large number of filetypes

## Benefits of gRPC

* **Bi-directional** **-** gRCP supports two-way communication
* **Simplicity -** No headers, methods, or body, and better status codes
* **Performant -** Binary data via protocol buffers for serializing structure data, performs better under high loads


# Serverless ML: FaaS and Lambda

Function-as-a-Service (FaaS) and Lambda functions are types of serverless systems.&#x20;

![An example of a common serverless website configuration. Source: NBS System](/files/-LwQZg_c0lrUCbVR-aET)

Going serverless for model serving or inference *sounds* attractive.  Theoretically, there would be less infrastructure to manage and less idle GPU/CPU cost.&#x20;

In practice, however, cold-start times and other unavoidable hurdles have slowed widespread adoption.


# Synthetic Data

[Data is the new oil](https://www.economist.com/leaders/2017/05/06/the-worlds-most-valuable-resource-is-no-longer-oil-but-data).  The aphorism is a bit cliche but it is true that the tech giants have benefited disproportionately from AI which is due in no small part to the amount of data they collect.

![Source: The Economist](/files/-LwQ_Nnp-Qmz70Q70KwG)

Companies that are not Google, Facebook, Amazon et al. often do not have enough data to train models accurately -- especially in the case of training deep neural networks that require more data than classical machine learning algorithms. &#x20;

Creation of fake data, called synthetic data, is one way of overcoming the lack of data.&#x20; This burgeoning technique can be used to generate all kinds of datasets including images, audio files, and more.  This is often proceeded by [transfer learning](/wiki/transfer-learning) during which models are deployed to similar problems where there may be substantial developmental overlap, thus reducing time and effort when compared to starting from scratch.


# Structured vs Unstructured Data

![Source: igneous.io](/files/-LwQbPMXwVHshv40D9bA)

### Structured

Structured data is organized and searchable and is the easiest to work with. Examples include names, dates, addresses, credit card numbers, stock information, etc.

### Unstructured&#x20;

Unstructured data is much more prevalent. Examples include text, video, audio, mobile activity, social media activity, satellite imagery, surveillance imagery, etc.


# Supervised, Unsupervised, & Reinforcement Learning

![Source: IBM](/files/-LwQcH6NWMz6kjAEqpge)

### Supervised Learning&#x20;

In supervised learning, the machine uses labeled training data. It is told the correct output and it compares its own output which informs the subsequent steps, adjusting itself along the way. &#x20;

This process is repeated until the model achieves a desired level of accuracy on the training data and can correctly predict the class label for new instances.

There are numerous supervised learning algorithms and each has benefits and drawbacks. Read more about [types of supervised learning](/wiki/machine-learning-models-explained#types-of-supervised-learning-models) models.

### Unsupervised&#x20;

In unsupervised learning, the data isn't labeled. The machine must figure out the correct answer without being told and must therefore discover unknown patterns in the data. Algorithms must therefore be formulated such that they can find suitable patterns and structures in the data on their own. &#x20;

Some popular examples of unsupervised learning include GANs and Autoencoders.

See types of [Unsupervised Learning](/wiki/machine-learning-models-explained#types-of-unsupervised-learning-models) models.

### Semi-Supervised

In Semi-Supervised Learning: Input data is a mixture of labeled and unlabeled examples.

### Reinforcement Learning

Reinforcement Learning allows the machine the most freedom. It uses trial and error to discover the actions that yield the greatest rewards. AlphaGo is a famous example of RL.&#x20;


# TensorBoard

![](/files/-LvIs_Lpza8ips01HNef)

TensorBoard is a powerful open source toolkit for tracking and visualizing [metrics](/wiki/metrics-in-machine-learning) within individual models or for comparing performance between multiple models.  Also included are some powerful debugging options that help you visually explore the model.  TensorBoard was initially built for TensorFlow but is now supported by other frameworks such as PyTorch. &#x20;

[TensorboardX](https://github.com/lanpa/tensorboardX) is a project that extends TensorBoard to other frameworks such as Chainer, MXnet, etc.

## TensorBoard + Gradient

TensorBoards are first-class citizens in Gradient. A single Experiment or multiple Experiments can easily be added to TensorBoard without any setup or management. &#x20;


# Tensor Processing Unit (TPU)

![An aisle of rack-based servers containing TPUs](/files/-LvItvW-NZvYZW5I4kca)

The Tensor Processing Unit (TPU) is a high-performance [ASIC chip](/wiki/ai-chips-for-training-and-inference) that is purpose-built to accelerate machine learning workloads.  Models that previously took weeks to train on general purpose chips like CPUs and GPUS can train in hours on TPUs.  The TPU was developed by Google and is only available in Google Cloud. &#x20;

There are a few drawbacks to be aware of:

* The topology is unlike other hardware platforms and is not trivial to work with for those not familiar with DevOps and the idiosyncrasies of the TPU itself
* The TPU only supports TensorFlow currently, although other frameworks may be supported in the future  &#x20;
* Certain TensorFlow operations (e.g. customer operations written in C++) are not supported
* TPUs are optimal for large models with very large batch sizes and workloads that are dominated by matrix-multiplication. Models dominated by algebra will not perform well.

Here's a full rundown of the architecture and a performance benchmark:

{% embed url="<https://blog.paperspace.com/the-tpu-is-weird-but-its-going-to-change-everything/>" %}

## TPU + Gradient

Gradient by [Paperspace](https://machine-learning.paperspace.com/wiki/www.paperspace.com/gradient) offers the TPU as an instance type, along with CPUs and GPUs.  Support for the TPU is an enterprise feature.  Contact [sales](https://info.paperspace.com/contact-sales) to learn more.

{% embed url="<https://info.paperspace.com/contact-sales>" %}


# Transfer Learning

## What is Transfer Learning?

Transfer learning is an approach used to transfer information from one machine learning task to another. Practically speaking, a pre-trained model that was trained for one task is re-purposed as the starting point for a new task.  As a result, great amounts of time and resources can be saved by transfer learning.

Creating complex models from scratch requires vast amounts of compute resources, data, and time.  Transfer learning accelerates the process by leveraging commonalities between tasks (such as detecting edges in images) and applying those learning to a new task.  Training time for a model can go from weeks to hours, making machine learning more commercially viable for many businesses.

![Source: Drivers of ML industrial success by Andrew Ng, 2016 NIPS](/files/-LvQyCF90QZxcaY5Jm0B)

Transfer learning is very popular in domains like computer vision and NLP where large amounts of data are needed to produce accurate models.&#x20;

### An Example

Let's say we have merely 1,000 images of an object we want to classify.  If we take a pre-trained CNN such as ResNet-50 which was trained on millions of images, we can re-train the model on our small dataset and build a state-of-the-art model with minimal effort.  In neural networks, this is achieved by removing the final layer in the existing model (called the "loss output" layer) and replacing it with a new layer for the intended prediction. &#x20;


# Weights and Biases

Weights and biases (commonly referred to as *w and b*) are the learnable parameters of a some machine learning models, including neural networks.

Neurons are the basic units of a neural network. In an ANN, each neuron in a layer is connected to some or all of the neurons in the next layer. When the inputs are transmitted between neurons, the weights are applied to the inputs along with the bias.

![A neuron](/files/-LvNczsh9MyG8YDoWJi-)

**Weights** control the signal (or the strength of the connection) between two neurons. In other words, a weight decides how much influence the input will have on the output.

**Biases**, which are constant, are an additional input into the next layer that will always have the value of 1. Bias units are not influenced by the previous layer (they do not have any incoming connections) but they do have outgoing connections with their own weights. The bias unit guarantees that even when all the inputs are zeros there will still be an activation in the neuron.

![Souce: Mate Labs](/files/-LvJSdcFXzoI-WW0L3w5)


