Skip to main content
Natural Language Processing

Word Embeddings and Word2Vec

Published: 2026-08-13
Level: undergraduate
Audience: Undergraduate students studying Natural Language Processing

Prerequisite Knowledge

This lecture builds on the following concepts from earlier lectures. If any feel unfamiliar, review the linked notes before proceeding.

Previously Covered in This Subject

  • Distributional hypothesis and word embeddings — covered in Lecture 2, Vector Semantics and Word Embeddings
  • Frequency-based sparse vectors (term-document and word-word co-occurrence matrices, TF-IDF) — covered in Lecture 2, Vector Semantics and Word Embeddings
  • Dot product and cosine similarity between vectors — covered in Lecture 2, Vector Semantics and Word Embeddings
  • Context windows around a target word — covered in Lecture 2, Vector Semantics and Word Embeddings
  • Tokenization, stop-word removal, and building a vocabulary from a corpus — covered in Lecture 1

3.1 Word Embedding Recall and Motivation

Why do we even turn words into numbers? Words are strings of letters, and you cannot multiply two strings. So before a machine can compare "bank" and "river" or search through millions of sentences, every word has to become something a computer can do arithmetic with. That something is a vector.

3.1.1 Why Words Become Vectors

A word embedding (how a word is placed into a numeric space) is the act of converting a word into a vector — a list of real numbers. The reason is two-fold:

  1. Similarity becomes computable. With vectors you can measure how alike two words are using a dot product or cosine similarity. Two strings cannot be compared this way at all.
  2. Meaning becomes encoded. A vector built the right way is a semantic representation: the numbers reflect what the word means, not how it is spelled. "Apple" and "mango" should land near each other; "apple" and "xylophone" should not.

Why does "built the right way" work? The guiding idea is the distributional hypothesis, the oldest idea in this field: a word is known by the company it keeps. Words that appear in similar surroundings (say, both preceded by "ripe" and "juicy") are used to mean similar things, so a good training algorithm places their vectors close together. The words themselves carry the signal — nobody writes down meanings by hand.

Think of the map of language. Every word is a city, and the training corpus is a huge pile of travel records saying which cities appear next to which other cities. Cities that hang around with the same neighbours ("coffee" and "tea" both appear near "hot", "cup", "drink") get drawn close on the map. Distance on the map = difference in usage. The analogy breaks in one place: language is not a flat 2D map. The vectors live in hundreds of dimensions, so "close" means close in a high-dimensional space, which your eyes can only see after a projection.

Q: In the previous session the context window was set to plus 4 and minus 4 words. If a sentence ends two words after the target word, does the window check only within that sentence, or does it continue into the next sentence?

A: The window continues past the full stop. The context check is not sentence-based. The window counts raw words on each side of the target, wherever those words fall, so it scans context beyond the sentence boundary too.

Where this session is heading: the star of today is word2vec and its workhorse variant, skip-gram with negative sampling (SGNS), the algorithm industry used everywhere before transformers arrived. Contextual embeddings built with attention inside transformers come in a later module, after the mid-semester break.

3.1.2 Recap: Frequency-Based Approaches and Their Problems

The previous session covered frequency-based embeddings. These are counting methods: TF-IDF weights, count vectors, and co-occurrence counts gathered inside a window of plus/minus 4 words around each target word. Every one of them counts how often words occur — inside a document, or inside a window, or across the whole collection. Counting is simple and cheap, and TF-IDF in particular still powers real search engines today.

The shared weakness is sparsity and size.

  • Sparse means mostly zeros. A sparse vector representation is one where most entries are 0. A TF-IDF vector for one document has a non-zero only for the handful of words that actually appear in that document; the other tens of thousands of slots sit empty.
  • Size means the vocabulary. Each vector's length equals , the number of unique words in the corpus. A training corpus with 100,000 unique words gives every word a vector with 100,000 entries, almost all zero.

Imagine storing 100,000 numbers per word just to hold a handful of useful values — and then computing dot products over those mostly-empty lists, millions of times. Long vectors full of zeros are a real computational burden. They also waste their dimensions: slot 47,213 of the vector means "one specific word occurred", which tells you nothing about meaning.

That burden is the motivating question of this whole session: can we improve this vector format?

3.1.3 Dense Vector Representation

The improvement is the dense vector representation: a short vector where most entries are non-zero. Instead of one slot per vocabulary word, a dense vector has a fixed small number of features — and the feature dimension is much smaller than the vocabulary size:

(the vocabulary size) is the number of unique words in the training corpus; (the embedding dimension) is the length of the dense vector you choose. The word2vec family — skip-gram, skip-gram with negative sampling (SGNS), CBOW — and also GloVe, all produce dense vectors. They come out of the neural language model line of research: the vectors are learned by a small network instead of counted from a table.

A dense vector compresses all the context information about a word into numbers. Where the sparse vector answers "did this exact word occur near me?", the dense vector answers "am I like these other words?" — and it answers it in a form that fits in 300 slots instead of 100,000.

Two design points about matter:

  • must stay well below . If were as large as , the dense format saves nothing — you would be back to one-hot-sized vectors with no compression benefit.
  • should not be enormous either. Typical values: 300 is the commonly recommended starting point; GPT-2 uses 768, GPT-4 about 1024, and reported sizes reach about 4000, rarely beyond 5000. Bigger costs more memory and compute for diminishing returns.
Model / recommendation Embedding dimension
Common recommendation 300
GPT-2 768
GPT-4 about 1024
Reported upper range up to ~4000, rarely beyond 5000

3.1.4 Static Versus Contextual Embeddings

There are two families of dense embeddings, and the difference is when the vector gets built.

Static word embeddings (word2vec, GloVe) do not depend on context. Each word gets one vector, learned once from the training data, and it stays fixed forever after. The word "bank" gets the same vector whether the sentence means a river bank or a financial bank. The vector is a compromise over every use of the word the training data ever saw.

Contextual word embeddings (BERT, GPT) are also dense vectors, but they are computed per occurrence. Inside a transformer, attention mixes each word with its actual surroundings, so "bank" sitting next to "river" produces one vector and "bank" sitting next to "loan" produces another. Contextual embedding gets full treatment after the mid-semester break.

Static (word2vec, GloVe) Contextual (BERT, GPT)
Number of vectors per word one, fixed one per occurrence
Depends on surrounding words? no yes
"bank" (river) vs "bank" (money) same vector different vectors
How built learned once on the whole corpus computed on the fly with attention
Where covered this session later module

