liveBook · Manning

Semantic analysis

As explained in Natural Language Processing in Action, Second Edition

Semantic analysis is the computational interpretation of the meanings of words, phrases, or statements.

Semantic analysis interprets and stores the meaning of words, phrases, or statements instead of treating language as word or character counts. It uses structured numerical representations and statistical relationships to help resolve ambiguity without relying on brittle, exhaustive grammar rules. section 1.2.3

A practical route is to analyze term co-occurrence. Words that appear in similar documents can receive related representations, allowing an algorithm to estimate relationships such as the synonymy between “apple” and “NYC” in a corpus. section 4.1.3

From word counts to topics

A small vocabulary—cat, dog, apple, lion, NYC, and love—can be assigned TF–IDF values and combined with positive or negative weights to form petness, animalness, and cityness topic vectors. Transposing the topic matrix produces word vectors, while later SVD-based transformations derive topics from TF–IDF or BOW representations. section 4.1.3 section 4.11

Listing 4.1 Sample weights for your topics
>>> import numpy as np

>>> topic = {}
>>> tfidf = dict(list(zip('cat dog apple lion NYC love'.split(),
...     np.random.rand(6))))                    #1
>>> topic['petness'] = (.3 * tfidf['cat'] +\
...                     .3 * tfidf['dog'] +\
...                      0 * tfidf['apple'] +\
...                      0 * tfidf['lion'] -\
...                     .2 * tfidf['NYC'] +\
...                     .2 * tfidf['love'])     #2
>>> topic['animalness']  = (.1 * tfidf['cat']  +\
...                         .1 * tfidf['dog'] -\
...                         .1 * tfidf['apple'] +\
...                         .5 * tfidf['lion'] +\
...                         .1 * tfidf['NYC'] -\
...                         .1 * tfidf['love'])
>>> topic['cityness']    = ( 0 * tfidf['cat']  -\
...                         .1 * tfidf['dog'] +\
...                         .2 * tfidf['apple'] -\
...                         .1 * tfidf['lion'] +\
...                         .5 * tfidf['NYC'] +\
...                         .1 * tfidf['love'])

Inspect the executable NumPy thought experiment that combines weighted word values into topic vectors. section 4.1.3

The resulting topic vectors support semantic search: documents can be retrieved by inferred meaning rather than exact word matches. Explainable topic analysis can use LDiA, while model and pipeline choices can be compared with a hyperparameter table. section 4.11

How Natural Language Processing in Action, Second Edition covers it

How deep it goes
Explains co-occurrence, signed topic weights, vector transformations, SVD, and search applications without detailing full production pipelines.
Examples
Uses petness, animalness, and cityness vectors built from cat, dog, apple, lion, NYC, and love.
What it assumes
Assumes familiarity with token counts and TF–IDF vectors while developing intuition for topics, co-occurrence, and word vectors.
What you can do after
Apply semantic representations to compare topics and retrieve documents by meaning rather than exact word counts.
How it connects
Connects natural language processing with statistics, machine learning, TF–IDF, BOW, SVD, LDiA, topic modeling, and semantic search.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Natural Language Processing in Action, Second Edition. The section links point to the parts of the book it draws on.