Back to section lessons
Free overview · medium · Lesson 3 of 9

Preserve word order

Swap two words and see why a model needs to know which came first.

A model receives numbers in place of words. One way to represent context is to reserve a place for each position. Swapping two words then changes the input even if the set of words stays the same.

A small example

Compare “cat sees dog” with “dog sees cat”. Let cat be 1, dog be 2 and sees be 3. The sequences [1, 3, 2] and [2, 3, 1] have the same sum. If you keep only the sum, how could you tell who sees whom?

What gets lost in a sum?

Both phrases add up to 6. Any rule that only receives the sum gets exactly the same input twice. By that point it has lost the evidence it would need to identify which animal came first.

Now draw three labelled boxes: first word, second word, third word. To answer “who sees?” in these two sentences, read the first box. A model can preserve this distinction too by giving each word position a separate place in its input.

See it happen

Same words. A different order.

Swap twice and compare. Joining keeps a separate place for each word. Averaging loses this distinction.

api[1, 2]responds[3, 4]

Join positions

[1, 2, 3, 4]

The first two numbers belong to the first word.

Average the words

[2, 3]

The average stays the same after a swap.

api → responds

Vectors are assigned for this calculation. These are not learned language meanings.

Done reading?

Mark the lesson as read to move your track progress forward.

Now build your own version

Write the first forward pass. Use controlled weights to verify that word order is preserved and separate examples stay separate.

What practice includes and how much it costs

MCP includes the full lesson and a local project with starter files. Work through the task with your agent, ask for a hint and run the checks on your computer.

$134 $67.00 for one year −50%

One payment, no auto-renewal · Terms

Buy for $67.00