The link between the two is direct, and that is why this session matters beyond itself: the intuition and several core ideas of static embedding algorithms carry over into contextual word embedding. Both are dense representations; the difference is only context dependence. The transformer's input is still an embedding table of exactly the kind word2vec builds.

Real-world placement. In next semester's NLP applications and conversational AI topics, practical systems — transformers, LLMs, agentic pipelines — usually run a hybrid: frequency-based sparse vectors (for exact keyword hits and fast first-pass retrieval) combined with dense vectors (for meaning-level matching). Neither family replaced the other; they stack.

Words must become vectors so similarity is computable and meaning is encoded. Counting methods (TF-IDF, co-occurrence) give long, mostly-zero vectors of length ; the fix is a dense vector of learned features. Static embeddings give one vector per word; contextual embeddings give one per occurrence — and the static machinery you learn today is the foundation the contextual models build on.

3.2 Vocabulary, One-Hot Encoding, and the Embedding Matrix

What is the simplest possible way to represent a word as numbers? Give every word in the dictionary its own slot, put a 1 in that slot and 0 everywhere else. It is so simple that it cannot be wrong — and so rigid that it captures nothing about meaning. This section builds that baseline, shows exactly where it breaks, and then shows the one-line fix that turns it into a dense embedding.

3.2.1 From Training Data to Token IDs

Start from the training corpus — all the text you collected. The vocabulary is the set of unique words that appear in it, and its size is written (the running example in this course uses ). The vocabulary also includes one special entry: the unknown token (UNK), a bucket that catches any word not in the vocabulary.

Sort the vocabulary alphabetically (lexicographic order). Each word then gets a token ID — its position in that sorted list, numbered from 0.

Worked example — token IDs for a tiny vocabulary. Sort 4 words alphabetically and number positions from 0:

Sorted word Token ID
aah 0
aardvark 1
aaron 2
zebra 3

The word "aaron" lies at position 2 — the third slot, because numbering starts at 0. Its token ID is 2. This ID is the word's address inside every vector and matrix we build next.

Sense-check: token IDs are just indices into the sorted list — they are arbitrary labels, not numbers that mean anything. Word 2 is not "bigger than" word 1 in any semantic way.

Q: Is the vocabulary made of words or of letters? If the corpus is a web site with many pages, what exactly counts?

A: Words, not letters. The corpus is all the text collected from the pages, and the vocabulary is the set of unique individual words found in that text — "cat", "the", "and", and so on. Letters never enter the picture.

3.2.2 One-Hot Representation

A one-hot vector is a vector of length where exactly one position is 1 and every other position is 0. "One hot" is literal: one position is hot (1), the rest are cold (0).

For a word with token ID , the one-hot vector of shape has:

That is the whole formula — one non-zero entry, at the word's own slot.

Worked example — the one-hot for "aaron". With and "aaron" at token ID 2, the one-hot row is:

Length 4, a single 1 at position 2. With a real vocabulary of 100,000 the same rule gives a row — 99,999 zeros and one 1.

Sense-check: exactly one position is 1 and it matches the token ID from the sorted vocabulary — position 2, so slot 2 is hot.

Q: In the example the one-hot vector has four positions. Is that the size of the vocabulary?

A: Yes. Four words were shown for simplicity, so and the one-hot vector has 4 slots. With a real vocabulary of 100,000 the one-hot vector is .

3.2.3 Why One-Hot Fails

One-hot is a perfect identifier and a terrible representation. Three failures stand out:

  1. No similarity. Any two distinct one-hot vectors have dot product 0 — "apple" and "mango" are exactly as different as "apple" and "xylophone". All pairs of distinct words sit the same distance apart. Orthogonality is fine for an index, useless for meaning.
  2. No context knowledge. A one-hot vector for "orange" says nothing about "juice", even if the corpus pairs them constantly. The spelling of one word cannot tell you anything about another word.
  3. No prediction. Because each word is an isolated axis, you cannot compute "which word comes next" from one-hot vectors — there is no shared coordinate system to make the comparison in.

On top of all that, one-hot keeps the exact problem we are trying to escape: it is the sparse format again, slots per word with almost all zeros. Every one-hot limitation pushes toward the same conclusion — we need dense vectors.

Scope: One-hot works as a lookup key — routing a word to its row in a table — and nothing more. Do not feed one-hot vectors to a model and expect semantic behaviour; the model would have to relearn everything about word relatedness from scratch on every task.

3.2.4 The Embedding Matrix: One-Hot Times a Weight Matrix

The mechanism that converts one-hot to dense is a weight matrix of size . Multiply the one-hot row by this matrix and out comes a dense vector.

For token ID , let be the one-hot row and the weight matrix. The embedding is the product:

The values inside are not hand-crafted. They are weights, learned with gradient descent on self-supervised data (section 3.3). Learning the model and learning the embeddings are the same act.

Worked example — one-hot times the matrix. With and , the one-hot is and the weight matrix is :

The product is a dense vector — "aaron"'s embedding, with no zeros in sight. In the real-sized version the same rule runs at scale: one-hot times weight matrix gives the compressed embedding. Each word drops from slots down to .

Sense-check of shapes: — inner dimensions match (4 = 4) and the output has the outer dimensions. In general . If your inner dimensions do not match, the multiplication is undefined.

There is a neat geometric fact hidden in this multiplication: a one-hot vector picks out one row of the weight matrix. Multiplying by the zeroes contributes nothing; the only survivor is the row whose index is hot. So the embedding of a word is that row of the matrix.

That is why, once the matrix is learned and stored, the matrix and the embeddings are the same thing. At run time you never multiply anything — you just look up row . The one-hot is only a pedagogical stepping stone.

Q: Is the weight matrix consistent for all input words, and is it reused after training?

A: Yes. One matrix is learned over the whole training data and stays fixed for every word. After training you store the word embeddings; the embeddings are rows of this matrix, so later lookups just read the stored vectors. The same weight matrix serves the whole vocabulary — it does not change per word.

Q: Does each word get its own vector, and are vectors combined further or processed individually?

A: Every unique word gets its own vector, and vectors start their life individually. In a prompt like "what is word embedding", each word is converted to its own vector and compared with stored vectors using cosine similarity, and similar words are returned. You can also combine word vectors into a sentence embedding — for example by averaging them or by max pooling, the same pooling idea used in CNNs. Sentence embeddings are what power sentiment classification.

