DL
    beginner

    Text Representation (OHE, BOW, N-gram, TF-IDF, Word2Vec)

    algorithms.live

    Text Representation Techniques

    Explore how words are converted to numbers for machine learning

    Input Documents (one per line)

    8 documents • 26 unique words

    One-Hot Encoding (OHE)

    Each word is represented as a binary vector with 1 at its vocabulary position, 0 elsewhere. Vector dimension = vocabulary size (26).

    "a"
    →
    1
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    "and"
    →
    0
    1
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    "are"
    →
    0
    0
    1
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    "crown"
    →
    0
    0
    0
    1
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    "delicious"
    →
    0
    0
    0
    0
    1
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    "eating"
    →
    0
    0
    0
    0
    0
    1
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    "fruits"
    →
    0
    0
    0
    0
    0
    0
    1
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    "guava"
    →
    0
    0
    0
    0
    0
    0
    0
    1
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0

    ...showing first 8 words of 26 total

    Key Properties:

    • Sparse: Only 1 non-zero value per vector (99%+ zeros for large vocab)
    • No semantic meaning: "king" and "queen" are equally distant
    • High dimensional: Vocabulary size = vector dimension
    • Used in: Categorical features, simple classification

    Technique Comparison

    TechniqueDimensionSparsitySemanticsBest For
    OHE|Vocab|Extremely SparseNoneCategorical features
    BOW|Vocab|Very SparseNoneDocument classification
    N-gramsup to |Vocab|^N (in practice, # of observed N-grams)Extremely SparseLocal contextText generation, LMs
    TF-IDF|Vocab|SparseImportanceSearch, similarity
    Word2Vec100-300DenseRich semanticsModern NLP, transfer learning
    NLP
    Text Representation
    Feature Engineering
    Embeddings
    Fundamental

    Order by how much meaning is kept

    Sequence

    Order these representations from least semantic to most.

    Tap a piece, then tap where it goes — or drag it. Tap the tray to take one back.

    1. 1Drop a step here
    2. 2Drop a step here
    3. 3Drop a step here
    4. 4Drop a step here
    4 pieces left to place

    Test your knowledge

    20 questions
    Question 1 of 20
    Score: 0

    What is One-Hot Encoding?

    Interview Questions

    Amazon
    Elastic
    Pinterest
    Yahoo
    Grammarly
    Hugging Face
    Spotify
    Apple
    SoundCloud
    Hugging Face
    Cohere
    Elastic
    Grammarly
    Duolingo
    Meta

    Love this visualization?

    Sign up to track your progress, earn achievements, use the AI assistant, and access your personal learning dashboard.

    100% free • No credit card required