AI · Deep Learning · Computer Vision · Autoencoder and VAE

OUTTA Basic — Connecting Language Models, Embeddings, and Autoencoders

2026-08-01 · updated 2026-08-01 · Hyeongrok Ryu

I connected TF-IDF cosine similarity, dense embeddings, and an autoencoder latent space as different representation-learning tools.

Series
2024 OUTTA AI Bootcamp Basic · 4
Type / level
study-note · intermediate
Tools
Python, PyTorch, scikit-learn, Matplotlib
01From tokens to probability

A checkpoint in the study sequence for this note.

02TF-IDF and cosine similarity

A checkpoint in the study sequence for this note.

03Dense embeddings

A checkpoint in the study sequence for this note.

04Autoencoder latent space

A checkpoint in the study sequence for this note.

A compact concept path generated from this post's table of contents.

From tokens to probability

I defined a language model as a distribution over the next token given previous tokens, not a device that stores complete sentences. The 49-page language-model module led me through vocabulary construction, integer indices, context windows, and shifted targets.

p(w₁…wₜ) = ∏ₜ p(wₜ | w before t)

The same sentence becomes a different index sequence when the tokenizer or vocabulary changes. I therefore fixed padding and unknown-token indices and checked that embedding inputs used the long dtype.

TF-IDF and cosine similarity

Before dense embeddings, I represented documents with TF-IDF. Cosine similarity compares direction rather than vector length. Bright cells in the heatmap connect documents with stronger vocabulary overlap.

cos(a, b) = aᵀb / (‖a‖₂‖b‖₂)

TF-IDF cosine-similarity heatmap for seven documents
The bright symmetric cells reveal the closest document pairs.

Dense embeddings

The 28-page embedding and autoencoder module replaced one-hot vectors with learned dense rows. Embedding(vocab_size, embedding_dim) appends an embedding axis to the input sequence. Cosine similarity still applies, but it now compares learned coordinates instead of raw counts.

Embedding exercise loss falling rapidly with iteration count
The retained curve drops sharply before settling near a low value.

Autoencoder latent space

An autoencoder compresses an input into a smaller latent code and reconstructs it. I initially confused this with PCA. PCA learns linear axes; nonlinear activations between an encoder and decoder can learn a curved representation.

z = fθ(x), x̂ = gφ(z), L = ‖x − x̂‖₂²

Shape-checking code

token_ids = tokenizer(batch_text)          # (batch, time)
vectors = embedding(token_ids)             # (batch, time, dim)

latent = encoder(features)                 # (batch, latent_dim)
reconstruction = decoder(latent)           # (batch, feature_dim)

assert vectors.shape[:2] == token_ids.shape
assert reconstruction.shape == features.shape

How I compared representations

TF-IDF is easy to connect to overlapping words. An embedding stores contextual similarity in a compact dense vector. An autoencoder latent code compresses information needed for reconstruction. I treated them as tools with different objectives and interpretation methods, not as interchangeable answers.

Sources used

  • Basic Language Models — course-pdf; tokenization and next-token prediction
  • Word Embeddings and Autoencoders — course-pdf; dense representations and reconstruction
Publication first-page preview