Q: Can two words end up with the same embedding, and can a word's target and context embeddings be the same?

A: No — every word has its own target embedding and its own context embedding, learned separately from the training data. Target and context vectors for the same word are different objects.

3.2.5 The Features Are Learned, Not Named

A key shift in perspective separates machine learning from deep learning:

  • In machine learning, you do feature engineering: you invent features by hand and hand them to the model, which learns weights for them.
  • In deep learning, the features themselves are learned from the training data through hidden nodes and interconnected neurons.

So what are the "features" in our dense vector? Nothing more than — abstract slots in a numeric space. The names are immaterial; only the numbers matter.

Q: How do we get from the one-hot encoding to a representation by features with weights — and how is the number of features decided?

A: The features are not named features like in machine learning. They are — abstract slots whose values are learned. Deep learning learns the features themselves from the training data; here the weight matrix is learned with gradient descent on self-supervised data, and its values are the weights . Do not worry about naming each feature. And is not computed — it is chosen. is a hyperparameter: fixed before training (300 is the size recommended by Andrew Ng, 768 is what GPT-2 uses), and only the weights are learned. Changing — say from 500 to 600 — means the whole matrix must be relearned; renaming the features does nothing.

Pitfalls: (1) Expecting readable meanings — no deep learning algorithm exposes human-readable feature meanings; the model is a black box, and the feature columns are just numbers. (2) Thinking you can resize later — the matrix must be relearned from scratch for a new . (3) Confusing self-supervision with reinforcement learning — see 3.3.3; self-supervision says nothing about rewards, it is a statement about where the labels come from.

Sort the vocabulary, assign token IDs, and one-hot them — but one-hot vectors are sparse, context-blind, and similarity-free. Multiply the one-hot row by a weight matrix and the product is the dense embedding; the multiplication reduces to picking the word's row, so the learned matrix is the embedding table. The features in that row are unnamed learned numbers — and , not the names, is the design choice. Next: how gradient descent learns this matrix without any human labels.

3.3 Word2Vec and Self-Supervised Learning

A decade ago this paper did something quietly radical: it showed you can learn good word vectors from raw text with no human labels at all. Millions of words, zero annotations — the data labels itself. That trick, self-supervision, later became the engine behind every large language model you have heard of.

3.3.1 What word2vec Is

word2vec is the conversion of words to vector format. It comes from a pioneering paper by Google — Mikolov et al. 2013, "Efficient Estimation of Word Representations in Vector Space". The idea is simple and elegant, which is itself a lesson: research does not always need fancy ideas; simple ideas can give very good solutions.

Two properties made word2vec famous:

  • Speed. It is a very fast algorithm. The skip-gram with negative sampling (SGNS) variant became the most-used word embedding method in industry precisely because it trains fast on huge corpora.
  • Portability. Today transformers and attention-based models dominate, but the input to a transformer is still a word embedding of the kind produced by skip-gram. Static embeddings did not die; they became the front door of the models that replaced them.

Real-world placement. Implementations of all the static embeddings are freely available online, including the embedding projector — an interactive tool where you can drag the vector space around and watch similar words huddle together. TF-IDF and word2vec need little compute: they train on a laptop, no GPU cluster or H100 servers required. That is a major practical advantage over training a transformer from scratch.

3.3.2 Self-Supervised Data Generation

Skip-gram training data needs no human labeler. Here is how the labels generate themselves, step by step:

  1. Pick a target word (also called the center word) from the corpus.
  2. Draw a context window of plus/minus words around it — the lecture uses in the worked examples, and the earlier sessions used plus/minus 4.
  3. Every word inside that window is a positive context word.
  4. Words outside the window are out-of-context or negative context words.

Because the window alone defines the labels, the data is called self-supervised: the system generates its own training examples automatically from any English corpus. No human ever says "this pair is correct". The supervision comes from the data itself.

Two practical points:

  • The window adapts to corpus size. With a huge training corpus, a smaller window is fine — there are plenty of context words. With a small corpus, use a longer window so each target still collects enough context words.
  • Each word plays both roles. Every word in the vocabulary gets two representations: one as a target word and one as a context word. A word can be a target in one example and a context word in another.

3.3.3 Supervised, Unsupervised, Self-Supervised — Terminology

The three terms differ only in where the labels come from:

Type Labels Example
Supervised given by humans "plays tennis / does not play tennis" from weather features ; learn parameters , predict class A or B when the dot product crosses a threshold
Unsupervised none at all, input only k-means clustering
Self-supervised none from humans; generated automatically from the data word2vec: whatever lies inside the window is positive, the rest negative

The supervised row is the typical ML model you already know: features go in, parameters get learned, and the dot product against a threshold decides the class. Self-supervision changes only the label story — the model itself still trains the same way.

Q: Is self-supervision the same as reinforcement learning?

A: No. Reinforcement learning is a type of learning algorithm built around a reward model — the agent acts, gets a reward, and adjusts to earn more. Self-supervision is a statement about the training data only: no human labeling, because the labels generate themselves. In word2vec, whatever lies within plus/minus 2 words of a target is positive and the rest is negative — no human and no reward decides it. This distinction came up more than once in class, so expect it to be examined.

The learning algorithm then uses gradient descent on this self-supervised data to learn the weights of the model — and those weights become the embeddings. That closes the loop from section 3.2: the matrix you multiply a one-hot by is trained on data that labeled itself.

word2vec is a fast, simple, self-supervised learner: the context window automatically stamps each word pair as positive (inside the window) or negative (outside). Supervised, unsupervised, and self-supervised differ only in label origin — humans, nothing, or the data itself. Next we look at the actual training examples the window produces: the apricot example and the art of choosing negative words.

3.4 Skip-Gram Training Data: Context and Out-of-Context Words

Before any training happens, word2vec needs a pile of labeled examples — but nobody labels them. This section shows the data factory: slide a window over a sentence, and every (target, neighbour) pair inside the window becomes a positive example; then the model is deliberately fed fakes. The fakes are half the story.

3.4.1 The Context Window Around a Target

Worked example — the apricot window. Take the target word "apricot" with a window of plus/minus 2 words in the sentence

…tablespoon of apricot jam, a…

Counting two words left and two words right of the target gives four context words: tablespoon, of, jam, a. Sliding this window over the corpus automatically generates (target, context) pairs:

Four positive pairs from one window position — no human involved.

Sense-check: the window is word positions, not sentence boundaries. Remember 3.1.1: the window continues past a full stop, so the pairs may straddle two sentences.

