blob: 4ea7454896ddbd645ae2e5b9e1421e3136dd3de4 [file] [log] [blame]
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Latent Dirichlet Allocation \n",
"\n",
"Latent Dirichlet Allocation (LDA) is a generative probabilistic model for natural texts. It is used in problems such as automated topic discovery, collaborative filtering, and document classification.\n",
"\n",
"In addition to an implementation of LDA, this MADlib module also provides a number of additional helper functions to interpret results of the LDA output."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/fmcquillan/anaconda/lib/python2.7/site-packages/IPython/config.py:13: ShimWarning: The `IPython.config` package has been deprecated since IPython 4.0. You should import from traitlets.config instead.\n",
" \"You should import from traitlets.config instead.\", ShimWarning)\n",
"/Users/fmcquillan/anaconda/lib/python2.7/site-packages/IPython/utils/traitlets.py:5: UserWarning: IPython.utils.traitlets has moved to a top-level traitlets package.\n",
" warn(\"IPython.utils.traitlets has moved to a top-level traitlets package.\")\n"
]
}
],
"source": [
"%load_ext sql"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"u'Connected: gpadmin@madlib'"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Greenplum Database 5.x on GCP (PM demo machine) - direct external IP access\n",
"#%sql postgresql://gpadmin@34.67.65.96:5432/madlib\n",
"\n",
"# Greenplum Database 5.x on GCP - via tunnel\n",
"%sql postgresql://gpadmin@localhost:8000/madlib\n",
" \n",
"# PostgreSQL local\n",
"#%sql postgresql://fmcquillan@localhost:5432/madlib"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1 rows affected.\n"
]
},
{
"data": {
"text/html": [
"<table>\n",
" <tr>\n",
" <th>version</th>\n",
" </tr>\n",
" <tr>\n",
" <td>MADlib version: 1.17-dev, git revision: rel/v1.16-40-gfc8af4e, cmake configuration time: Thu Nov 7 22:54:15 UTC 2019, build type: release, build system: Linux-3.10.0-957.27.2.el7.x86_64, C compiler: gcc 4.8.5, C++ compiler: g++ 4.8.5</td>\n",
" </tr>\n",
"</table>"
],
"text/plain": [
"[(u'MADlib version: 1.17-dev, git revision: rel/v1.16-40-gfc8af4e, cmake configuration time: Thu Nov 7 22:54:15 UTC 2019, build type: release, build system: Linux-3.10.0-957.27.2.el7.x86_64, C compiler: gcc 4.8.5, C++ compiler: g++ 4.8.5',)]"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"%sql select madlib.version();\n",
"#%sql select version();"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 1. Prepare documents\n",
"The examples below are short strings extracted from various Wikipedia documents. First we create a document table with one document per row:"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Done.\n",
"Done.\n",
"4 rows affected.\n",
"4 rows affected.\n"
]
},
{
"data": {
"text/html": [
"<table>\n",
" <tr>\n",
" <th>docid</th>\n",
" <th>contents</th>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>Statistical topic models are a class of Bayesian latent variable models, originally developed for analyzing the semantic content of large document corpora.</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1</td>\n",
" <td>By the late 1960s, the balance between pitching and hitting had swung in favor of the pitchers. In 1968 Carl Yastrzemski won the American League batting title with an average of just .301, the lowest in history.</td>\n",
" </tr>\n",
" <tr>\n",
" <td>2</td>\n",
" <td>Machine learning is closely related to and often overlaps with computational statistics; a discipline that also specializes in prediction-making. It has strong ties to mathematical optimization, which deliver methods, theory and application domains to the field.</td>\n",
" </tr>\n",
" <tr>\n",
" <td>3</td>\n",
" <td>California's diverse geography ranges from the Sierra Nevada in the east to the Pacific Coast in the west, from the Redwood–Douglas fir forests of the northwest, to the Mojave Desert areas in the southeast. The center of the state is dominated by the Central Valley, a major agricultural area.</td>\n",
" </tr>\n",
"</table>"
],
"text/plain": [
"[(0, u'Statistical topic models are a class of Bayesian latent variable models, originally developed for analyzing the semantic content of large document corpora.'),\n",
" (1, u'By the late 1960s, the balance between pitching and hitting had swung in favor of the pitchers. In 1968 Carl Yastrzemski won the American League batting title with an average of just .301, the lowest in history.'),\n",
" (2, u'Machine learning is closely related to and often overlaps with computational statistics; a discipline that also specializes in prediction-making. It has strong ties to mathematical optimization, which deliver methods, theory and application domains to the field.'),\n",
" (3, u\"California's diverse geography ranges from the Sierra Nevada in the east to the Pacific Coast in the west, from the Redwood\\u2013Douglas fir forests of the northwest, to the Mojave Desert areas in the southeast. The center of the state is dominated by the Central Valley, a major agricultural area.\")]"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"%%sql\n",
"DROP TABLE IF EXISTS documents;\n",
"CREATE TABLE documents(docid INT4, contents TEXT);\n",
"\n",
"INSERT INTO documents VALUES\n",
"(0, 'Statistical topic models are a class of Bayesian latent variable models, originally developed for analyzing the semantic content of large document corpora.'),\n",
"(1, 'By the late 1960s, the balance between pitching and hitting had swung in favor of the pitchers. In 1968 Carl Yastrzemski won the American League batting title with an average of just .301, the lowest in history.'),\n",
"(2, 'Machine learning is closely related to and often overlaps with computational statistics; a discipline that also specializes in prediction-making. It has strong ties to mathematical optimization, which deliver methods, theory and application domains to the field.'),\n",
"(3, 'California''s diverse geography ranges from the Sierra Nevada in the east to the Pacific Coast in the west, from the Redwood–Douglas fir forests of the northwest, to the Mojave Desert areas in the southeast. The center of the state is dominated by the Central Valley, a major agricultural area.');\n",
"\n",
"SELECT * from documents ORDER BY docid;"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You can apply stemming, stop word removal and tokenization at this point in order to prepare the documents for text processing. Depending upon your database version, various tools are available. Databases based on more recent versions of PostgreSQL may do something like: "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%%sql\n",
"SELECT tsvector_to_array(to_tsvector('english',contents)) from documents;"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In this example, we assume a database based on an older version of PostgreSQL and just perform basic punctuation removal and tokenization. The array of words is added as a new column to the documents table:"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Done.\n",
"4 rows affected.\n",
"4 rows affected.\n"
]
},
{
"data": {
"text/html": [
"<table>\n",
" <tr>\n",
" <th>docid</th>\n",
" <th>contents</th>\n",
" <th>words</th>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>Statistical topic models are a class of Bayesian latent variable models, originally developed for analyzing the semantic content of large document corpora.</td>\n",
" <td>[u'statistical', u'topic', u'models', u'are', u'a', u'class', u'of', u'bayesian', u'latent', u'variable', u'models', u'originally', u'developed', u'for', u'analyzing', u'the', u'semantic', u'content', u'of', u'large', u'document', u'corpora']</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1</td>\n",
" <td>By the late 1960s, the balance between pitching and hitting had swung in favor of the pitchers. In 1968 Carl Yastrzemski won the American League batting title with an average of just .301, the lowest in history.</td>\n",
" <td>[u'by', u'the', u'late', u'1960s', u'the', u'balance', u'between', u'pitching', u'and', u'hitting', u'had', u'swung', u'in', u'favor', u'of', u'the', u'pitchers', u'in', u'1968', u'carl', u'yastrzemski', u'won', u'the', u'american', u'league', u'batting', u'title', u'with', u'an', u'average', u'of', u'just', u'301', u'the', u'lowest', u'in', u'history']</td>\n",
" </tr>\n",
" <tr>\n",
" <td>2</td>\n",
" <td>Machine learning is closely related to and often overlaps with computational statistics; a discipline that also specializes in prediction-making. It has strong ties to mathematical optimization, which deliver methods, theory and application domains to the field.</td>\n",
" <td>[u'machine', u'learning', u'is', u'closely', u'related', u'to', u'and', u'often', u'overlaps', u'with', u'computational', u'statistics', u'a', u'discipline', u'that', u'also', u'specializes', u'in', u'prediction-making', u'it', u'has', u'strong', u'ties', u'to', u'mathematical', u'optimization', u'which', u'deliver', u'methods', u'theory', u'and', u'application', u'domains', u'to', u'the', u'field']</td>\n",
" </tr>\n",
" <tr>\n",
" <td>3</td>\n",
" <td>California's diverse geography ranges from the Sierra Nevada in the east to the Pacific Coast in the west, from the Redwood–Douglas fir forests of the northwest, to the Mojave Desert areas in the southeast. The center of the state is dominated by the Central Valley, a major agricultural area.</td>\n",
" <td>[u'californias', u'diverse', u'geography', u'ranges', u'from', u'the', u'sierra', u'nevada', u'in', u'the', u'east', u'to', u'the', u'pacific', u'coast', u'in', u'the', u'west', u'from', u'the', u'redwood\\u2013douglas', u'fir', u'forests', u'of', u'the', u'northwest', u'to', u'the', u'mojave', u'desert', u'areas', u'in', u'the', u'southeast', u'the', u'center', u'of', u'the', u'state', u'is', u'dominated', u'by', u'the', u'central', u'valley', u'a', u'major', u'agricultural', u'area']</td>\n",
" </tr>\n",
"</table>"
],
"text/plain": [
"[(0, u'Statistical topic models are a class of Bayesian latent variable models, originally developed for analyzing the semantic content of large document corpora.', [u'statistical', u'topic', u'models', u'are', u'a', u'class', u'of', u'bayesian', u'latent', u'variable', u'models', u'originally', u'developed', u'for', u'analyzing', u'the', u'semantic', u'content', u'of', u'large', u'document', u'corpora']),\n",
" (1, u'By the late 1960s, the balance between pitching and hitting had swung in favor of the pitchers. In 1968 Carl Yastrzemski won the American League batting title with an average of just .301, the lowest in history.', [u'by', u'the', u'late', u'1960s', u'the', u'balance', u'between', u'pitching', u'and', u'hitting', u'had', u'swung', u'in', u'favor', u'of', u'the', u'pitchers', u'in', u'1968', u'carl', u'yastrzemski', u'won', u'the', u'american', u'league', u'batting', u'title', u'with', u'an', u'average', u'of', u'just', u'301', u'the', u'lowest', u'in', u'history']),\n",
" (2, u'Machine learning is closely related to and often overlaps with computational statistics; a discipline that also specializes in prediction-making. It has strong ties to mathematical optimization, which deliver methods, theory and application domains to the field.', [u'machine', u'learning', u'is', u'closely', u'related', u'to', u'and', u'often', u'overlaps', u'with', u'computational', u'statistics', u'a', u'discipline', u'that', u'also', u'specializes', u'in', u'prediction-making', u'it', u'has', u'strong', u'ties', u'to', u'mathematical', u'optimization', u'which', u'deliver', u'methods', u'theory', u'and', u'application', u'domains', u'to', u'the', u'field']),\n",
" (3, u\"California's diverse geography ranges from the Sierra Nevada in the east to the Pacific Coast in the west, from the Redwood\\u2013Douglas fir forests of the northwest, to the Mojave Desert areas in the southeast. The center of the state is dominated by the Central Valley, a major agricultural area.\", [u'californias', u'diverse', u'geography', u'ranges', u'from', u'the', u'sierra', u'nevada', u'in', u'the', u'east', u'to', u'the', u'pacific', u'coast', u'in', u'the', u'west', u'from', u'the', u'redwood\\u2013douglas', u'fir', u'forests', u'of', u'the', u'northwest', u'to', u'the', u'mojave', u'desert', u'areas', u'in', u'the', u'southeast', u'the', u'center', u'of', u'the', u'state', u'is', u'dominated', u'by', u'the', u'central', u'valley', u'a', u'major', u'agricultural', u'area'])]"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"%%sql\n",
"ALTER TABLE documents ADD COLUMN words TEXT[];\n",
"\n",
"UPDATE documents SET words = \n",
" regexp_split_to_array(lower(\n",
" regexp_replace(contents, E'[,.;\\']','', 'g')\n",
" ), E'[\\\\s+]');\n",
" \n",
"SELECT * FROM documents ORDER BY docid;"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 2. Term frequency\n",
"Build a word count table by extracting the words and building a histogram for each document using the term_frequency() function."
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Done.\n",
"1 rows affected.\n",
"20 rows affected.\n"
]
},
{
"data": {
"text/html": [
"<table>\n",
" <tr>\n",
" <th>docid</th>\n",
" <th>wordid</th>\n",
" <th>count</th>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>17</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>11</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>95</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>90</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>85</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>68</td>\n",
" <td>2</td>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>54</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>42</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>35</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>28</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>8</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>3</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>97</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>80</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>71</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>64</td>\n",
" <td>2</td>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>56</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>32</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>29</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>24</td>\n",
" <td>1</td>\n",
" </tr>\n",
"</table>"
],
"text/plain": [
"[(0, 17, 1),\n",
" (0, 11, 1),\n",
" (0, 95, 1),\n",
" (0, 90, 1),\n",
" (0, 85, 1),\n",
" (0, 68, 2),\n",
" (0, 54, 1),\n",
" (0, 42, 1),\n",
" (0, 35, 1),\n",
" (0, 28, 1),\n",
" (0, 8, 1),\n",
" (0, 3, 1),\n",
" (0, 97, 1),\n",
" (0, 80, 1),\n",
" (0, 71, 1),\n",
" (0, 64, 2),\n",
" (0, 56, 1),\n",
" (0, 32, 1),\n",
" (0, 29, 1),\n",
" (0, 24, 1)]"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"%%sql\n",
"DROP TABLE IF EXISTS documents_tf, documents_tf_vocabulary;\n",
"\n",
"SELECT madlib.term_frequency('documents', -- input table\n",
" 'docid', -- document id column\n",
" 'words', -- vector of words in document\n",
" 'documents_tf', -- output documents table with term frequency\n",
" TRUE); -- TRUE to created vocabulary table\n",
"\n",
"SELECT * FROM documents_tf ORDER BY docid LIMIT 20;"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Here is the associated vocabulary table. Note that wordid starts at 0:"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"scrolled": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"20 rows affected.\n"
]
},
{
"data": {
"text/html": [
"<table>\n",
" <tr>\n",
" <th>wordid</th>\n",
" <th>word</th>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>1960s</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1</td>\n",
" <td>1968</td>\n",
" </tr>\n",
" <tr>\n",
" <td>2</td>\n",
" <td>301</td>\n",
" </tr>\n",
" <tr>\n",
" <td>3</td>\n",
" <td>a</td>\n",
" </tr>\n",
" <tr>\n",
" <td>4</td>\n",
" <td>agricultural</td>\n",
" </tr>\n",
" <tr>\n",
" <td>5</td>\n",
" <td>also</td>\n",
" </tr>\n",
" <tr>\n",
" <td>6</td>\n",
" <td>american</td>\n",
" </tr>\n",
" <tr>\n",
" <td>7</td>\n",
" <td>an</td>\n",
" </tr>\n",
" <tr>\n",
" <td>8</td>\n",
" <td>analyzing</td>\n",
" </tr>\n",
" <tr>\n",
" <td>9</td>\n",
" <td>and</td>\n",
" </tr>\n",
" <tr>\n",
" <td>10</td>\n",
" <td>application</td>\n",
" </tr>\n",
" <tr>\n",
" <td>11</td>\n",
" <td>are</td>\n",
" </tr>\n",
" <tr>\n",
" <td>12</td>\n",
" <td>area</td>\n",
" </tr>\n",
" <tr>\n",
" <td>13</td>\n",
" <td>areas</td>\n",
" </tr>\n",
" <tr>\n",
" <td>14</td>\n",
" <td>average</td>\n",
" </tr>\n",
" <tr>\n",
" <td>15</td>\n",
" <td>balance</td>\n",
" </tr>\n",
" <tr>\n",
" <td>16</td>\n",
" <td>batting</td>\n",
" </tr>\n",
" <tr>\n",
" <td>17</td>\n",
" <td>bayesian</td>\n",
" </tr>\n",
" <tr>\n",
" <td>18</td>\n",
" <td>between</td>\n",
" </tr>\n",
" <tr>\n",
" <td>19</td>\n",
" <td>by</td>\n",
" </tr>\n",
"</table>"
],
"text/plain": [
"[(0, u'1960s'),\n",
" (1, u'1968'),\n",
" (2, u'301'),\n",
" (3, u'a'),\n",
" (4, u'agricultural'),\n",
" (5, u'also'),\n",
" (6, u'american'),\n",
" (7, u'an'),\n",
" (8, u'analyzing'),\n",
" (9, u'and'),\n",
" (10, u'application'),\n",
" (11, u'are'),\n",
" (12, u'area'),\n",
" (13, u'areas'),\n",
" (14, u'average'),\n",
" (15, u'balance'),\n",
" (16, u'batting'),\n",
" (17, u'bayesian'),\n",
" (18, u'between'),\n",
" (19, u'by')]"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"%%sql\n",
"SELECT * FROM documents_tf_vocabulary ORDER BY wordid LIMIT 20;"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The total number of words in the vocabulary across all documents is:"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1 rows affected.\n"
]
},
{
"data": {
"text/html": [
"<table>\n",
" <tr>\n",
" <th>count</th>\n",
" </tr>\n",
" <tr>\n",
" <td>103</td>\n",
" </tr>\n",
"</table>"
],
"text/plain": [
"[(103L,)]"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"%%sql\n",
"SELECT COUNT(*) FROM documents_tf_vocabulary;"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 3. Train LDA model\n",
"For Dirichlet priors we use initial rule-of-thumb values of 50/(number of topics) for alpha and 0.01 for beta.\n",
"\n",
"Reminder that column names for docid, wordid, and count are currently fixed, so you must use these exact names in the input table. After a successful run of the LDA training function two tables are generated, one for storing the learned model and the other for storing the output data table."
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Done.\n",
"2 rows affected.\n",
"4 rows affected.\n"
]
},
{
"data": {
"text/html": [
"<table>\n",
" <tr>\n",
" <th>docid</th>\n",
" <th>wordcount</th>\n",
" <th>words</th>\n",
" <th>counts</th>\n",
" <th>topic_count</th>\n",
" <th>topic_assignment</th>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>22</td>\n",
" <td>[24, 17, 11, 95, 90, 85, 68, 54, 42, 35, 28, 8, 3, 97, 80, 71, 64, 56, 32, 29]</td>\n",
" <td>[1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1]</td>\n",
" <td>[3, 5, 8, 5, 1]</td>\n",
" <td>[3, 2, 1, 3, 0, 0, 3, 3, 1, 2, 1, 4, 2, 0, 1, 2, 2, 2, 2, 1, 2, 3]</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1</td>\n",
" <td>37</td>\n",
" <td>[1, 50, 49, 46, 19, 16, 14, 9, 7, 0, 90, 68, 57, 102, 101, 100, 93, 88, 75, 74, 59, 55, 53, 48, 39, 21, 18, 15, 6, 2]</td>\n",
" <td>[1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 5, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]</td>\n",
" <td>[11, 7, 2, 11, 6]</td>\n",
" <td>[0, 0, 0, 0, 1, 3, 2, 1, 1, 1, 3, 1, 0, 0, 0, 4, 4, 3, 3, 4, 4, 2, 3, 3, 1, 1, 3, 3, 3, 3, 0, 4, 3, 0, 4, 0, 0]</td>\n",
" </tr>\n",
" <tr>\n",
" <td>2</td>\n",
" <td>36</td>\n",
" <td>[10, 27, 33, 40, 47, 51, 58, 62, 63, 69, 72, 83, 100, 99, 94, 92, 91, 90, 89, 87, 86, 79, 76, 70, 60, 52, 50, 36, 30, 25, 9, 5, 3]</td>\n",
" <td>[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1]</td>\n",
" <td>[9, 12, 5, 5, 5]</td>\n",
" <td>[0, 0, 1, 4, 3, 4, 3, 3, 2, 2, 3, 2, 0, 1, 0, 0, 0, 2, 1, 4, 1, 1, 1, 4, 4, 2, 1, 3, 0, 1, 1, 1, 1, 1, 0, 0]</td>\n",
" </tr>\n",
" <tr>\n",
" <td>3</td>\n",
" <td>49</td>\n",
" <td>[77, 78, 81, 82, 67, 65, 51, 45, 44, 43, 34, 26, 13, 98, 96, 94, 90, 84, 73, 68, 66, 61, 50, 41, 38, 37, 31, 23, 22, 20, 19, 12, 4, 3]</td>\n",
" <td>[1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 11, 1, 1, 2, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]</td>\n",
" <td>[12, 4, 11, 3, 19]</td>\n",
" <td>[2, 1, 3, 4, 1, 4, 0, 0, 4, 4, 4, 2, 1, 4, 2, 4, 0, 1, 4, 4, 0, 0, 4, 4, 4, 4, 0, 4, 4, 4, 4, 3, 3, 2, 2, 0, 0, 0, 2, 0, 2, 2, 0, 2, 4, 2, 2, 4, 0]</td>\n",
" </tr>\n",
"</table>"
],
"text/plain": [
"[(0, 22, [24, 17, 11, 95, 90, 85, 68, 54, 42, 35, 28, 8, 3, 97, 80, 71, 64, 56, 32, 29], [1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1], [3, 5, 8, 5, 1], [3, 2, 1, 3, 0, 0, 3, 3, 1, 2, 1, 4, 2, 0, 1, 2, 2, 2, 2, 1, 2, 3]),\n",
" (1, 37, [1, 50, 49, 46, 19, 16, 14, 9, 7, 0, 90, 68, 57, 102, 101, 100, 93, 88, 75, 74, 59, 55, 53, 48, 39, 21, 18, 15, 6, 2], [1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 5, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [11, 7, 2, 11, 6], [0, 0, 0, 0, 1, 3, 2, 1, 1, 1, 3, 1, 0, 0, 0, 4, 4, 3, 3, 4, 4, 2, 3, 3, 1, 1, 3, 3, 3, 3, 0, 4, 3, 0, 4, 0, 0]),\n",
" (2, 36, [10, 27, 33, 40, 47, 51, 58, 62, 63, 69, 72, 83, 100, 99, 94, 92, 91, 90, 89, 87, 86, 79, 76, 70, 60, 52, 50, 36, 30, 25, 9, 5, 3], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1], [9, 12, 5, 5, 5], [0, 0, 1, 4, 3, 4, 3, 3, 2, 2, 3, 2, 0, 1, 0, 0, 0, 2, 1, 4, 1, 1, 1, 4, 4, 2, 1, 3, 0, 1, 1, 1, 1, 1, 0, 0]),\n",
" (3, 49, [77, 78, 81, 82, 67, 65, 51, 45, 44, 43, 34, 26, 13, 98, 96, 94, 90, 84, 73, 68, 66, 61, 50, 41, 38, 37, 31, 23, 22, 20, 19, 12, 4, 3], [1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 11, 1, 1, 2, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [12, 4, 11, 3, 19], [2, 1, 3, 4, 1, 4, 0, 0, 4, 4, 4, 2, 1, 4, 2, 4, 0, 1, 4, 4, 0, 0, 4, 4, 4, 4, 0, 4, 4, 4, 4, 3, 3, 2, 2, 0, 0, 0, 2, 0, 2, 2, 0, 2, 4, 2, 2, 4, 0])]"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"%%sql\n",
"DROP TABLE IF EXISTS lda_model, lda_output_data;\n",
"\n",
"SELECT madlib.lda_train( 'documents_tf', -- documents table in the form of term frequency\n",
" 'lda_model', -- model table created by LDA training (not human readable)\n",
" 'lda_output_data', -- readable output data table \n",
" 103, -- vocabulary size\n",
" 5, -- number of topics\n",
" 10, -- number of iterations\n",
" 5, -- Dirichlet prior for the per-doc topic multinomial (alpha)\n",
" 0.01 -- Dirichlet prior for the per-topic word multinomial (beta)\n",
" );\n",
"\n",
"SELECT * FROM lda_output_data ORDER BY docid;"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1 rows affected.\n"
]
},
{
"data": {
"text/html": [
"<table>\n",
" <tr>\n",
" <th>voc_size</th>\n",
" <th>topic_num</th>\n",
" <th>alpha</th>\n",
" <th>beta</th>\n",
" <th>num_iterations</th>\n",
" <th>perplexity</th>\n",
" <th>perplexity_iters</th>\n",
" </tr>\n",
" <tr>\n",
" <td>103</td>\n",
" <td>5</td>\n",
" <td>5.0</td>\n",
" <td>0.01</td>\n",
" <td>10</td>\n",
" <td>None</td>\n",
" <td>None</td>\n",
" </tr>\n",
"</table>"
],
"text/plain": [
"[(103, 5, 5.0, 0.01, 10, None, None)]"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"%%sql\n",
"SELECT voc_size, topic_num, alpha, beta, num_iterations, perplexity, perplexity_iters from lda_model;"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 4. Helper functions on learned model \n",
"\n",
"First, we get topic description by top-k words. These are the k words with the highest probability for the topic.\n",
"\n",
"Note that if there are ties in probability, more than k words may actually be reported for each topic. Also note that topicid starts at 0."
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Done.\n",
"1 rows affected.\n",
"40 rows affected.\n"
]
},
{
"data": {
"text/html": [
"<table>\n",
" <tr>\n",
" <th>topicid</th>\n",
" <th>wordid</th>\n",
" <th>prob</th>\n",
" <th>word</th>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>50</td>\n",
" <td>0.194560088815</td>\n",
" <td>in</td>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>90</td>\n",
" <td>0.194560088815</td>\n",
" <td>the</td>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>94</td>\n",
" <td>0.111296142104</td>\n",
" <td>to</td>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>3</td>\n",
" <td>0.0835414932001</td>\n",
" <td>a</td>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>85</td>\n",
" <td>0.0280321953927</td>\n",
" <td>statistical</td>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>5</td>\n",
" <td>0.0280321953927</td>\n",
" <td>also</td>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>0.0280321953927</td>\n",
" <td>1968</td>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>18</td>\n",
" <td>0.0280321953927</td>\n",
" <td>between</td>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>2</td>\n",
" <td>0.0280321953927</td>\n",
" <td>301</td>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>38</td>\n",
" <td>0.0280321953927</td>\n",
" <td>east</td>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>100</td>\n",
" <td>0.0280321953927</td>\n",
" <td>with</td>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>10</td>\n",
" <td>0.0280321953927</td>\n",
" <td>application</td>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>48</td>\n",
" <td>0.0280321953927</td>\n",
" <td>history</td>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>6</td>\n",
" <td>0.0280321953927</td>\n",
" <td>american</td>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>45</td>\n",
" <td>0.0280321953927</td>\n",
" <td>geography</td>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>51</td>\n",
" <td>0.0280321953927</td>\n",
" <td>is</td>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>23</td>\n",
" <td>0.0280321953927</td>\n",
" <td>central</td>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>27</td>\n",
" <td>0.0280321953927</td>\n",
" <td>computational</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1</td>\n",
" <td>9</td>\n",
" <td>0.103685842232</td>\n",
" <td>and</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1</td>\n",
" <td>49</td>\n",
" <td>0.0347915949018</td>\n",
" <td>hitting</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1</td>\n",
" <td>97</td>\n",
" <td>0.0347915949018</td>\n",
" <td>variable</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1</td>\n",
" <td>91</td>\n",
" <td>0.0347915949018</td>\n",
" <td>theory</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1</td>\n",
" <td>25</td>\n",
" <td>0.0347915949018</td>\n",
" <td>closely</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1</td>\n",
" <td>89</td>\n",
" <td>0.0347915949018</td>\n",
" <td>that</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1</td>\n",
" <td>87</td>\n",
" <td>0.0347915949018</td>\n",
" <td>strong</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>0.0347915949018</td>\n",
" <td>1960s</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1</td>\n",
" <td>60</td>\n",
" <td>0.0347915949018</td>\n",
" <td>machine</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1</td>\n",
" <td>88</td>\n",
" <td>0.0347915949018</td>\n",
" <td>swung</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1</td>\n",
" <td>56</td>\n",
" <td>0.0347915949018</td>\n",
" <td>latent</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1</td>\n",
" <td>78</td>\n",
" <td>0.0347915949018</td>\n",
" <td>redwood–douglas</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1</td>\n",
" <td>54</td>\n",
" <td>0.0347915949018</td>\n",
" <td>large</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1</td>\n",
" <td>16</td>\n",
" <td>0.0347915949018</td>\n",
" <td>batting</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1</td>\n",
" <td>86</td>\n",
" <td>0.0347915949018</td>\n",
" <td>statistics</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1</td>\n",
" <td>14</td>\n",
" <td>0.0347915949018</td>\n",
" <td>average</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1</td>\n",
" <td>36</td>\n",
" <td>0.0347915949018</td>\n",
" <td>domains</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1</td>\n",
" <td>99</td>\n",
" <td>0.0347915949018</td>\n",
" <td>which</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1</td>\n",
" <td>11</td>\n",
" <td>0.0347915949018</td>\n",
" <td>are</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1</td>\n",
" <td>35</td>\n",
" <td>0.0347915949018</td>\n",
" <td>document</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1</td>\n",
" <td>67</td>\n",
" <td>0.0347915949018</td>\n",
" <td>northwest</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1</td>\n",
" <td>26</td>\n",
" <td>0.0347915949018</td>\n",
" <td>coast</td>\n",
" </tr>\n",
"</table>"
],
"text/plain": [
"[(0, 50, 0.194560088814876, u'in'),\n",
" (0, 90, 0.194560088814876, u'the'),\n",
" (0, 94, 0.111296142103802, u'to'),\n",
" (0, 3, 0.083541493200111, u'a'),\n",
" (0, 85, 0.0280321953927283, u'statistical'),\n",
" (0, 5, 0.0280321953927283, u'also'),\n",
" (0, 1, 0.0280321953927283, u'1968'),\n",
" (0, 18, 0.0280321953927283, u'between'),\n",
" (0, 2, 0.0280321953927283, u'301'),\n",
" (0, 38, 0.0280321953927283, u'east'),\n",
" (0, 100, 0.0280321953927283, u'with'),\n",
" (0, 10, 0.0280321953927283, u'application'),\n",
" (0, 48, 0.0280321953927283, u'history'),\n",
" (0, 6, 0.0280321953927283, u'american'),\n",
" (0, 45, 0.0280321953927283, u'geography'),\n",
" (0, 51, 0.0280321953927283, u'is'),\n",
" (0, 23, 0.0280321953927283, u'central'),\n",
" (0, 27, 0.0280321953927283, u'computational'),\n",
" (1, 9, 0.103685842232174, u'and'),\n",
" (1, 49, 0.0347915949018257, u'hitting'),\n",
" (1, 97, 0.0347915949018257, u'variable'),\n",
" (1, 91, 0.0347915949018257, u'theory'),\n",
" (1, 25, 0.0347915949018257, u'closely'),\n",
" (1, 89, 0.0347915949018257, u'that'),\n",
" (1, 87, 0.0347915949018257, u'strong'),\n",
" (1, 0, 0.0347915949018257, u'1960s'),\n",
" (1, 60, 0.0347915949018257, u'machine'),\n",
" (1, 88, 0.0347915949018257, u'swung'),\n",
" (1, 56, 0.0347915949018257, u'latent'),\n",
" (1, 78, 0.0347915949018257, u'redwood\\u2013douglas'),\n",
" (1, 54, 0.0347915949018257, u'large'),\n",
" (1, 16, 0.0347915949018257, u'batting'),\n",
" (1, 86, 0.0347915949018257, u'statistics'),\n",
" (1, 14, 0.0347915949018257, u'average'),\n",
" (1, 36, 0.0347915949018257, u'domains'),\n",
" (1, 99, 0.0347915949018257, u'which'),\n",
" (1, 11, 0.0347915949018257, u'are'),\n",
" (1, 35, 0.0347915949018257, u'document'),\n",
" (1, 67, 0.0347915949018257, u'northwest'),\n",
" (1, 26, 0.0347915949018257, u'coast')]"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"%%sql\n",
"DROP TABLE IF EXISTS helper_output_table;\n",
"\n",
"SELECT madlib.lda_get_topic_desc( 'lda_model', -- LDA model generated in training\n",
" 'documents_tf_vocabulary', -- vocabulary table that maps wordid to word\n",
" 'helper_output_table', -- output table for per-topic descriptions\n",
" 5); -- k: number of top words for each topic\n",
"\n",
"SELECT * FROM helper_output_table ORDER BY topicid, prob DESC LIMIT 40;"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Get the per-word topic counts. This mapping shows how many times a given word is assigned to a topic. E.g., wordid 3 is assigned to topicid 0 three times. "
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Done.\n",
"1 rows affected.\n",
"20 rows affected.\n"
]
},
{
"data": {
"text/html": [
"<table>\n",
" <tr>\n",
" <th>wordid</th>\n",
" <th>topic_count</th>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>[0, 1, 0, 0, 0]</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1</td>\n",
" <td>[1, 0, 0, 0, 0]</td>\n",
" </tr>\n",
" <tr>\n",
" <td>2</td>\n",
" <td>[1, 0, 0, 0, 0]</td>\n",
" </tr>\n",
" <tr>\n",
" <td>3</td>\n",
" <td>[3, 0, 0, 0, 0]</td>\n",
" </tr>\n",
" <tr>\n",
" <td>4</td>\n",
" <td>[0, 0, 0, 0, 1]</td>\n",
" </tr>\n",
" <tr>\n",
" <td>5</td>\n",
" <td>[1, 0, 0, 0, 0]</td>\n",
" </tr>\n",
" <tr>\n",
" <td>6</td>\n",
" <td>[1, 0, 0, 0, 0]</td>\n",
" </tr>\n",
" <tr>\n",
" <td>7</td>\n",
" <td>[0, 0, 0, 1, 0]</td>\n",
" </tr>\n",
" <tr>\n",
" <td>8</td>\n",
" <td>[0, 0, 1, 0, 0]</td>\n",
" </tr>\n",
" <tr>\n",
" <td>9</td>\n",
" <td>[0, 3, 0, 0, 0]</td>\n",
" </tr>\n",
" <tr>\n",
" <td>10</td>\n",
" <td>[1, 0, 0, 0, 0]</td>\n",
" </tr>\n",
" <tr>\n",
" <td>11</td>\n",
" <td>[0, 1, 0, 0, 0]</td>\n",
" </tr>\n",
" <tr>\n",
" <td>12</td>\n",
" <td>[0, 0, 1, 0, 0]</td>\n",
" </tr>\n",
" <tr>\n",
" <td>13</td>\n",
" <td>[0, 0, 0, 0, 1]</td>\n",
" </tr>\n",
" <tr>\n",
" <td>14</td>\n",
" <td>[0, 1, 0, 0, 0]</td>\n",
" </tr>\n",
" <tr>\n",
" <td>15</td>\n",
" <td>[0, 0, 0, 0, 1]</td>\n",
" </tr>\n",
" <tr>\n",
" <td>16</td>\n",
" <td>[0, 1, 0, 0, 0]</td>\n",
" </tr>\n",
" <tr>\n",
" <td>17</td>\n",
" <td>[0, 0, 1, 0, 0]</td>\n",
" </tr>\n",
" <tr>\n",
" <td>18</td>\n",
" <td>[1, 0, 0, 0, 0]</td>\n",
" </tr>\n",
" <tr>\n",
" <td>19</td>\n",
" <td>[0, 0, 2, 0, 0]</td>\n",
" </tr>\n",
"</table>"
],
"text/plain": [
"[(0, [0, 1, 0, 0, 0]),\n",
" (1, [1, 0, 0, 0, 0]),\n",
" (2, [1, 0, 0, 0, 0]),\n",
" (3, [3, 0, 0, 0, 0]),\n",
" (4, [0, 0, 0, 0, 1]),\n",
" (5, [1, 0, 0, 0, 0]),\n",
" (6, [1, 0, 0, 0, 0]),\n",
" (7, [0, 0, 0, 1, 0]),\n",
" (8, [0, 0, 1, 0, 0]),\n",
" (9, [0, 3, 0, 0, 0]),\n",
" (10, [1, 0, 0, 0, 0]),\n",
" (11, [0, 1, 0, 0, 0]),\n",
" (12, [0, 0, 1, 0, 0]),\n",
" (13, [0, 0, 0, 0, 1]),\n",
" (14, [0, 1, 0, 0, 0]),\n",
" (15, [0, 0, 0, 0, 1]),\n",
" (16, [0, 1, 0, 0, 0]),\n",
" (17, [0, 0, 1, 0, 0]),\n",
" (18, [1, 0, 0, 0, 0]),\n",
" (19, [0, 0, 2, 0, 0])]"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"%%sql\n",
"DROP TABLE IF EXISTS helper_output_table;\n",
"\n",
"SELECT madlib.lda_get_word_topic_count( 'lda_model', -- LDA model generated in training\n",
" 'helper_output_table'); -- output table for per-word topic counts\n",
"\n",
"SELECT * FROM helper_output_table ORDER BY wordid LIMIT 20;"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Get the per-topic word counts. This mapping shows which words are associated with each topic by frequency."
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Done.\n",
"1 rows affected.\n",
"5 rows affected.\n"
]
},
{
"data": {
"text/html": [
"<table>\n",
" <tr>\n",
" <th>topicid</th>\n",
" <th>word_count</th>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>[0, 1, 1, 3, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0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, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 11, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1])]"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"%%sql\n",
"DROP TABLE IF EXISTS helper_output_table;\n",
"\n",
"SELECT madlib.lda_get_topic_word_count( 'lda_model',\n",
" 'helper_output_table');\n",
"\n",
"SELECT * FROM helper_output_table ORDER BY topicid;"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Get the per-document word to topic mapping:"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Done.\n",
"1 rows affected.\n",
"40 rows affected.\n"
]
},
{
"data": {
"text/html": [
"<table>\n",
" <tr>\n",
" <th>docid</th>\n",
" <th>wordid</th>\n",
" <th>topicid</th>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>56</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>54</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>42</td>\n",
" <td>2</td>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>35</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>32</td>\n",
" <td>2</td>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>29</td>\n",
" <td>3</td>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>28</td>\n",
" <td>4</td>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>24</td>\n",
" <td>3</td>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>17</td>\n",
" <td>2</td>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>11</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>8</td>\n",
" <td>2</td>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>3</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>97</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>95</td>\n",
" <td>3</td>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>90</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>85</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>80</td>\n",
" <td>2</td>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>71</td>\n",
" <td>2</td>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>68</td>\n",
" <td>3</td>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>64</td>\n",
" <td>2</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1</td>\n",
" <td>6</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1</td>\n",
" <td>2</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1</td>\n",
" <td>102</td>\n",
" <td>4</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1</td>\n",
" <td>101</td>\n",
" <td>2</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1</td>\n",
" <td>100</td>\n",
" <td>3</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1</td>\n",
" <td>93</td>\n",
" <td>3</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1</td>\n",
" <td>90</td>\n",
" <td>4</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1</td>\n",
" <td>90</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1</td>\n",
" <td>88</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1</td>\n",
" <td>75</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1</td>\n",
" <td>74</td>\n",
" <td>3</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1</td>\n",
" <td>68</td>\n",
" <td>3</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1</td>\n",
" <td>59</td>\n",
" <td>3</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1</td>\n",
" <td>57</td>\n",
" <td>4</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1</td>\n",
" <td>55</td>\n",
" <td>3</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1</td>\n",
" <td>53</td>\n",
" <td>3</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1</td>\n",
" <td>50</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1</td>\n",
" <td>49</td>\n",
" <td>1</td>\n",
" </tr>\n",
"</table>"
],
"text/plain": [
"[(0, 56, 1),\n",
" (0, 54, 1),\n",
" (0, 42, 2),\n",
" (0, 35, 1),\n",
" (0, 32, 2),\n",
" (0, 29, 3),\n",
" (0, 28, 4),\n",
" (0, 24, 3),\n",
" (0, 17, 2),\n",
" (0, 11, 1),\n",
" (0, 8, 2),\n",
" (0, 3, 0),\n",
" (0, 97, 1),\n",
" (0, 95, 3),\n",
" (0, 90, 0),\n",
" (0, 85, 0),\n",
" (0, 80, 2),\n",
" (0, 71, 2),\n",
" (0, 68, 3),\n",
" (0, 64, 2),\n",
" (1, 6, 0),\n",
" (1, 2, 0),\n",
" (1, 1, 0),\n",
" (1, 0, 1),\n",
" (1, 102, 4),\n",
" (1, 101, 2),\n",
" (1, 100, 3),\n",
" (1, 93, 3),\n",
" (1, 90, 4),\n",
" (1, 90, 0),\n",
" (1, 88, 1),\n",
" (1, 75, 1),\n",
" (1, 74, 3),\n",
" (1, 68, 3),\n",
" (1, 59, 3),\n",
" (1, 57, 4),\n",
" (1, 55, 3),\n",
" (1, 53, 3),\n",
" (1, 50, 0),\n",
" (1, 49, 1)]"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"%%sql\n",
"DROP TABLE IF EXISTS helper_output_table;\n",
"\n",
"SELECT madlib.lda_get_word_topic_mapping('lda_output_data',\n",
" 'helper_output_table');\n",
"\n",
"SELECT * FROM helper_output_table ORDER BY docid LIMIT 40;"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 6. Predict\n",
"Use a learned LDA model for prediction (that is, to label new documents). In this example, we use the same input table as we used to train, just for demonstration purpose. Normally, the test document is a new one that we want to predict on."
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Done.\n",
"1 rows affected.\n",
"4 rows affected.\n"
]
},
{
"data": {
"text/html": [
"<table>\n",
" <tr>\n",
" <th>docid</th>\n",
" <th>wordcount</th>\n",
" <th>words</th>\n",
" <th>counts</th>\n",
" <th>topic_count</th>\n",
" <th>topic_assignment</th>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>22</td>\n",
" <td>[24, 17, 11, 95, 90, 85, 68, 54, 42, 35, 28, 8, 3, 97, 80, 71, 64, 56, 32, 29]</td>\n",
" <td>[1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1]</td>\n",
" <td>[0, 0, 1, 19, 2]</td>\n",
" <td>[3, 3, 3, 3, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 3, 3, 2, 3, 3, 3, 3]</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1</td>\n",
" <td>37</td>\n",
" <td>[1, 50, 49, 46, 19, 16, 14, 9, 7, 0, 90, 68, 57, 102, 101, 100, 93, 88, 75, 74, 59, 55, 53, 48, 39, 21, 18, 15, 6, 2]</td>\n",
" <td>[1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 5, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]</td>\n",
" <td>[9, 1, 3, 3, 21]</td>\n",
" <td>[4, 0, 0, 0, 4, 4, 2, 0, 0, 1, 4, 4, 4, 4, 0, 4, 4, 3, 3, 2, 4, 4, 4, 0, 0, 0, 4, 4, 4, 4, 4, 3, 4, 4, 2, 4, 4]</td>\n",
" </tr>\n",
" <tr>\n",
" <td>2</td>\n",
" <td>36</td>\n",
" <td>[10, 27, 33, 40, 47, 51, 58, 62, 63, 69, 72, 83, 100, 99, 94, 92, 91, 90, 89, 87, 86, 79, 76, 70, 60, 52, 50, 36, 30, 25, 9, 5, 3]</td>\n",
" <td>[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1]</td>\n",
" <td>[9, 5, 0, 20, 2]</td>\n",
" <td>[3, 3, 3, 3, 3, 4, 0, 3, 3, 0, 3, 3, 0, 3, 1, 0, 0, 0, 3, 4, 3, 3, 3, 1, 1, 0, 3, 3, 0, 3, 3, 3, 1, 1, 3, 0]</td>\n",
" </tr>\n",
" <tr>\n",
" <td>3</td>\n",
" <td>49</td>\n",
" <td>[77, 78, 81, 82, 67, 65, 51, 45, 44, 43, 34, 26, 13, 98, 96, 94, 90, 84, 73, 68, 66, 61, 50, 41, 38, 37, 31, 23, 22, 20, 19, 12, 4, 3]</td>\n",
" <td>[1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 11, 1, 1, 2, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]</td>\n",
" <td>[17, 1, 1, 8, 22]</td>\n",
" <td>[3, 0, 4, 4, 3, 0, 4, 4, 4, 3, 4, 4, 4, 4, 0, 2, 1, 0, 0, 0, 4, 4, 0, 0, 0, 4, 4, 4, 4, 0, 4, 3, 3, 4, 3, 0, 0, 0, 3, 4, 4, 3, 4, 0, 4, 0, 0, 4, 0]</td>\n",
" </tr>\n",
"</table>"
],
"text/plain": [
"[(0, 22, [24, 17, 11, 95, 90, 85, 68, 54, 42, 35, 28, 8, 3, 97, 80, 71, 64, 56, 32, 29], [1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1], [0, 0, 1, 19, 2], [3, 3, 3, 3, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 3, 3, 2, 3, 3, 3, 3]),\n",
" (1, 37, [1, 50, 49, 46, 19, 16, 14, 9, 7, 0, 90, 68, 57, 102, 101, 100, 93, 88, 75, 74, 59, 55, 53, 48, 39, 21, 18, 15, 6, 2], [1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 5, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [9, 1, 3, 3, 21], [4, 0, 0, 0, 4, 4, 2, 0, 0, 1, 4, 4, 4, 4, 0, 4, 4, 3, 3, 2, 4, 4, 4, 0, 0, 0, 4, 4, 4, 4, 4, 3, 4, 4, 2, 4, 4]),\n",
" (2, 36, [10, 27, 33, 40, 47, 51, 58, 62, 63, 69, 72, 83, 100, 99, 94, 92, 91, 90, 89, 87, 86, 79, 76, 70, 60, 52, 50, 36, 30, 25, 9, 5, 3], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1], [9, 5, 0, 20, 2], [3, 3, 3, 3, 3, 4, 0, 3, 3, 0, 3, 3, 0, 3, 1, 0, 0, 0, 3, 4, 3, 3, 3, 1, 1, 0, 3, 3, 0, 3, 3, 3, 1, 1, 3, 0]),\n",
" (3, 49, [77, 78, 81, 82, 67, 65, 51, 45, 44, 43, 34, 26, 13, 98, 96, 94, 90, 84, 73, 68, 66, 61, 50, 41, 38, 37, 31, 23, 22, 20, 19, 12, 4, 3], [1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 11, 1, 1, 2, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [17, 1, 1, 8, 22], [3, 0, 4, 4, 3, 0, 4, 4, 4, 3, 4, 4, 4, 4, 0, 2, 1, 0, 0, 0, 4, 4, 0, 0, 0, 4, 4, 4, 4, 0, 4, 3, 3, 4, 3, 0, 0, 0, 3, 4, 4, 3, 4, 0, 4, 0, 0, 4, 0])]"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"%%sql\n",
"DROP TABLE IF EXISTS outdata_predict;\n",
"\n",
"SELECT madlib.lda_predict( 'documents_tf', -- Document to predict\n",
" 'lda_model', -- LDA model from training\n",
" 'outdata_predict' \n",
" );\n",
"\n",
"SELECT * FROM outdata_predict ORDER BY docid;"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 7. Helper function on prediction"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Done.\n",
"1 rows affected.\n",
"40 rows affected.\n"
]
},
{
"data": {
"text/html": [
"<table>\n",
" <tr>\n",
" <th>docid</th>\n",
" <th>wordid</th>\n",
" <th>topicid</th>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>56</td>\n",
" <td>3</td>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>54</td>\n",
" <td>3</td>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>42</td>\n",
" <td>3</td>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>35</td>\n",
" <td>3</td>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>32</td>\n",
" <td>3</td>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>29</td>\n",
" <td>3</td>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>28</td>\n",
" <td>3</td>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>24</td>\n",
" <td>3</td>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>17</td>\n",
" <td>3</td>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>11</td>\n",
" <td>3</td>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>8</td>\n",
" <td>3</td>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>3</td>\n",
" <td>3</td>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>97</td>\n",
" <td>4</td>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>95</td>\n",
" <td>3</td>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>90</td>\n",
" <td>4</td>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>85</td>\n",
" <td>3</td>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>80</td>\n",
" <td>3</td>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>71</td>\n",
" <td>3</td>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>68</td>\n",
" <td>3</td>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>64</td>\n",
" <td>3</td>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>64</td>\n",
" <td>2</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1</td>\n",
" <td>7</td>\n",
" <td>4</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1</td>\n",
" <td>6</td>\n",
" <td>4</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1</td>\n",
" <td>2</td>\n",
" <td>4</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>4</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>4</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1</td>\n",
" <td>102</td>\n",
" <td>4</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1</td>\n",
" <td>101</td>\n",
" <td>4</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1</td>\n",
" <td>100</td>\n",
" <td>4</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1</td>\n",
" <td>93</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1</td>\n",
" <td>90</td>\n",
" <td>4</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1</td>\n",
" <td>90</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1</td>\n",
" <td>88</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1</td>\n",
" <td>75</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1</td>\n",
" <td>74</td>\n",
" <td>4</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1</td>\n",
" <td>68</td>\n",
" <td>3</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1</td>\n",
" <td>59</td>\n",
" <td>4</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1</td>\n",
" <td>57</td>\n",
" <td>2</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1</td>\n",
" <td>55</td>\n",
" <td>4</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1</td>\n",
" <td>53</td>\n",
" <td>4</td>\n",
" </tr>\n",
"</table>"
],
"text/plain": [
"[(0, 56, 3),\n",
" (0, 54, 3),\n",
" (0, 42, 3),\n",
" (0, 35, 3),\n",
" (0, 32, 3),\n",
" (0, 29, 3),\n",
" (0, 28, 3),\n",
" (0, 24, 3),\n",
" (0, 17, 3),\n",
" (0, 11, 3),\n",
" (0, 8, 3),\n",
" (0, 3, 3),\n",
" (0, 97, 4),\n",
" (0, 95, 3),\n",
" (0, 90, 4),\n",
" (0, 85, 3),\n",
" (0, 80, 3),\n",
" (0, 71, 3),\n",
" (0, 68, 3),\n",
" (0, 64, 3),\n",
" (0, 64, 2),\n",
" (1, 7, 4),\n",
" (1, 6, 4),\n",
" (1, 2, 4),\n",
" (1, 1, 4),\n",
" (1, 0, 4),\n",
" (1, 102, 4),\n",
" (1, 101, 4),\n",
" (1, 100, 4),\n",
" (1, 93, 0),\n",
" (1, 90, 4),\n",
" (1, 90, 0),\n",
" (1, 88, 0),\n",
" (1, 75, 0),\n",
" (1, 74, 4),\n",
" (1, 68, 3),\n",
" (1, 59, 4),\n",
" (1, 57, 2),\n",
" (1, 55, 4),\n",
" (1, 53, 4)]"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"%%sql\n",
"DROP TABLE IF EXISTS helper_output_table;\n",
"\n",
"SELECT madlib.lda_get_word_topic_mapping('outdata_predict', -- Output table from prediction\n",
" 'helper_output_table');\n",
"\n",
"SELECT * FROM helper_output_table ORDER BY docid LIMIT 40;"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 8. Perplexity on final model\n",
"\n",
"Call perplexity function to see how well the model fits the data. Perplexity computes word likelihoods averaged over the test documents."
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1 rows affected.\n"
]
},
{
"data": {
"text/html": [
"<table>\n",
" <tr>\n",
" <th>lda_get_perplexity</th>\n",
" </tr>\n",
" <tr>\n",
" <td>77.1798997241</td>\n",
" </tr>\n",
"</table>"
],
"text/plain": [
"[(77.1798997240748,)]"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"%%sql\n",
"SELECT madlib.lda_get_perplexity( 'lda_model',\n",
" 'outdata_predict'\n",
" );"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 9. Perplexity by iteration\n",
"Now let's look at how perplexity changes from one iteration to the next:"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Done.\n",
"2 rows affected.\n",
"4 rows affected.\n"
]
},
{
"data": {
"text/html": [
"<table>\n",
" <tr>\n",
" <th>docid</th>\n",
" <th>wordcount</th>\n",
" <th>words</th>\n",
" <th>counts</th>\n",
" <th>topic_count</th>\n",
" <th>topic_assignment</th>\n",
" </tr>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>22</td>\n",
" <td>[24, 17, 11, 95, 90, 85, 68, 54, 42, 35, 28, 8, 3, 97, 80, 71, 64, 56, 32, 29]</td>\n",
" <td>[1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1]</td>\n",
" <td>[5, 0, 6, 3, 8]</td>\n",
" <td>[2, 4, 0, 4, 3, 0, 2, 2, 0, 2, 0, 3, 4, 4, 0, 2, 4, 4, 4, 4, 3, 2]</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1</td>\n",
" <td>37</td>\n",
" <td>[1, 50, 49, 46, 19, 16, 14, 9, 7, 0, 90, 68, 57, 102, 101, 100, 93, 88, 75, 74, 59, 55, 53, 48, 39, 21, 18, 15, 6, 2]</td>\n",
" <td>[1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 5, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]</td>\n",
" <td>[4, 10, 8, 8, 7]</td>\n",
" <td>[4, 0, 0, 0, 0, 3, 1, 4, 1, 1, 3, 4, 2, 3, 3, 2, 2, 2, 2, 1, 4, 1, 1, 2, 3, 2, 1, 1, 2, 1, 4, 1, 3, 4, 3, 4, 3]</td>\n",
" </tr>\n",
" <tr>\n",
" <td>2</td>\n",
" <td>36</td>\n",
" <td>[10, 27, 33, 40, 47, 51, 58, 62, 63, 69, 72, 83, 100, 99, 94, 92, 91, 90, 89, 87, 86, 79, 76, 70, 60, 52, 50, 36, 30, 25, 9, 5, 3]</td>\n",
" <td>[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1]</td>\n",
" <td>[3, 6, 12, 4, 11]</td>\n",
" <td>[2, 4, 3, 4, 3, 4, 2, 1, 3, 2, 4, 4, 1, 4, 2, 2, 2, 2, 4, 2, 1, 2, 3, 1, 2, 4, 0, 4, 0, 2, 4, 0, 1, 1, 2, 4]</td>\n",
" </tr>\n",
" <tr>\n",
" <td>3</td>\n",
" <td>49</td>\n",
" <td>[77, 78, 81, 82, 67, 65, 51, 45, 44, 43, 34, 26, 13, 98, 96, 94, 90, 84, 73, 68, 66, 61, 50, 41, 38, 37, 31, 23, 22, 20, 19, 12, 4, 3]</td>\n",
" <td>[1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 11, 1, 1, 2, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]</td>\n",
" <td>[12, 6, 12, 16, 3]</td>\n",
" <td>[1, 2, 1, 0, 2, 0, 3, 2, 0, 0, 1, 2, 3, 3, 3, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 2, 3, 3, 0, 0, 2, 2, 3, 4, 0, 0, 0, 1, 4, 2, 1, 2, 3, 0, 1, 0, 0, 4]</td>\n",
" </tr>\n",
"</table>"
],
"text/plain": [
"[(0, 22, [24, 17, 11, 95, 90, 85, 68, 54, 42, 35, 28, 8, 3, 97, 80, 71, 64, 56, 32, 29], [1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1], [5, 0, 6, 3, 8], [2, 4, 0, 4, 3, 0, 2, 2, 0, 2, 0, 3, 4, 4, 0, 2, 4, 4, 4, 4, 3, 2]),\n",
" (1, 37, [1, 50, 49, 46, 19, 16, 14, 9, 7, 0, 90, 68, 57, 102, 101, 100, 93, 88, 75, 74, 59, 55, 53, 48, 39, 21, 18, 15, 6, 2], [1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 5, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [4, 10, 8, 8, 7], [4, 0, 0, 0, 0, 3, 1, 4, 1, 1, 3, 4, 2, 3, 3, 2, 2, 2, 2, 1, 4, 1, 1, 2, 3, 2, 1, 1, 2, 1, 4, 1, 3, 4, 3, 4, 3]),\n",
" (2, 36, [10, 27, 33, 40, 47, 51, 58, 62, 63, 69, 72, 83, 100, 99, 94, 92, 91, 90, 89, 87, 86, 79, 76, 70, 60, 52, 50, 36, 30, 25, 9, 5, 3], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1], [3, 6, 12, 4, 11], [2, 4, 3, 4, 3, 4, 2, 1, 3, 2, 4, 4, 1, 4, 2, 2, 2, 2, 4, 2, 1, 2, 3, 1, 2, 4, 0, 4, 0, 2, 4, 0, 1, 1, 2, 4]),\n",
" (3, 49, [77, 78, 81, 82, 67, 65, 51, 45, 44, 43, 34, 26, 13, 98, 96, 94, 90, 84, 73, 68, 66, 61, 50, 41, 38, 37, 31, 23, 22, 20, 19, 12, 4, 3], [1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 11, 1, 1, 2, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [12, 6, 12, 16, 3], [1, 2, 1, 0, 2, 0, 3, 2, 0, 0, 1, 2, 3, 3, 3, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 2, 3, 3, 0, 0, 2, 2, 3, 4, 0, 0, 0, 1, 4, 2, 1, 2, 3, 0, 1, 0, 0, 4])]"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"%%sql\n",
"DROP TABLE IF EXISTS lda_model_perp, lda_output_data_perp;\n",
"\n",
"SELECT madlib.lda_train( 'documents_tf', -- documents table in the form of term frequency\n",
" 'lda_model_perp', -- model table created by LDA training (not human readable)\n",
" 'lda_output_data_perp', -- readable output data table \n",
" 103, -- vocabulary size\n",
" 5, -- number of topics\n",
" 30, -- number of iterations\n",
" 5, -- Dirichlet prior for the per-doc topic multinomial (alpha)\n",
" 0.01, -- Dirichlet prior for the per-topic word multinomial (beta)\n",
" 2, -- Evaluate perplexity every n iterations\n",
" 0.3 -- Tolerance to stop iteration\n",
" );\n",
"\n",
"SELECT * FROM lda_output_data_perp ORDER BY docid;"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1 rows affected.\n"
]
},
{
"data": {
"text/html": [
"<table>\n",
" <tr>\n",
" <th>voc_size</th>\n",
" <th>topic_num</th>\n",
" <th>alpha</th>\n",
" <th>beta</th>\n",
" <th>num_iterations</th>\n",
" <th>perplexity</th>\n",
" <th>perplexity_iters</th>\n",
" </tr>\n",
" <tr>\n",
" <td>103</td>\n",
" <td>5</td>\n",
" <td>5.0</td>\n",
" <td>0.01</td>\n",
" <td>10</td>\n",
" <td>[67.1591056287, 69.9501444785, 66.7049790698, 68.0639898651, 68.2407536396]</td>\n",
" <td>[2, 4, 6, 8, 10]</td>\n",
" </tr>\n",
"</table>"
],
"text/plain": [
"[(103, 5, 5.0, 0.01, 10, [67.1591056287, 69.9501444785, 66.7049790698, 68.0639898651, 68.2407536396], [2, 4, 6, 8, 10])]"
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"%%sql\n",
"SELECT voc_size, topic_num, alpha, beta, num_iterations, perplexity, perplexity_iters from lda_model_perp;"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Double check that the perplexity is that same as the final value of the iteration:"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1 rows affected.\n"
]
},
{
"data": {
"text/html": [
"<table>\n",
" <tr>\n",
" <th>lda_get_perplexity</th>\n",
" </tr>\n",
" <tr>\n",
" <td>68.2407536396</td>\n",
" </tr>\n",
"</table>"
],
"text/plain": [
"[(68.2407536395908,)]"
]
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"%%sql\n",
"SELECT madlib.lda_get_perplexity( 'lda_model_perp',\n",
" 'lda_output_data_perp'\n",
" );"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Plot perplexity by number of iterations"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1 rows affected.\n",
"1 rows affected.\n",
"1 rows affected.\n"
]
},
{
"data": {
"text/plain": [
"<matplotlib.legend.Legend at 0x116101d50>"
]
},
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYwAAAEWCAYAAAB1xKBvAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvIxREBQAAIABJREFUeJzt3Xd4VQW29/HvSggQWiAgAem9CglBIOooiAIiKioggogmDlYGxbl3nHmd0RlnvDr3EsWOCliogoiiCCLCzKgBpIQaOiihSw8tIVnvH3tHQ0g5KSc7J1mf5zlPzt5nl985gbOy29qiqhhjjDH5CfI6gDHGmMBgBcMYY4xPrGAYY4zxiRUMY4wxPrGCYYwxxidWMIwxxvjECoYpM0RkqYg8UAzL2Sg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zcaGIvIDTNTVRRKa64zK3ZsRd9gb3Hhx3ZVn20iz3v5jqXrF8EXeaF8W578lWEfmNO/6iLQQR+VxEemau213nRhH5WkS6ucvZKSK3Zll8I3f8NhF5Jsuy7nHXlygiEzKLg7vccSKyFvD8Xh2mFFNVe9gjoB9AivuzJ/B5lvGjgKfd55WAlThN7XriNAFslmXacPdnKE5LkdpZl53Duu4EFuHcryECp6VFfXfZJ3CaRgYBCThNEbNnXgqMc5/3B752n98HvJZlus+Bnu5zBW5yn3+C0wgvBOf+DIlZ5t8P1M7yXrritOeeB4S4070B3JtluUO8/j3ao/Q/yntrEFO29QE6icggdzgMaAWkAitUdVeWaX8nIre7zxu50x3JY9nXANNVNR2n8du/gCuBk+6ykwHcljNNgW9zWEZms8tV7jT5ScXplAqwHjivqmkisj7b/ItU9Yi7/jlu1gs4N0r6wd3gCeXXBnXpOA04jcmTFQxTlgkwWlUXXjTS2cVzOtvwDUCMqp4RkaVAUW4Lej7L83Ry/392PodpLnDxruKsOdJUNbOXT0bm/Kqake1YTPZ+P4rzWbyvqn/MIcc5t/AZkyc7hmHKklNA9SzDC4GH3Rb2iEjrXG5eFAYcc4tFW5zb9WZKy5w/m/8Ad7nHSS7DuaveimJ4D7uBSBEJEpFGFK5F+43i3OM5FOfOa9/h3LZzUJaOq+Ei0qQY8ppyxLYwTFmyDkh3D96+h3Mv7abAavfA82FyvnXlAuAhEUkCtgDLsrz2NrBORFar6vAs4z/BOUC8Fucv+P9W1QNuwSmK74BdOAfjk3C6thbUCpxdTA2BKaq6EkBEnsa5I2EQbsdVnM6mxvjEutUaY4zxie2SMsYY4xMrGMYYY3xiBcMYY4xPrGAYY4zxiRUMY4wxPrGCYYwxxidWMIwxxvjk/wMVPdh3uSDJEgAAAABJRU5ErkJggg==\n",
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"import pandas as pd\n",
"import numpy as np\n",
"import sys\n",
"import os\n",
"from matplotlib import pyplot as plt\n",
"\n",
"# get accuracy and iteration number\n",
"iters_proxy = %sql SELECT perplexity_iters FROM lda_model_perp;\n",
"perplexity_proxy = %sql SELECT perplexity FROM lda_model_perp;\n",
"\n",
"# get number of points\n",
"num_points_proxy = %sql SELECT array_length(perplexity_iters,1) FROM lda_model_perp;\n",
"num_points = num_points_proxy[0]\n",
"\n",
"# reshape to np arrays\n",
"iters = np.array(iters_proxy).reshape(num_points)\n",
"perplexity = np.array(perplexity_proxy).reshape(num_points)\n",
"\n",
"#plot\n",
"plt.title('Perplexity by iteration')\n",
"plt.xlabel('Iteration number')\n",
"plt.ylabel('Perplexity')\n",
"plt.grid(True)\n",
"plt.plot(iters, perplexity, 'g.-')\n",
"plt.legend()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.10"
}
},
"nbformat": 4,
"nbformat_minor": 1
}