liveBook · Manning

Embedding

As explained in Transfer Learning for Natural Language Processing

An embedding is a vector representation of an item in a space where relationships among items can be modeled geometrically.

An embedding represents text as a vector in a space where distances can reflect differences in meaning. Neural methods such as word2vec and sent2vec learn these representations from context without labeled data. section 1.3.1

Once text is embedded, clustering or classification can operate on the vectors. This separates unsupervised representation learning from a typically supervised downstream task, reducing the need for labeled data. section 1.3.1

Sentence embeddings for movie reviews

A pretrained sent2vec model turns IMDB reviews into sentence vectors for a classification task. One example uses a 600-dimensional model trained on Wikipedia unigrams. section 4.2

Listing 4.3 Loading IMDB data into a NumPy array
def assemble_embedding_vectors(data):
    out = None
    for item in data:                                   #1
        vec = model.embed_sentence(" ".join(item))      #2
        if vec is not None:                             #3
            if out is not None:
                out = np.concatenate((out,vec),axis=0)
            else:
                out = vec
        else:
            pass
        
        
    return out

The function embeds each review as a sentence vector and collects the vectors into an array. section 4.2

How Transfer Learning for Natural Language Processing covers it

How deep it goes
Explains context-based vector representations and downstream use, then demonstrates pretrained sentence embeddings without deriving their training algorithm.
Examples
Uses word analogies such as man–king and woman–queen, plus sent2vec vectors for IMDB movie reviews.
What you can do after
Apply pretrained sent2vec vectors to IMDB reviews for classification.
How it connects
Connects distributional semantics and word2vec with sent2vec, transfer learning, clustering, and classification.

Also explained in

Compare how 51 books explain embedding →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Transfer Learning for Natural Language Processing. The section links point to the parts of the book it draws on.