3.4.2 Negative Examples

Every pair whose context word lies inside the window is a positive example. For each positive example, sample negative examples — words that do not lie in the window of the target.

Worked example — counting the training set. With 4 positive pairs and :

SGNS deliberately uses more negatives than positives — typically 2 or 3 times as many. is usually 2 to 5 for larger datasets.

Sense-check: 12 examples from one window position shows why huge corpora matter — a single sentence position already yields a dozen training examples.

Why more negatives than positives? Because learning to say "no" is what shapes the space. The same idea appears in contrastive learning, used today when training transformers and visual language models: positive and negative examples, with more negatives to sharpen the contrast so the model learns the weights better.

Think of a school fill-in-the-blank question: give a student the options "jam / table / philosophy" for "apricot ___" and the right choice is obvious in one glance. Give the same student twenty confusing distractors and picking the right one is genuinely hard — and the learning that happens is stronger. More negatives = harder discrimination = better weights. The analogy breaks where noise sneaks in: in the exam every wrong option is guaranteed wrong, but a randomly sampled negative word may actually be a valid context in some sentence of the corpus.

Negative selection needs care:

  • A negative word must not fall inside the target's plus/minus 2 window.
  • If a word is a positive context for a target, it must not appear as a negative for that same pair.
  • The same word can be a negative for a different target — negativity is judged per pair, not globally.
  • Some noise still slips through the samples, which is why you take more training examples — quantity washes out the occasional bad sample.
  • You sample randomly, not exhaustively: if "apple" occurs 1000 times across 10,000 articles, you may pick just 3 or 4 occurrences.

Q: How are negative context words selected?

A: Whatever is outside the target's plus/minus 2 window counts as out-of-context, but you must make sure the negative is not within that window. Randomly select words outside the window — if 4 context words are positive, 8 negatives are drawn for them. Some noise may remain (a word that is a positive context in another document can slip into the negatives), so you take more training examples.

Q: Can a negative word repeat for the same positive pair, or across pairs?

A: Within one pair the negative must be unique — a word appears once as negative for that target. But the same word can be a negative for another target word.

Q: In the toy corpus the sentence only contains "Ned Stark the honorable man", so where do pimples and zebra come from?

A: The toy corpus is only an illustration. A real corpus has many more sentences where pimples and zebra occur outside the context of ned. The negative words come from the entire corpus, not from the one displayed sentence.

3.4.3 Each Word Has Two Embeddings

Every word in the vocabulary carries two vectors:

  • a target embedding — used when the word acts as the target (center) word, and
  • a context embedding — used when it acts as a context word.

SGNS learns both, and they remain distinct through training. At the end, the final vector used for a word is the sum of its two embeddings:

Pitfalls: (1) Sampling a negative that is actually a context word of the target in some sentence — that injects noise, which is why more examples help. (2) Reusing the same negative within one pair — not allowed; one negative per pair. (3) Forgetting that the two roles use different vectors — a word's target row and context row are separate objects, learned and updated separately.

The window converts sentences into (target, context) pairs — 4 positives for apricot — and each positive gets random out-of-window negatives, giving 12 training examples from one position. More negatives than positives sharpens the learning, exactly as contrastive learning does today. And every word owns two embeddings: the final one is the sum of the two. Next: how a classifier turns all these pairs into vectors.

3.5 The Classification Framework and Its Math

3.5.1 Word2Vec as Binary Classification

The training problem gets reframed as classification. Positive pairs (target + a word inside the window) form the positive class with label ; negative pairs (target + an out-of-context word) form the negative class with label . Two classes only: context and out of context.

The training goal follows straight from the labels:

  • maximize the similarity between the target and its context words, and
  • minimize the similarity between the target and the out-of-context words.

Training the classifier learns the weights — and those weights are the embeddings. The classifier is a means to an end: we do not care about the classification task itself, only about the vectors the network builds while solving it.

Why frame it this way? The original skip-gram asked a 100,000-way question — "which word out of the whole vocabulary is the context?" — using a softmax over all words. Every single training step had to compute a dot product against the entire vocabulary, which is brutally expensive at . Negative sampling swaps that for a far cheaper binary question: "is this specific pair real or fake?" That is the whole trick.

The security guard analogy for why this matters. A guard checking tickets at a stadium could verify each fan by comparing them against every one of the 100,000 people inside (softmax over the whole vocabulary) — or the guard could check the entering fan's ticket and glance at just a handful of random people nearby to confirm they have no ticket (negative sampling). Same decision, checks instead of checks. The analogy breaks on one detail: the guard only verifies tickets, while SGNS updates vectors during the check — the few sampled words are the only ones whose vectors move.

Any classification algorithm could be used — decision tree, SVM, naive Bayes — but skip-gram uses logistic regression, the same classifier from the ML course. That is convenient: everything below reuses the logistic machinery you already know.

3.5.2 Similarity and the Sigmoid Probability

To measure similarity we take the dot product of the two vectors. The dot product is not normalized, so raw values are hard to interpret — is 0.508 big? Small? That is why the dot product is pushed through the sigmoid function to get a probability (or we use cosine similarity for retrieval, where interpretability is less important).

The sigmoid function is the logistic function from ML:

It takes any real number and squashes it into the range . Here is the dot product , where is the target word vector and is the context word vector. So the probability that the pair is a positive example is:

The probability that the pair is negative is one minus that. A mechanical substitution gives the twin formula:

Read the middle form aloud and it matches the lecture: "the negative probability is 1 by 1 plus e raised to plus c dot w." Training wants the positive probability near 1 and the negative probability near 0.

The identity is worth memorising — it says the sigmoid is symmetric around the point in the sense that mirroring the input flips the output around one half. It is the step that lets the same function handle both classes.

Why sigmoid? Its derivative is elegant. Verify it once with the chain rule, because the result is used constantly:

The derivative of the sigmoid is just "sigmoid times one minus sigmoid" — no exponentials left in the expression, which makes gradient math cheap. That nice property is why sigmoid shows up in feedforward networks, transformers, and softmax-style variants across the field.

Visual intuition. Plot on the horizontal axis and on the vertical: the curve is an S. It hugs 0 on the far left, rises through exactly at , and hugs 1 on the far right, never quite touching either end. Landmarks: at the curve reads ; at it reads — mirror inputs give mirror distances from the ends. The takeaway: the sigmoid is a soft switch — large positive dot products read as "same context" (near 1), large negative ones as "out of context" (near 0), and everything in between is graded smoothly.

