> For the complete documentation index, see [llms.txt](https://dsic-alcoi.gitbook.io/the-new-revolution-of-generative-ai-models/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dsic-alcoi.gitbook.io/the-new-revolution-of-generative-ai-models/basic-concepts-on-generative-ai/image-generation/autoencoders.md).

# Autoencoders

NN can generate new images? Creativity? Random numbers?

**Autoencoders** are NN with two main characteristics:&#x20;

* The input and output layers have the same dimensions (hidden layers preferably lesser)&#x20;

* It is a unsupervised model, so no labels&#x20;

An autoencoder is, in fact, composed by two concatenated NN, generally trained as a whole:&#x20;

* Encoder: tries to get a selected set of features (latent space) by compressing the input into a lesser dimensional space&#x20;

* Decoder: tries to reconstruct the original input as close as possible &#x20;

**Some applications:** denoising images, anomalies detection, recommendation engines, generative models etc.

<figure><img src="https://4092288392-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FY8AeUFC5KYkaUv3lbFhX%2Fuploads%2FVaII7jvo2PpIGJ511dLS%2Fimage.png?alt=media&amp;token=3b979239-3f82-4fa1-b368-075e0eeef2e1" alt=""><figcaption><p>The layer in red is also known as LATENT SPACE</p></figcaption></figure>

<figure><img src="https://4092288392-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FY8AeUFC5KYkaUv3lbFhX%2Fuploads%2F0ffggjCDs9Q2G9IEsDtz%2Fimage.png?alt=media&amp;token=c15da944-3085-4464-bf7b-d5a01606e459" alt=""><figcaption><p>The latent space becomes a kind of compression - or we can think about it as a way to get the 'essence' of the element - uhmmm.... so, somehow NN can retain 'essence' of things? and other semantic features from images or videos?</p></figcaption></figure>

<figure><img src="https://4092288392-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FY8AeUFC5KYkaUv3lbFhX%2Fuploads%2FB2X9o0H4tIhCpP0KCKpU%2Fimage.png?alt=media&amp;token=c7b03d17-b04b-438a-92d6-33aff8691c85" alt=""><figcaption><p>Example of denoising use of autoencoders - pay attention, since this can help in order to understand how stable diffusion models work</p></figcaption></figure>

{% hint style="info" %}
**Question:** What can happen if we train an autoencoder with thousands of faces, where we use the same image as input and output and force the NN to get into the latent space the best way te get the essence of a face?

And what happens if afterwards, we use just the decoder part, by using a new latent space generated by random numbers???

We will be creating new faces !!! Isn't this **creativity**????
{% endhint %}

<figure><img src="https://4092288392-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FY8AeUFC5KYkaUv3lbFhX%2Fuploads%2FE693FRZU5ZTdmSfCG9Sl%2Fimage.png?alt=media&amp;token=ac7631dd-78c0-4f45-a6ab-bc2d592d754e" alt=""><figcaption><p>Example use of autoencoders as generative models</p></figcaption></figure>

**Variational autoencoders** works by making the latent space more predictable, more continuous, less sparse.

They do that by forcing latent variables to become normally distributed, so VAE gain control over the latent space.

<figure><img src="https://4092288392-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FY8AeUFC5KYkaUv3lbFhX%2Fuploads%2FT9AvBGVQPgLyTHSSppzH%2Fimage.png?alt=media&amp;token=aa3e9377-23f4-49c2-b18e-b5daa88d17e5" alt=""><figcaption></figcaption></figure>

VAE allows the similar elements in latent space to be closer, and make much easier to generate new 'good' variations in generative modeling.

<figure><img src="https://4092288392-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FY8AeUFC5KYkaUv3lbFhX%2Fuploads%2FqkPWB2kNM9JCqKyjFvDn%2Fimage.png?alt=media&amp;token=c8600b88-7994-4f1a-9e15-137db2cba8e5" alt=""><figcaption></figcaption></figure>

<figure><img src="https://4092288392-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FY8AeUFC5KYkaUv3lbFhX%2Fuploads%2FpYOeytVp3UFUGTwWV2vQ%2Fimage.png?alt=media&amp;token=491876fc-17a3-4271-940f-047d120e4d16" alt=""><figcaption></figcaption></figure>
