{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "inputHidden": false, "outputHidden": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Hello World!\n", "Hello Again\n", "I like typing this.\n", "This is fun.\n", "Yay! Printing.\n", "I'd much rather you 'not'.\n", "I \"said\" do not touch this.\n" ] } ], "source": [ "print(\"Hello World!\")\n", "print(\"Hello Again\")\n", "print(\"I like typing this.\")\n", "print(\"This is fun.\")\n", "print('Yay! Printing.')\n", "print(\"I'd much rather you 'not'.\")\n", "print('I \"said\" do not touch this.')" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "inputHidden": false, "outputHidden": false }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\n", "
\n", "" ], "text/plain": [ "" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import requests\n", "import re\n", "from gensim.parsing.preprocessing import remove_stopwords\n", "from gensim.corpora.dictionary import Dictionary\n", "from gensim.models.ldamodel import LdaModel\n", "import pyLDAvis\n", "import pyLDAvis.gensim\n", "\n", "pride_and_prejudice = requests.get(\"http://www.gutenberg.org/cache/epub/42671/pg42671.txt\").text\n", "paragraphs = [re.split(r\"\\W+\",remove_stopwords(paragraph)) for paragraph in re.split(r\"\\r\\n\\r\\n\",re.sub(r\"CHAPTER [XIV]+\\.\",\"\",pride_and_prejudice[pride_and_prejudice.index(\"CHAPTER I.\"):pride_and_prejudice.index(\"*** END OF THE PROJECT GUTENBERG EBOOK PRIDE AND PREJUDICE ***\")]))]\n", "d = Dictionary(paragraphs)\n", "c = [d.doc2bow(paragraph) for paragraph in paragraphs]\n", "m = LdaModel(c,num_topics = 15, alpha='auto')\n", "pyLDAvis.display(pyLDAvis.gensim.prepare(m,c,d))\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "inputHidden": false, "outputHidden": false }, "outputs": [], "source": [] } ], "metadata": { "kernel_info": { "name": "python3" }, "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.6" }, "nteract": { "version": "0.11.9" } }, "nbformat": 4, "nbformat_minor": 4 }