3.5.3 Multiple Context Words: Product Becomes Sum

With context words , the probability of the whole set being positive is the product of the individual probabilities:

Products of small probabilities shrink fast: , and ten such terms would be unreadable — numbers that small also play badly with floating-point arithmetic on a computer. Probability theory has a standard fix: take the log. The log converts the product into a summation:

Logarithm = counting digits, or "how many times you fold paper". Products of tiny numbers become sums of medium negative numbers — becomes about — which are stable to compute and easy to differentiate. Cross-entropy loss uses the log for exactly this reason. The analogy breaks if you push it: log is not just a bookkeeping trick; it also reshapes the optimization landscape, but for this course the bookkeeping story is the useful one.

3.5.4 The SGNS Loss and Its Gradients

For one target word , one positive context word , and negative words , the loss is:

Each term is the usual logistic log loss. With labels for the positive and for each negative, a single term reads:

Put and the bracket keeps only — the positive term. Put and it keeps — the negative term. So the SGNS loss is logistic regression's cross-entropy written out for one positive plus negatives. Minimizing it raises the positive probability and lowers the negative probabilities, exactly the goal from 3.5.1.

Deriving the gradient with respect to the target . Use the chain rule one term at a time. For a term of the form with :

and . For the positive term, . For a negative term, , so , and the minus sign flips the error back:

In words: the positive term is sigmoid minus its label 1 times the positive context vector; each negative term is sigmoid minus its label 0 times that negative vector; add all the vectors. The unified pattern: (predicted probability minus true label) times the other vector.

The same chain rule gives the derivatives with respect to the context vectors — now the inner derivative of is itself, so multiplies the error:

The pattern to remember: differentiating with respect to the target pulls in the context vector as the multiplier; differentiating with respect to a context word pulls in the target vector , because appears in both the positive and negative terms of the loss.

The update rule is plain gradient descent — new weight = old weight minus times the derivative of the loss:

Scope: These updates assume the window defines truth — a positive pair is positive by construction of the window, not by human judgment. The loss also treats the context words independently (the product in 3.5.3), so correlations between neighbours inside the window are ignored — a harmless simplification in practice. The dot product similarity itself is sensitive to vector lengths (a long vector scores high against everything), which is why the sigmoid calibration and enough training examples matter. If the sampled negatives are noisy — a true neighbour drawn as a negative — the gradients fight each other, and training compensates with volume, not precision.

The full derivation of these gradients appears in the appendix of the Jurafsky and Martin textbook. The exam does not require deriving the loss function itself.

3.5.5 Gradient Descent Variants and the Learning Rate

A quick recap of the SGD variants from the ML course, applied to the 12 training examples from the apricot example:

  • Batch gradient descent: update the weights after all training examples (after all 12).
  • Mini-batch: divide into chunks (say, two chunks of 6) and update after each chunk.
  • Stochastic gradient descent: update after every single training example.

SGNS uses stochastic gradient descent: update after every example, where one example = one positive pair together with its negative pairs.

The learning rate is the step size — how fast you go down the loss curve. If is very large, you move fast and can overshoot and miss the minimum; if very small, convergence takes very long. Typical values are 0.05 or 0.01. At the minimum of the loss curve the derivative equals 0 — the update stops changing the weights, which is the signature that you have arrived. Stopping criteria are the same as any gradient descent: stop when the loss reaches a minimum, or after a fixed number of iterations (say 10), or after going through the training examples (say 12).

Q: When there are several positive context words, do we compute the probability for each word individually or the sum total?

A: Individually first — each context word's probability should be high on its own — and then the whole set as one function. The likelihood is the product over the context words (which a softmax-style view would normalize across all words), and the log converts the product into a sum. The slide example shows one positive and a few negatives only to keep the arithmetic simple.

Q: Are the positive and negative initial values given to us, or do we compute them?

A: Initial values are given. The algorithm starts from randomized values, and in the exam the table of initial embeddings will be provided. What you compute is the dot product and the sigmoid.

Exam note: SGNS is logistic regression on self-generated pairs: positive probability , negative probability , and a loss whose gradient has one memorable shape — (sigmoid minus label) times the other vector — applied with SGD after every example. You do not need to derive the loss, but you must be able to use the update formulas with typically 0.05 or 0.01. Next: the whole machinery, run by hand on the ned–stark example.

3.6 SGNS Worked Example: Ned Stark, One Full Iteration

Everything so far converges on one question: can you run a single SGNS update by hand? Yes — and this section does it with real numbers, one full iteration for the target word "ned". This exact style of problem is flagged as very likely on the exam.

3.6.1 Setup, Embedding Dimensions, and Initialization

Toy corpus: "Ned Stark the honorable man" — five words after stop-word removal. The vocabulary has 5 words; every word gets a target embedding and a context embedding of dimension

All vectors start from random values. Initialization guidelines: values between and , avoiding zeros and avoiding too-high values. (Small random values keep the dot products tame at the start, so the sigmoids begin near where the gradient is largest — the network learns fastest from a neutral start.)

The slide table for this iteration — target word ned (), positive context stark (), and three negative context words pimples, zebra, idle (, so ):

Word Role Vector
ned target
stark positive context
pimples negative
zebra negative
idle negative

One target, one positive, three negatives — this single set is one training example.

3.6.2 Forward Pass: Dot Products and Sigmoid

Take the dot product of the target vector with each context vector — multiply component-wise and add. For the positive pair:

Then push it through the sigmoid:

A note on the numbers read aloud in class: the lecture quotes "you get this 0.55 value" for the positive sigmoid, while the slide's dot product gives — the two differ because the slide table rounds its own entries. When you solve a problem, the table you are given is the authority: compute each sigmoid from the dot products in your table and carry one consistent value through every later step. The worked computation here uses so every number lines up end to end.

For the negatives, use the negative formula — the same dot product but with , which equals :

The three negative probabilities should be 0, but the random initialization gives around 0.55 for each:

Worked example — the sigmoid table. Store these values in a table. They are needed twice: once as the probabilities, and once inside the derivative formulas of the target update. Good exam practice is to build this table explicitly — it is easier to grade and harder to get wrong.

Pair Dot product True label Error
ned–stark (positive)
ned–pimples (negative)
ned–zebra (negative)
ned–idle (negative)

