Home / Natural Language Processing

What is a Sequence?

A sequence is data where order carries meaning. Shuffle a sentence and watch its meaning fall apart.

Input Sentence

Tip: Try "dog bites man" — a 3-word sentence where a single swap completely flips the meaning.

The Sequence (order preserved)

SEQUENCE INTACT

The Same Words as a Bag (order ignored)

A "bag of words" only knows which words appear and how often — never where. Notice this view never changes when you shuffle: to a bag, every ordering is identical.

Sequences Beyond Text

Stock prices
102 → 105 → 103 → 110

Yesterday's price helps predict today's.

DNA
A → T → G → C → A

Rearranging bases changes the protein.

Music
C → E → G → C

The same notes in a different order is a different melody.

What is a Sequence? Why Order is Information

The foundational idea behind all sequential models — from sliding windows to RNNs and Transformers.

The Core Idea

A sequence is an ordered collection of items where the position of each item carries meaning. "Dog bites man" and "man bites dog" contain exactly the same three words, yet they describe opposite events. That difference lives entirely in the order — and order is precisely what ordinary tabular data doesn't have.

Sequential vs. Tabular Data

In a classic spreadsheet-style dataset, each row is independent: shuffling the rows of a housing-price table changes nothing about what a model can learn. Sequential data breaks this assumption in two ways:

  • Order matters: the items form a meaningful progression — words in a sentence, prices over days, frames in a video.
  • Context matters: the meaning of an element depends on its neighbours. The word "bank" means something different after "river" than after "savings".

Because of this, sequence models need a way to remember or look at what came before — the motivation behind sliding windows, recurrent networks, and attention.

Interactive Exploration Guide

  1. Shuffle the default sentence. Watch the top panel: the words get amber borders and the read-out sentence becomes gibberish, while the "bag" panel below is completely unchanged. The bag never noticed.
  2. Type "dog bites man" and click "Reverse the Order". Three words, one reversal, opposite meaning — the smallest possible demonstration that position is information.
  3. Restore the original. The status badge flips back to green the moment every word returns to its home index.

Key Takeaway

A sequence is not just a set of values — it is values plus their order. Any model that throws the order away (like a bag of words) throws information away with it. Everything else in this NLP track — sliding windows, encodings, embeddings, recurrent cells — exists to let neural networks use that ordering information instead of losing it.

Cheat sheet

What is a Sequence?

A "bag of words" only knows which words appear and how often — never where. Notice this view never changes when you shuffle: to a bag, every ordering is identical.

NLP · vizlearn.in/natural_language_processing/what_is_a_sequence.html