A TF-IDF-to-topic transformation maps a document’s high-dimensional TF-IDF vector into a smaller topic vector. Think of it as mixing word counts into semantic colors: each topic assigns weights to vocabulary terms, then matrix multiplication combines them. section 4.1.3
Three topics from six words
For petness, animalness, and cityness, a 3×6 weight matrix connects six terms—cat, dog, apple, lion, NYC, and love—to three topics. Cat and dog receive equal petness weights of .3, while NYC receives a negative petness weight of −.2. Multiplying this matrix by a 6×1 TF-IDF vector produces a 3×1 topic vector. section 4.1.3
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 NumPy-style weighted sums that construct topic values from individual TF-IDF terms. section 4.1.3
The weights are illustrative rather than a real algorithm. A practical method would compute them from many documents, token counts, and TF-IDF vectors, including relationships such as apple and NYC. section 4.1.3