Sense-check against the labels: the positive pair should predict 1 but predicts 0.62 — the model is wrong by . Each negative pair should predict 0 but predicts about 0.55 — wrong by each. Nothing is right yet, so the embeddings must be updated.

3.6.3 Updating the Target Embedding

The derivative with respect to the target (from 3.5.4):

Compute each term — the positive error times the stark vector, plus each negative sigmoid times its vector:

Add the four vectors:

Then update with (the worked slide uses 0.05; 0.01 is the other typical value — the lecture's spoken "0.5 by default" is the slide's 0.05):

The headline result matches the slide: the first component of ned moves from to about . The old value was negative and the update pushes it positive — toward stark's positive first component. That is exactly the aim: the positive context embedding moves closer to the target, while the negative pulls drag ned away from pimples, zebra, and idle.

Q: Should the updated target embedding end up closer to stark?

A: Yes, that is the aim. The first component moved from a negative value (about ) to a positive one (about ), which lies closer to stark's embedding. The negatives pull in the opposite direction at the same time.

3.6.4 Updating the Context Embeddings

The same iteration also updates the context word vectors. For the positive context stark, reuse the error from the table — but multiply it by the target vector (ned), not by the context vector:

For each negative, use its own sigmoid from the table:

Each negative context word is updated individually with its own sigmoid. Geometrically the update is pure force: stark is pulled slightly toward ned (its error is negative, so adds a touch of ned to stark), and each negative is pushed away (positive error times the target vector, subtracted). Words that appear together attract; sampled words that do not appear together repel.

3.6.5 Iterations and Stopping

One pass through one positive pair and its negatives is one iteration — and since SGNS updates after every example, it is also one stochastic update. In practice you repeat over all training examples: stark will later act as target with its own context window, pimples as target with other negatives, and so on. Each word keeps a single target embedding and a single context embedding, but a word serving as context for many targets gets updated many times — and that is fine, that accumulation is the learning.

When to stop? Stop when the loss reaches a minimum, or after a fixed number of iterations, or after passing through the training examples. The gradient descent stopping logic applies unchanged.

Pitfalls: (1) Mixing roles — updating stark's target vector when stark is acting as context; the roles use different rows. (2) Multiplying the positive error by the wrong vector when updating contexts — with respect to , the multiplier is . (3) Rounding every line differently so the update no longer matches the table — pick one sigmoid value per pair and carry it everywhere. (4) Expecting one update to do much — one step moves a vector a little; it takes many examples for words to truly come together.

Q: When we finish learning for ned and move on to stark as the next target, will the new updates disturb what ned learned?

A: No. Stark acting as a target uses stark's target embedding, a different row from stark's context embedding. Every word has exactly one target embedding and one context embedding. A context embedding can be updated from many targets, and that is fine.

Q: Is the whole set — one positive and three negatives — one example or one iteration?

A: Both, in this case: one training example and one stochastic update. After it, you repeat for the other examples. One update may not bring the two words close; closeness takes many examples.

Q: The values (1 and 0) — are they given by us or computed?

A: They are given by the binary classification setup: 1 for the positive context, 0 for each negative. The sigmoid is the predicted value; the difference between the two is the error that drives the update.

Practice run — the king example (one more iteration, different numbers). Target king , positive context rules , one negative table , , .

  1. Dot products: ; .
  2. Sigmoids: (goal 1); (goal 0 — the model thinks this fake pair might be real).
  3. Errors: positive ; negative .
  4. Gradient for the target: .
  5. Update: .

Sense-check: the y-coordinate grew toward rules (at ) and the x-coordinate shrank away from table (at ) — attraction and repulsion working exactly as designed. Updating the context vectors is the mirror move: and .

Exam note: A numerical SGNS problem is very likely. The statement will give the target, the positive and negative context words, and the initial embedding table with small (2 to 4). You compute: dot products, a sigmoid table, one target update, and one update per context word — with simple values like 0.1 and 0.01; the exam tests understanding, not arithmetic skill. Show the sigmoid table explicitly; it is easier to grade. Use (or 0.01) and remember the labels are given: positive, negative. The full worked calculations also live in the shared Excel sheet — go through the slides, the video, and the sheet and practice, because this math matters.

3.7 Hyperparameters, OOV Words, and Practical Training Choices

By now the algorithm is clear; what separates a decent embedding from a great one is a handful of knobs and corner cases. This section collects them: how wide the window, how many negatives, what to do with words you have never seen, and how the two vectors per word merge into one.

3.7.1 The Context Window and K

The two main knobs are the context window (words on each side) and (negative samples per positive pair):

  • Window : plus/minus 2 in the worked examples, but plus/minus 4 or 5 works too. Small corpus → larger window, because you need more context words per target; huge corpus → smaller window is fine, since context is plentiful.
  • : 2 to 5 for larger datasets; the apricot example used (8 negatives from 4 positives, 12 examples total) and the ned example used . More negatives generally give better learning but slow down training, since each negative costs a dot product and a vector update.

3.7.2 Out-of-Vocabulary Words

Q: Is it possible that a word has no embedding because it never appeared in training, and then a user asks about it at runtime?

A: Yes — the out-of-vocabulary (OOV) problem. Words the training corpus never contained have no word embedding at all; they become unknown tokens, and at test time nothing can be done about them. TF-IDF does not have this problem because it needs no training — it can weigh any word on the fly. That is exactly why real systems use hybrid techniques: dense retrieval plus sparse retrieval, so OOV words are still covered by the sparse side.

The OOV gap is a direct consequence of the static design: the vocabulary is frozen at training time, and the matrix has a row only for words in that vocabulary. Retraining is the only way to add a brand-new word's embedding.

3.7.3 Static Means Learned Once

The weight matrix is learned once from the training data and then stays fixed for every word. This is why these algorithms are called static word embeddings. Given the same corpus, the learned matrix is the same; a different training corpus yields a different matrix. There is no per-user or per-sentence computation — the vectors are precomputed and stored.

3.7.4 Choosing D and Initialization

  • (embedding dimension) is a hyperparameter: 300 is the common recommendation, GPT-2 uses 768, GPT-4 about 1024, and typical practice keeps below 5000. must be smaller than , otherwise there is no benefit over one-hot.
  • Initialization: random values in , no zeros, nothing too large. Small symmetric random values start every sigmoid near — the point of steepest gradient — so learning starts fast. A reference document with initialization guidelines was shared in class.

3.7.5 Final Embedding = Target Plus Context

After training, the vector used for a word is the sum of its target embedding and its context embedding:

SGNS learns two sets of embeddings; the final representation adds them. This is a specific detail to remember — the lecture states it flat out: "the word embedding for each word is going to be the summation of the target and the context."

3.7.6 How Negatives Are Sampled: The Noise Distribution

A supporting detail from the reference material, useful for knowing why real implementations do not just pick uniformly: negative words are drawn from a noise distribution rather than uniformly. Drawing from the raw frequency distribution would flood the samples with ultra-frequent words like "the" and "is", which teach the model little. The standard fix raises the unigram distribution to the power :

The power is a smoothing trick: it shrinks the gap between frequent and rare words, so rare words get sampled a bit more often and frequent words a bit less. (" to the three quarters" sits between the square root and the identity power 1 — milder than a square root, enough to rebalance.) In this course, unless a problem says otherwise, you can treat negatives as randomly drawn from outside the window; the detail is context, not exam arithmetic.

3.7.7 Subsampling Frequent Words

One more standard trick: subsampling. Very frequent words like "the" and "is" appear everywhere and carry little meaning — the pair (France, the) teaches almost nothing compared to (France, Paris). Implementations randomly discard such words before generating pairs, with probability

where is a threshold (for example ) and is the word's frequency. Frequent words get dropped often, rare words almost never. This speeds up training and improves the embeddings of rarer words, because they stop being swamped by "the".

Pitfalls: (1) Using a huge for a small corpus — more parameters than data means the vectors memorize noise. (2) Expecting coverage of brand-new words — static embeddings have none; the OOV answer is a hybrid system, not a better matrix. (3) Forgetting that the final vector is the sum of two embeddings, not a choice between them. (4) Sampling negatives uniformly in a real project — the reweighted noise distribution exists for a reason.

Exam note: the phrase to remember is "final word embedding = target embedding + context embedding". The knobs are (window, larger for small corpora) and (negatives per positive, 2–5); is fixed before training (300 is standard) and initial values are random in . Static embeddings are trained once and cannot cover words the corpus never saw — that is the OOV problem, and the industrial answer is hybrid sparse + dense retrieval. The appendix sections that follow collect the exam guidance and industry picture for the whole lecture.

Exam Guidance Summary

  • A numerical SGNS problem is very likely. The statement will give you: the target word, the positive context words, the negative context words, and the table of initial embeddings (with , 3, or at most 4). Expect a numerical on skip-gram negative sampling — it may be tweaked, not exactly as shown in class.
  • What you must compute: dot products, a sigmoid table (positive and negative rows), one SGD weight update for the target, and one update for each context word. Exam note: show your work in a table — it is easier to grade, and reusing the table rows in the derivative step saves you from recomputing sigmoids.
  • The labels are given, not computed: for the positive context, for each negative. The sigmoid is the prediction; the difference between the two is the error that drives the update.
  • Values stay simple: numbers like 0.1 and 0.01. The exam tests understanding of the concept, not calculation skill. No big numbers.
  • You do not have to derive the loss function. Know the update formulas — — and the derivative pattern: sigmoid minus label, times the other vector.
  • Learning rate: typically 0.05 (or 0.01). Stopping criteria: minimum loss, or a fixed number of iterations.
  • Remember: final word embedding = target embedding + context embedding.
  • Theory background: the full content — skip-gram, TF-IDF, contextual embeddings — is in the Jurafsky and Martin textbook, and the derivation is in its appendix. Andrew Ng's tutorial video and slides cover the intuition.
  • Practice: the instructor shares the Excel sheet with the correct worked calculations. Go through the sheet, the slides, and the recording again — practice is required, because this math is the exam's centrepiece.

Key Industry Applications

  • SGNS was the industry standard. Skip-gram negative sampling was the most popular word embedding method in industry before transformer-based embeddings (BERT, GPT) took over — and it trained fast enough to run on enormous corpora.
  • LLMs still begin with word vectors. GPT-2 uses 768-dimension word vectors and GPT-4 about 1024; every large language model consumes dense word embeddings as its input layer.
  • Transformers build on static embeddings. Attention inside a transformer produces contextual embeddings, but the input to the transformer is still a static-style word embedding table of the kind this lecture describes.
  • Hybrid retrieval is production practice. Real systems combine sparse retrieval (TF-IDF) with dense retrieval (word vectors); the sparse side also covers out-of-vocabulary words that the dense side cannot.
  • Similarity search is a whole industry. Dense vectors let a user prompt be converted to vectors and matched against a stored vector data store using cosine similarity — the machinery behind modern search, recommendation, and retrieval-augmented generation (RAG) systems.
  • Sentence embeddings power classification. Averaging or max-pooling word vectors builds sentence embeddings, which drive sentiment classification and other lightweight text classifiers without any deep model.
  • Negative sampling became contrastive learning. The positive/negative pair idea is exactly the mechanism of contrastive learning used today in transformer training and visual language models.
  • Static embeddings run anywhere. Tools like the interactive embedding projector (which lets you visually explore the vector space) run on a laptop without GPUs — no H100 servers needed.
  • Named references: the Google word2vec paper (Mikolov et al. 2013, "Efficient Estimation of Word Representations in Vector Space"), Andrew Ng's tutorial, and the Jurafsky and Martin textbook (skip-gram, TF-IDF, contextual word embeddings).

NLP Lecture 3 Notes · Word Embeddings and Word2Vec

Natural Language Processing· undergraduate· 2026-08-13

Sections Breakdown

13.1 Word Embedding Recall and Motivation

Why words must become vectors, the failure of sparse frequency-based embeddings, dense vectors, and static versus contextual embeddings.

23.2 Vocabulary, One-Hot Encoding, and the Embedding Matrix

Vocabulary, token IDs, one-hot vectors, why one-hot fails, and the embedding matrix that turns one-hot into dense vectors.

33.3 Word2Vec and Self-Supervised Learning

The word2vec algorithm and how the context window generates labels without human supervision.

43.4 Skip-Gram Training Data: Context and Out-of-Context Words

Positive and negative training pairs from the context window, K negative samples, and the two embeddings per word.

53.5 The Classification Framework and Its Math

SGNS as binary classification with the sigmoid probability, the cross-entropy loss, and its gradients.

63.6 SGNS Worked Example: Ned Stark, One Full Iteration

A complete hand-run SGNS update: dot products, the sigmoid table, and gradient updates for the ned-stark example.

73.7 Hyperparameters, OOV Words, and Practical Training Choices

Window and K choices, embedding dimension D, initialization, out-of-vocabulary words, and the final target-plus-context embedding.

8Exam Guidance Summary

What the numerical SGNS exam problem will ask for and how to structure the solution.

9Key Industry Applications

How static embeddings, negative sampling, and hybrid retrieval are used in production systems.

Undergraduate students studying Natural Language Processing

Exam Revision Notes

Below is the distilled, exam-ready core. Every entry comes from the full explanation above. Use this section for rapid review; return to the main notes when a point needs more context.

Word Embedding Recall and Motivation

Must-know: Dense vectors use D much smaller than V and encode meaning from context; static embeddings are one vector per word, contextual embeddings one per occurrence.

⚠️ Top pitfall: Thinking the context window stops at the sentence boundary - it continues past the full stop, since the window counts raw words, not sentences.

Self-check: A corpus has 100,000 unique words. How long is a one-hot vector, and how long is a dense embedding with D = 300?

Connects to: Vocabulary, One-Hot Encoding, and the Embedding Matrix, Word2Vec and Self-Supervised Learning

Vocabulary, One-Hot Encoding, and the Embedding Matrix

Must-know: One-hot size is 1 by V; multiplying by the V by D weight matrix gives the 1 by D embedding, which is exactly the word's row of the matrix; D is a hyperparameter (300 typical) and must stay below V.

⚠️ Top pitfall: Expecting the learned features F_1 ... F_300 to have human-readable names - they are abstract numeric slots.

Self-check: Vocabulary V = 4, D = 5. What are the shapes of the one-hot, the weight matrix, and the product?

Connects to: Word Embedding Recall and Motivation, Word2Vec and Self-Supervised Learning

Word2Vec and Self-Supervised Learning

Must-know: Self-supervision means the labels come from the data itself (context window), unlike reinforcement learning which uses a reward model; window size adapts to corpus size.

⚠️ Top pitfall: Calling word2vec reinforcement learning - it has no reward model; the confusion point between self-supervision and RL is examinable.

Self-check: Who labels the word2vec training data, and what makes a pair positive?

Connects to: Word Embedding Recall and Motivation, Vocabulary, One-Hot Encoding, and the Embedding Matrix, Skip-Gram Training Data: Context and Out-of-Context Words

Skip-Gram Training Data: Context and Out-of-Context Words

Must-know: 4 positive pairs with K = 2 give 8 negatives and 12 training examples; negatives must be outside the window and unique per pair, and the final word embedding is target + context embedding.

⚠️ Top pitfall: Letting a negative word come from inside the target's context window, or reusing a negative within the same pair.

Self-check: Apricot has 4 positive context words and K = 3. How many training examples does one window position produce?

Connects to: Word2Vec and Self-Supervised Learning, The Classification Framework and Its Math

The Classification Framework and Its Math

Must-know: Positive probability is sigmoid of the dot product, negative probability is sigmoid of minus the dot product; every gradient is (sigmoid minus label) times the other vector, and the update is w_new = w_old − η × ∂L/∂w.

⚠️ Top pitfall: Forgetting that sigmoid prime is sigma times one minus sigma, or multiplying the error by the wrong vector when differentiating with respect to the context word.

Self-check: For a pair with c dot w = 0.508, compute sigma(c dot w), sigma(-c dot w), and their sum.

Connects to: Skip-Gram Training Data: Context and Out-of-Context Words, SGNS Worked Example: Ned Stark, One Full Iteration

SGNS Worked Example: Ned Stark, One Full Iteration

Must-know: Given the initial embedding table, compute the dot products, build the sigmoid table, then update the target with (sigma minus label) times each context vector and each context word with (sigma minus label) times the target vector, using w_new = w_old − η × ∂L/∂w.

⚠️ Top pitfall: Multiplying the positive error by the context vector when updating the context word - with respect to c the multiplier is the target vector w.

Self-check: ned dot stark = 0.508, eta = 0.05. What are sigma, the positive error, and the first component of the updated ned?

Connects to: The Classification Framework and Its Math, Hyperparameters, OOV Words, and Practical Training Choices

Hyperparameters, OOV Words, and Practical Training Choices

Must-know: Final word embedding = target embedding + context embedding; window larger for small corpora, K between 2 and 5; static embeddings have no coverage for OOV words, hence hybrid sparse + dense retrieval.

⚠️ Top pitfall: Believing a word outside the training vocabulary can still get an embedding at test time - static embeddings cannot cover OOV words.

Self-check: Why does TF-IDF survive out-of-vocabulary words while word2vec does not?

Connects to: SGNS Worked Example: Ned Stark, One Full Iteration, Word Embedding Recall and Motivation

Exam Guidance Summary

Must-know: A numerical SGNS problem is very likely: dot products, sigmoid table, one update per vector with eta 0.05; show work in a table; no loss derivation required.

⚠️ Top pitfall: Treating the sigmoid as the label - the labels t = 1 and t = 0 are given; the sigmoid is the prediction and their difference is the error.

Self-check: What will the exam problem statement give you, and what must you compute from it?

Connects to: The Classification Framework and Its Math, SGNS Worked Example: Ned Stark, One Full Iteration, Hyperparameters, OOV Words, and Practical Training Choices

Key Industry Applications

Must-know: Static embeddings like SGNS still matter: transformers consume them as inputs, and production retrieval combines sparse TF-IDF with dense vectors, which also covers OOV words.

⚠️ Top pitfall: Assuming word2vec is obsolete - its ideas (self-supervision, negative sampling) are the foundation of contrastive learning and transformer input layers.

Self-check: Which two retrieval families do production systems combine, and what problem does the hybrid solve?

Connects to: Word Embedding Recall and Motivation, Word2Vec and Self-Supervised Learning, Hyperparameters, OOV Words, and Practical Training Choices

Was this lecture useful?

Loading comments…
🤖

BitsNotes AI Assistant

Subject Notes Assistant

Configure AI Chat

Choose how to access the chatbot
Have your own API key?

Switch to "Bring Your Own Key" tab above for unlimited access with any OpenAI-compatible provider.

🔑 Enter API key above to fetch live models from provider, or enter model name manually.
OpenAI-Compatible API Support

Choose any provider preset (Gemini, DeepSeek, Kimi, GLM, MiniMax, Qwen, OpenAI, Groq, Ollama, etc.) or enter a custom endpoint URL.

Security & Privacy First

Your API key is sent directly from your browser to your specified provider. BitsNotes servers never store or see your key.