{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "

Tutorial: automatic summarization using Gensim

\n", "\n", "This module automatically summarizes the given text, by extracting one or more important sentences from the text. In a similar way, it can also extract keywords. This tutorial will teach you to use this summarization module via some examples. First, we will try a small example, then we will try two larger ones, and then we will review the performance of the summarizer in terms of speed.\n", "\n", "This summarizer is based on the \"TextRank\" algorithm, from an [article](http://web.eecs.umich.edu/%7Emihalcea/papers/mihalcea.emnlp04.pdf) by Mihalcea et al. This algorithm was later improved upon by Barrios et al. in another [article](https://raw.githubusercontent.com/summanlp/docs/master/articulo/articulo-en.pdf), by introducing something called a \"BM25 ranking function\". \n", "\n", "This tutorial assumes that you are familiar with Python and have [installed Gensim](http://radimrehurek.com/gensim/install.html).\n", "\n", "Note: Gensim's summarization only works for English for now, because the text is pre-processed so that stopwords are removed and the words are stemmed, and these processes are language-dependent.\n", "\n", "\n", "

Small example

\n", "\n", "First of all, we import the function \"summarize\"." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "2017-11-28 08:32:40,713 : INFO : 'pattern' package not found; tag filters are not available for English\n" ] } ], "source": [ "import logging\n", "logging.basicConfig(format='%(asctime)s : %(levelname)s : %(message)s', level=logging.INFO)\n", "\n", "from gensim.summarization import summarize" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We will try summarizing a small toy example; later we will use a larger piece of text. In reality, the text is too small, but it suffices as an illustrative example." ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Input text:\n", "Thomas A. Anderson is a man living two lives. By day he is an average computer programmer and by night a hacker known as Neo. Neo has always questioned his reality, but the truth is far beyond his imagination. Neo finds himself targeted by the police when he is contacted by Morpheus, a legendary computer hacker branded a terrorist by the government. Morpheus awakens Neo to the real world, a ravaged wasteland where most of humanity have been captured by a race of machines that live off of the humans' body heat and electrochemical energy and who imprison their minds within an artificial reality known as the Matrix. As a rebel against the machines, Neo must return to the Matrix and confront the agents: super-powerful computer programs devoted to snuffing out Neo and the entire human rebellion. \n" ] } ], "source": [ "text = \"Thomas A. Anderson is a man living two lives. By day he is an \" + \\\n", " \"average computer programmer and by night a hacker known as \" + \\\n", " \"Neo. Neo has always questioned his reality, but the truth is \" + \\\n", " \"far beyond his imagination. Neo finds himself targeted by the \" + \\\n", " \"police when he is contacted by Morpheus, a legendary computer \" + \\\n", " \"hacker branded a terrorist by the government. Morpheus awakens \" + \\\n", " \"Neo to the real world, a ravaged wasteland where most of \" + \\\n", " \"humanity have been captured by a race of machines that live \" + \\\n", " \"off of the humans' body heat and electrochemical energy and \" + \\\n", " \"who imprison their minds within an artificial reality known as \" + \\\n", " \"the Matrix. As a rebel against the machines, Neo must return to \" + \\\n", " \"the Matrix and confront the agents: super-powerful computer \" + \\\n", " \"programs devoted to snuffing out Neo and the entire human \" + \\\n", " \"rebellion. \"\n", "\n", "print ('Input text:')\n", "print (text)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To summarize this text, we pass the raw string data as input to the function \"summarize\", and it will return a summary.\n", "\n", "Note: make sure that the string does not contain any newlines where the line breaks in a sentence. A sentence with a newline in it (i.e. a carriage return, \"\\n\") will be treated as two sentences." ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "2017-11-28 08:32:40,736 : WARNING : Input text is expected to have at least 10 sentences.\n", "2017-11-28 08:32:40,737 : INFO : adding document #0 to Dictionary(0 unique tokens: [])\n", "2017-11-28 08:32:40,738 : INFO : built Dictionary(53 unique tokens: [u'electrochem', u'real', u'captur', u'mind', u'agent']...) from 6 documents (total 68 corpus positions)\n", "2017-11-28 08:32:40,738 : WARNING : Input corpus is expected to have at least 10 documents.\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Summary:\n", "Morpheus awakens Neo to the real world, a ravaged wasteland where most of humanity have been captured by a race of machines that live off of the humans' body heat and electrochemical energy and who imprison their minds within an artificial reality known as the Matrix.\n" ] } ], "source": [ "print ('Summary:')\n", "print (summarize(text))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Use the \"split\" option if you want a list of strings instead of a single string." ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "2017-11-28 08:32:40,748 : WARNING : Input text is expected to have at least 10 sentences.\n", "2017-11-28 08:32:40,749 : INFO : adding document #0 to Dictionary(0 unique tokens: [])\n", "2017-11-28 08:32:40,750 : INFO : built Dictionary(53 unique tokens: [u'electrochem', u'real', u'captur', u'mind', u'agent']...) from 6 documents (total 68 corpus positions)\n", "2017-11-28 08:32:40,751 : WARNING : Input corpus is expected to have at least 10 documents.\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "[\"Morpheus awakens Neo to the real world, a ravaged wasteland where most of humanity have been captured by a race of machines that live off of the humans' body heat and electrochemical energy and who imprison their minds within an artificial reality known as the Matrix.\"]\n" ] } ], "source": [ "print (summarize(text, split=True))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You can adjust how much text the summarizer outputs via the \"ratio\" parameter or the \"word_count\" parameter. Using the \"ratio\" parameter, you specify what fraction of sentences in the original text should be returned as output. Below we specify that we want 50% of the original text (the default is 20%)." ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "2017-11-28 08:32:40,761 : WARNING : Input text is expected to have at least 10 sentences.\n", "2017-11-28 08:32:40,761 : INFO : adding document #0 to Dictionary(0 unique tokens: [])\n", "2017-11-28 08:32:40,762 : INFO : built Dictionary(53 unique tokens: [u'electrochem', u'real', u'captur', u'mind', u'agent']...) from 6 documents (total 68 corpus positions)\n", "2017-11-28 08:32:40,763 : WARNING : Input corpus is expected to have at least 10 documents.\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Summary:\n", "By day he is an average computer programmer and by night a hacker known as Neo. Neo has always questioned his reality, but the truth is far beyond his imagination.\n", "Neo finds himself targeted by the police when he is contacted by Morpheus, a legendary computer hacker branded a terrorist by the government.\n", "Morpheus awakens Neo to the real world, a ravaged wasteland where most of humanity have been captured by a race of machines that live off of the humans' body heat and electrochemical energy and who imprison their minds within an artificial reality known as the Matrix.\n" ] } ], "source": [ "print ('Summary:')\n", "print (summarize(text, ratio=0.5))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Using the \"word_count\" parameter, we specify the maximum amount of words we want in the summary. Below we have specified that we want no more than 50 words." ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "2017-11-28 08:32:40,774 : WARNING : Input text is expected to have at least 10 sentences.\n", "2017-11-28 08:32:40,775 : INFO : adding document #0 to Dictionary(0 unique tokens: [])\n", "2017-11-28 08:32:40,776 : INFO : built Dictionary(53 unique tokens: [u'electrochem', u'real', u'captur', u'mind', u'agent']...) from 6 documents (total 68 corpus positions)\n", "2017-11-28 08:32:40,777 : WARNING : Input corpus is expected to have at least 10 documents.\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Summary:\n", "Morpheus awakens Neo to the real world, a ravaged wasteland where most of humanity have been captured by a race of machines that live off of the humans' body heat and electrochemical energy and who imprison their minds within an artificial reality known as the Matrix.\n" ] } ], "source": [ "print ('Summary:')\n", "print (summarize(text, word_count=50))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "As mentioned earlier, this module also supports keyword extraction. Keyword extraction works in the same way as summary generation (i.e. sentence extraction), in that the algorithm tries to find words that are important or seem representative of the entire text. They keywords are not always single words; in the case of multi-word keywords, they are typically all nouns." ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Keywords:\n", "humanity\n", "human\n", "neo\n", "humans body\n", "super\n", "hacker\n", "reality\n" ] } ], "source": [ "from gensim.summarization import keywords\n", "\n", "print ('Keywords:')\n", "print (keywords(text))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

Larger example

\n", "\n", "Let us try an example with a larger piece of text. We will be using a synopsis of the movie \"The Matrix\", which we have taken from [this](http://www.imdb.com/title/tt0133093/synopsis?ref_=ttpl_pl_syn) IMDb page.\n", "\n", "In the code below, we read the text file directly from a web-page using \"requests\". Then we produce a summary and some keywords." ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": false }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "2017-11-28 08:32:41,320 : INFO : adding document #0 to Dictionary(0 unique tokens: [])\n", "2017-11-28 08:32:41,326 : INFO : built Dictionary(1093 unique tokens: [u'code', u'squiddi', u'relai', u'dinosaur', u'electron']...) from 416 documents (total 2985 corpus positions)\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Summary:\n", "Anderson, a software engineer for a Metacortex, the other life as Neo, a computer hacker \"guilty of virtually every computer crime we have a law for.\" Agent Smith asks him to help them capture Morpheus, a dangerous terrorist, in exchange for amnesty.\n", "Morpheus explains that he's been searching for Neo his entire life and asks if Neo feels like \"Alice in Wonderland, falling down the rabbit hole.\" He explains to Neo that they exist in the Matrix, a false reality that has been constructed for humans to hide the truth.\n", "Neo is introduced to Morpheus's crew including Trinity; Apoc (Julian Arahanga), a man with long, flowing black hair; Switch; Cypher (bald with a goatee); two brawny brothers, Tank (Marcus Chong) and Dozer (Anthony Ray Parker); and a young, thin man named Mouse (Matt Doran).\n", "Cypher cuts up a juicy steak and ruminates that he knows the steak is merely the simulation telling his brain that it is delicious and juicy, but after nine years he has discovered that \"ignorance is bliss.\" He strikes a deal for the machines to reinsert his body into a power plant, reinsert him into the Matrix, and he'll help the Agents.\n", "\n", "Keywords:\n", "neo\n", "morpheus\n", "trinity\n", "cypher\n", "agents\n", "agent\n", "smith\n", "tank\n", "says\n", "saying\n" ] } ], "source": [ "import requests\n", "\n", "text = requests.get('http://rare-technologies.com/the_matrix_synopsis.txt').text\n", "\n", "print ('Summary:')\n", "print (summarize(text, ratio=0.01))\n", "\n", "print ('\\nKeywords:')\n", "print (keywords(text, ratio=0.01))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If you know this movie, you see that this summary is actually quite good. We also see that some of the most important characters (Neo, Morpheus, Trinity) were extracted as keywords.\n", "\n", "

Another example

\n", "\n", "Let's try an example similar to the one above. This time, we will use the [IMDb synopsis](http://www.imdb.com/title/tt0118715/synopsis?ref_=tt_stry_pl) of \"The Big Lebowski\".\n", "\n", "Again, we download the text and produce a summary and some keywords." ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "collapsed": false }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "2017-11-28 08:32:43,682 : INFO : adding document #0 to Dictionary(0 unique tokens: [])\n", "2017-11-28 08:32:43,687 : INFO : built Dictionary(1054 unique tokens: [u'fawn', u'windi', u'concept', u'doctor', u'gant']...) from 227 documents (total 2434 corpus positions)\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Summary:\n", "The answering machine records a woman introducing herself as Maude Lebowski and saying that she is the one who took his rug and has sent a car to pick Dude up at his apartment.\n", "As he climbs out of bed to make a White Russian, Maude asks about the apartment and Dude explains that Treehorn's thugs most likely vandalized it looking for Lebowski's money.\n", "\n", "Keywords:\n", "dude\n", "dudes\n", "walter\n", "lebowski\n", "brandt\n", "maude\n", "donny\n", "bunny\n" ] } ], "source": [ "import requests\n", "\n", "text = requests.get('http://rare-technologies.com/the_big_lebowski_synopsis.txt').text\n", "\n", "print ('Summary:')\n", "print (summarize(text, ratio=0.01))\n", "\n", "print ('\\nKeywords:')\n", "print (keywords(text, ratio=0.01))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This time around, the summary is not of high quality, as it does not tell us much about the movie. In a way, this might not be the algorithms fault, rather this text simply doesn't contain one or two sentences that capture the essence of the text as in \"The Matrix\" synopsis.\n", "\n", "The keywords, however, managed to find some of the main characters.\n", "\n", "

Performance

\n", "\n", "We will test how the speed of the summarizer scales with the size of the dataset. These tests were run on an Intel Core i5 4210U CPU @ 1.70 GHz x 4 processor. Note that the summarizer does not support multithreading (parallel processing).\n", "\n", "The tests were run on the book \"Honest Abe\" by Alonzo Rothschild. Download the book in plain-text here. \n", "\n", "In the plot below, we see the running times together with the sizes of the datasets. To create datasets of different sizes, we have simply taken prefixes of text; in other words we take the first n characters of the book. The algorithm seems to be quadratic in time, so one needs to be careful before plugging a large dataset into the summarizer.\n", "\n", "
\n", "\n", "
\n", "
\n", "\n", "

Text-content dependent running times

\n", "\n", "The running time is not only dependent on the size of the dataset. For example, summarizing \"The Matrix\" synopsis (about 36,000 characters) takes about 3.1 seconds, while summarizing 35,000 characters of this book takes about 8.5 seconds. So the former is more than twice as fast. \n", "\n", "One reason for this difference in running times is the data structure that is used. The algorithm represents the data using a graph, where vertices (nodes) are sentences, and then constructs weighted edges between the vertices that represent how the sentences relate to each other. This means that every piece of text will have a different graph, thus making the running times different. The size of this data structure is quadratic in the worst case (the worst case is when each vertex has an edge to every other vertex).\n", "\n", "Another possible reason for the difference in running times is that the problems converge at different rates, meaning that the error drops slower for some datasets than for others.\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Montemurro and Zanette's entropy based keyword extraction algorithm\n", "\n", "[This paper](https://arxiv.org/abs/0907.1558) describes a technique to identify words that play a significant role in the large-scale structure of a text. These typically correspond to the major themes of the text. The text is divided into blocks of ~1000 words, and the entropy of each word's distribution amongst the blocks is\n", "caclulated and compared with the expected entropy if the word were distributed randomly." ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import requests\n", "from gensim.summarization import mz_keywords" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "collapsed": false }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/home/pete/gensim/gensim/summarization/mz_entropy.py:74: RuntimeWarning: divide by zero encountered in log2\n", " logp = numpy.log2(p)\n", "/home/pete/gensim/gensim/summarization/mz_entropy.py:75: RuntimeWarning: invalid value encountered in multiply\n", " H = numpy.nan_to_num(p * logp).sum(axis=0)\n" ] }, { "data": { "text/plain": [ "[(u'lincoln', 0.0056009079527401728),\n", " (u'i', 0.0048480807199453163),\n", " (u'gutenberg', 0.0033118705607652456),\n", " (u'you', 0.0033044241876850882),\n", " (u'the', 0.003184223100952537),\n", " (u'project', 0.0030400432599562814),\n", " (u'v', 0.0029892072316233462),\n", " (u's', 0.0027479946846166391),\n", " (u'he', 0.0026405628272363011),\n", " (u'iv', 0.0025895621076850355),\n", " (u'ii', 0.0025019507619403148),\n", " (u'by', 0.0022277723676676691),\n", " (u'abraham', 0.0021168707666022494),\n", " (u'or', 0.0020858843371172162),\n", " (u'iii', 0.002071167621155823),\n", " (u'tm', 0.0019565820396828327),\n", " (u'was', 0.0018954215033062955),\n", " (u'his', 0.0018126024538229718),\n", " (u'work', 0.0017646814365061972),\n", " (u'co', 0.0017416964820475558),\n", " (u'case', 0.001661734006946057),\n", " (u'new', 0.0016558607106467698),\n", " (u'york', 0.0015861543846297651),\n", " (u'court', 0.0014488333654852606),\n", " (u'a', 0.0013369063978456374),\n", " (u'it', 0.0013221654971075282),\n", " (u'had', 0.0012652752682645698),\n", " (u'on', 0.0012621040038518136),\n", " (u'their', 0.0012449891448184512),\n", " (u'herndon', 0.0012402952190743249),\n", " (u'life', 0.00123104152062403),\n", " (u'my', 0.0011741303053317792),\n", " (u'_works_', 0.0010832651550141503),\n", " (u'we', 0.0010768294653523067),\n", " (u'money', 0.0010191083741917691),\n", " (u'father', 0.0010168268194887184)]" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "text=requests.get(\"http://www.gutenberg.org/files/49679/49679-0.txt\").text\n", "mz_keywords(text,scores=True,threshold=0.001)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "By default, the algorithm weights the entropy by the overall frequency of the word in the document. We can remove this weighting by setting weighted=False" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "[(u'gutenberg', 3.7766363961259684),\n", " (u'tm', 3.6403066998316511),\n", " (u'project', 3.5428530523255342),\n", " (u'co', 3.2983688146004528),\n", " (u'donations', 2.8613536046553563),\n", " (u'electronic', 2.8210861922674084),\n", " (u'access', 2.7810662866642568),\n", " (u'refund', 2.7810662866642568),\n", " (u'foundation', 2.7234464816769872),\n", " (u'foxboro', 2.5477601487545121),\n", " (u'gloves', 2.5281337853661761),\n", " (u'e', 2.4036269322210768),\n", " (u'york', 2.3692008259770594),\n", " (u'edited', 2.361641829495754),\n", " (u'_works_', 2.3445174072327686),\n", " (u'works', 2.3426500474551113),\n", " (u'dogskin', 2.3425994588269479),\n", " (u'ragsdale', 2.2931552327841351),\n", " (u'replacement', 2.2931552327841351),\n", " (u'trunks', 2.2931552327841351),\n", " (u'iv', 2.2510299269025058),\n", " (u'iii', 2.2186807817292546),\n", " (u'v', 2.2168420707754368),\n", " (u'brokaw', 2.1699176369612583),\n", " (u'coon', 2.1699176369612583),\n", " (u'bonds', 2.1343080503770544),\n", " (u'license', 2.1009287665795293),\n", " (u'ii', 2.0892470886183649),\n", " (u'agreement', 2.0779209847210556),\n", " (u'almanac', 2.0060727272918055),\n", " (u'_weekly_', 1.9794475925140163),\n", " (u'bounded', 1.9794475925140163),\n", " (u'format', 1.9794475925140163),\n", " (u'millions', 1.9794475925140163),\n", " (u'oxen', 1.9794475925140163),\n", " (u'specie', 1.9794475925140163),\n", " (u'archive', 1.9682995275030786),\n", " (u'barrett', 1.9422319940872796),\n", " (u'reminiscences', 1.9330537427622287),\n", " (u'ebooks', 1.8984698469769548),\n", " (u'forquer', 1.8843080503770544),\n", " (u'parker', 1.8843080503770544),\n", " (u'pglaf', 1.8843080503770544),\n", " (u'ebook', 1.8838775575675983),\n", " (u'trademark', 1.8838775575675983),\n", " (u'paragraph', 1.8301079379685583),\n", " (u'hardin', 1.7669683658081703),\n", " (u'work', 1.7328354724344326),\n", " (u'rothschild', 1.7275730939964973),\n", " (u'org', 1.7211393195188851),\n", " (u'attitude', 1.716230650790012),\n", " (u'london', 1.6791112857988695),\n", " (u'boston', 1.6754810009833907),\n", " (u'xvi', 1.66018729770736),\n", " (u'news', 1.6601872977073597),\n", " (u'biographical', 1.6294643147000225),\n", " (u'green', 1.6254512602292723),\n", " (u'delegates', 1.6127555612626692),\n", " (u'medium', 1.6127555612626692),\n", " (u'scripps', 1.6127555612626692),\n", " (u'volunteers', 1.6127555612626692),\n", " (u'lamon', 1.6001560607245646),\n", " (u'tarbell', 1.5897346234235084),\n", " (u'volumes', 1.5819481863246514),\n", " (u'bank', 1.5744728128489647),\n", " (u'copyright', 1.5731550611734115),\n", " (u'_via_', 1.5722781569106761),\n", " (u'admissibility', 1.5722781569106761),\n", " (u'advertisers', 1.5722781569106761),\n", " (u'applicable', 1.5722781569106761),\n", " (u'attire', 1.5722781569106761),\n", " (u'bags', 1.5722781569106761),\n", " (u'berries', 1.5722781569106761),\n", " (u'breeches', 1.5722781569106761),\n", " (u'cline', 1.5722781569106761),\n", " (u'continuance', 1.5722781569106761),\n", " (u'currents', 1.5722781569106761),\n", " (u'daguerreotype', 1.5722781569106761),\n", " (u'disclaimer', 1.5722781569106761),\n", " (u'email', 1.5722781569106761),\n", " (u'enrolled', 1.5722781569106761),\n", " (u'fool', 1.5722781569106761),\n", " (u'guineas', 1.5722781569106761),\n", " (u'hatchet', 1.5722781569106761),\n", " (u'instruct', 1.5722781569106761),\n", " (u'liability', 1.5722781569106761),\n", " (u'lonny', 1.5722781569106761),\n", " (u'paullin', 1.5722781569106761),\n", " (u'performing', 1.5722781569106761),\n", " (u'plow', 1.5722781569106761),\n", " (u'polite', 1.5722781569106761),\n", " (u'puffs', 1.5722781569106761),\n", " (u'rulings', 1.5722781569106761),\n", " (u'scammon', 1.5722781569106761),\n", " (u'tilda', 1.5722781569106761),\n", " (u'wake', 1.5722781569106761),\n", " (u'warranties', 1.5722781569106761),\n", " (u'america', 1.5712271378967728),\n", " (u'clair', 1.5712271378967728),\n", " (u'displaying', 1.5712271378967728),\n", " (u'forgery', 1.5712271378967728),\n", " (u'holder', 1.5712271378967728),\n", " (u'posted', 1.5712271378967728),\n", " (u'sketches', 1.5712271378967728),\n", " (u'snow', 1.5712271378967728),\n", " (u'wore', 1.5712271378967728),\n", " (u'http', 1.5645865830262038),\n", " (u'journalism', 1.5399471126066209),\n", " (u'copy', 1.5258495075146912),\n", " (u'_early', 1.5202411939312348),\n", " (u'armstrong', 1.5106440743450187),\n", " (u'railroad', 1.4938165623572677),\n", " (u'ross', 1.489097832809857),\n", " (u'pair', 1.4791112857988695),\n", " (u'banks', 1.4791112857988693),\n", " (u'irelan', 1.4791112857988693),\n", " (u'scott', 1.4791112857988693),\n", " (u'browne', 1.4764336408243595),\n", " (u'abraham', 1.4577679329151634),\n", " (u'publication', 1.4490612388306794),\n", " (u'provide', 1.4490612388306792),\n", " (u'chiniquy', 1.4275140308616106),\n", " (u'literary', 1.4150354420715021),\n", " (u'rr', 1.4070491486733681),\n", " (u'axe', 1.3967912341407889),\n", " (u'fence', 1.3967912341407889),\n", " (u'genuine', 1.3967912341407889),\n", " (u'life_', 1.3941370904272503),\n", " (u'she', 1.3923582867044937),\n", " (u'copper', 1.3828069220574104),\n", " (u'distributing', 1.3828069220574104),\n", " (u'saddle', 1.3828069220574104),\n", " (u'sons', 1.3828069220574104),\n", " (u'_life_', 1.373910241709706),\n", " (u'calhoun', 1.373910241709706),\n", " (u'mother', 1.3728688332198922),\n", " (u'college', 1.3697302821858961),\n", " (u'nicolay', 1.3633245760231363),\n", " (u'whitney', 1.3627575629840512),\n", " (u'philadelphia', 1.3540886863558637),\n", " (u'sarah', 1.3540886863558634),\n", " (u'vi', 1.3540886863558634),\n", " (u'harrison', 1.3476159735283106),\n", " (u'terms', 1.3426509824683515),\n", " (u'herndon', 1.3421892681433798),\n", " (u'improvement', 1.329344333012155),\n", " (u'buckskin', 1.3222046383294666),\n", " (u'sham', 1.3222046383294666),\n", " (u'fee', 1.3158554460066139),\n", " (u'generosity', 1.3144503596878891),\n", " (u'moore', 1.3144503596878887),\n", " (u'copies', 1.3127747798184011),\n", " (u'p', 1.309088202039181),\n", " (u'compliance', 1.2961309813666892),\n", " (u'constable', 1.2961309813666892),\n", " (u'currency', 1.2961309813666892),\n", " (u'distribution', 1.2961309813666892),\n", " (u'harvey', 1.2961309813666892),\n", " (u'individual', 1.2961309813666892),\n", " (u'revolutionary', 1.2961309813666892),\n", " (u'brooks', 1.286562189794501),\n", " (u'chicago', 1.2700186510810929),\n", " (u'weems', 1.2659709073661847),\n", " (u'february', 1.2574199029295277),\n", " (u'information', 1.2487001310514776),\n", " (u'bridge', 1.2326416539256813),\n", " (u'resolution', 1.2268390166084573),\n", " (u'stoddard', 1.2268390166084573),\n", " (u'father', 1.2254034208363418),\n", " (u'cartwright', 1.2157428532629155),\n", " (u'houghton', 1.2157428532629155),\n", " (u'publishing', 1.2157428532629155),\n", " (u'describes', 1.2157428532629153),\n", " (u'j', 1.2115310804189017),\n", " (u'_stories_', 1.2049337080807629),\n", " (u'september', 1.2030636155192291),\n", " (u'boys', 1.1974364414369618),\n", " (u'defendants', 1.1955861748361873),\n", " (u'per', 1.1955861748361873),\n", " (u'permission', 1.1955861748361873),\n", " (u'uncle', 1.1955861748361873),\n", " (u'thomas', 1.1924565577943991),\n", " (u'trade', 1.1918333507609624),\n", " (u'f', 1.1915163381561049),\n", " (u'store', 1.189052998865439),\n", " (u'notes', 1.1850922942502753),\n", " (u'baker', 1.1828856976412236),\n", " (u'baddeley', 1.1681694680548835),\n", " (u'cogdal', 1.1681694680548835),\n", " (u'copying', 1.1681694680548835),\n", " (u'crafton', 1.1681694680548835),\n", " (u'defect', 1.1681694680548835),\n", " (u'donate', 1.1681694680548835),\n", " (u'easier', 1.1681694680548835),\n", " (u'editions', 1.1681694680548835),\n", " (u'hawley', 1.1681694680548835),\n", " (u'hitchcock', 1.1681694680548835),\n", " (u'jake', 1.1681694680548835),\n", " (u'jewelry', 1.1681694680548835),\n", " (u'jurors', 1.1681694680548835),\n", " (u'lightning', 1.1681694680548835),\n", " (u'machine', 1.1681694680548835),\n", " (u'paragraphs', 1.1681694680548835),\n", " (u'pg', 1.1681694680548835),\n", " (u'pork', 1.1681694680548835),\n", " (u'retains', 1.1681694680548835),\n", " (u'rod', 1.1681694680548835),\n", " (u'securities', 1.1681694680548835),\n", " (u'status', 1.1681694680548835),\n", " (u'trousers', 1.1681694680548835),\n", " (u'unpublished', 1.1681694680548835),\n", " (u'berry', 1.1644932670010606),\n", " (u'pp', 1.1608077284905565),\n", " (u'hanks', 1.1587285139891437),\n", " (u'mcclure', 1.1537352404836496),\n", " (u'her', 1.1531891574151381),\n", " (u'hamlin', 1.1529222466025137),\n", " (u'speeches', 1.1437050469373577),\n", " (u'kentucky', 1.1401563236722736),\n", " (u'johnston', 1.1368073989967304),\n", " (u'offutt', 1.1345503657246403),\n", " (u'dress', 1.1343080503770544),\n", " (u'german', 1.1343080503770544),\n", " (u'matheney', 1.1343080503770544),\n", " (u'company', 1.1298148326748745),\n", " (u'g', 1.128517881924167),\n", " (u'votes', 1.1187730676938106),\n", " (u'nine', 1.113374076177045),\n", " (u'charles', 1.1065580194728426),\n", " (u'note', 1.0974655406391749),\n", " (u'deed', 1.0970926363431248),\n", " (u'east', 1.0970926363431248),\n", " (u'spurious', 1.0970926363431248),\n", " (u'atkinson', 1.0970926363431244),\n", " (u'comply', 1.0970926363431244),\n", " (u'jewelers', 1.0970926363431244),\n", " (u'leland', 1.0970926363431244),\n", " (u'priest', 1.0970926363431244),\n", " (u'soldier', 1.0970926363431244),\n", " (u'd', 1.0936709970367389),\n", " (u'tax', 1.0890978328098568),\n", " (u'colonel', 1.0886122317272675),\n", " (u'pitcher', 1.0886122317272675),\n", " (u'spink', 1.0886122317272675),\n", " (u'charter', 1.0886122317272673),\n", " (u'clock', 1.0886122317272673),\n", " (u'distribute', 1.0886122317272673),\n", " (u'fisher', 1.0886122317272673),\n", " (u'convention', 1.0842245322470756),\n", " (u'plaintiff', 1.0813648643938589),\n", " (u'island', 1.0791112857988696),\n", " (u'voyage', 1.0772490318253176),\n", " (u'you', 1.0716742799027257),\n", " (u'road', 1.0587290524017576),\n", " (u'holland', 1.05373524048365),\n", " (u'trailor', 1.0479900750043671),\n", " (u'limited', 1.0447190713617185),\n", " (u'domain', 1.0399471126066209),\n", " (u'grandfather', 1.0399471126066209),\n", " (u'voted', 1.0399471126066209),\n", " (u'agree', 1.0367857078081339),\n", " (u'including', 1.0367857078081339),\n", " (u'life', 1.0279778291629844),\n", " (u'witness', 1.0249646422762066),\n", " (u'james', 1.0153080476245506),\n", " (u'stuart', 1.0149104889383316),\n", " (u'dungee', 1.0102738780733427),\n", " (u'john', 1.0074378828094916),\n", " (u'surveyor', 1.0071083505332288),\n", " (u'cross', 1.0008479040802145),\n", " (u'dollars', 1.0002448365299736)]" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mz_keywords(text,scores=True,weighted=False,threshold=1.0)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "When this option is used, it is possible to calculate a threshold automatically from the number of blocks" ] }, { "cell_type": "code", "execution_count": 13, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "[(u'gutenberg', 3.7766363961259684),\n", " (u'tm', 3.6403066998316511),\n", " (u'project', 3.5428530523255342),\n", " (u'co', 3.2983688146004528),\n", " (u'donations', 2.8613536046553563),\n", " (u'electronic', 2.8210861922674084),\n", " (u'access', 2.7810662866642568),\n", " (u'refund', 2.7810662866642568),\n", " (u'foundation', 2.7234464816769872),\n", " (u'foxboro', 2.5477601487545121),\n", " (u'gloves', 2.5281337853661761),\n", " (u'e', 2.4036269322210768),\n", " (u'york', 2.3692008259770594),\n", " (u'edited', 2.361641829495754),\n", " (u'_works_', 2.3445174072327686),\n", " (u'works', 2.3426500474551113),\n", " (u'dogskin', 2.3425994588269479),\n", " (u'ragsdale', 2.2931552327841351),\n", " (u'replacement', 2.2931552327841351),\n", " (u'trunks', 2.2931552327841351),\n", " (u'iv', 2.2510299269025058),\n", " (u'iii', 2.2186807817292546),\n", " (u'v', 2.2168420707754368),\n", " (u'brokaw', 2.1699176369612583),\n", " (u'coon', 2.1699176369612583),\n", " (u'bonds', 2.1343080503770544),\n", " (u'license', 2.1009287665795293),\n", " (u'ii', 2.0892470886183649),\n", " (u'agreement', 2.0779209847210556),\n", " (u'almanac', 2.0060727272918055),\n", " (u'_weekly_', 1.9794475925140163),\n", " (u'bounded', 1.9794475925140163),\n", " (u'format', 1.9794475925140163),\n", " (u'millions', 1.9794475925140163),\n", " (u'oxen', 1.9794475925140163),\n", " (u'specie', 1.9794475925140163),\n", " (u'archive', 1.9682995275030786),\n", " (u'barrett', 1.9422319940872796),\n", " (u'reminiscences', 1.9330537427622287),\n", " (u'ebooks', 1.8984698469769548),\n", " (u'forquer', 1.8843080503770544),\n", " (u'parker', 1.8843080503770544),\n", " (u'pglaf', 1.8843080503770544),\n", " (u'ebook', 1.8838775575675983),\n", " (u'trademark', 1.8838775575675983),\n", " (u'paragraph', 1.8301079379685583),\n", " (u'hardin', 1.7669683658081703),\n", " (u'work', 1.7328354724344326),\n", " (u'rothschild', 1.7275730939964973),\n", " (u'org', 1.7211393195188851),\n", " (u'attitude', 1.716230650790012),\n", " (u'london', 1.6791112857988695),\n", " (u'boston', 1.6754810009833907),\n", " (u'xvi', 1.66018729770736),\n", " (u'news', 1.6601872977073597),\n", " (u'biographical', 1.6294643147000225),\n", " (u'green', 1.6254512602292723),\n", " (u'delegates', 1.6127555612626692),\n", " (u'medium', 1.6127555612626692),\n", " (u'scripps', 1.6127555612626692),\n", " (u'volunteers', 1.6127555612626692),\n", " (u'lamon', 1.6001560607245646),\n", " (u'tarbell', 1.5897346234235084),\n", " (u'volumes', 1.5819481863246514),\n", " (u'bank', 1.5744728128489647),\n", " (u'copyright', 1.5731550611734115),\n", " (u'_via_', 1.5722781569106761),\n", " (u'admissibility', 1.5722781569106761),\n", " (u'advertisers', 1.5722781569106761),\n", " (u'applicable', 1.5722781569106761),\n", " (u'attire', 1.5722781569106761),\n", " (u'bags', 1.5722781569106761),\n", " (u'berries', 1.5722781569106761),\n", " (u'breeches', 1.5722781569106761),\n", " (u'cline', 1.5722781569106761),\n", " (u'continuance', 1.5722781569106761),\n", " (u'currents', 1.5722781569106761),\n", " (u'daguerreotype', 1.5722781569106761),\n", " (u'disclaimer', 1.5722781569106761),\n", " (u'email', 1.5722781569106761),\n", " (u'enrolled', 1.5722781569106761),\n", " (u'fool', 1.5722781569106761),\n", " (u'guineas', 1.5722781569106761),\n", " (u'hatchet', 1.5722781569106761),\n", " (u'instruct', 1.5722781569106761),\n", " (u'liability', 1.5722781569106761),\n", " (u'lonny', 1.5722781569106761),\n", " (u'paullin', 1.5722781569106761),\n", " (u'performing', 1.5722781569106761),\n", " (u'plow', 1.5722781569106761),\n", " (u'polite', 1.5722781569106761),\n", " (u'puffs', 1.5722781569106761),\n", " (u'rulings', 1.5722781569106761),\n", " (u'scammon', 1.5722781569106761),\n", " (u'tilda', 1.5722781569106761),\n", " (u'wake', 1.5722781569106761),\n", " (u'warranties', 1.5722781569106761),\n", " (u'america', 1.5712271378967728),\n", " (u'clair', 1.5712271378967728),\n", " (u'displaying', 1.5712271378967728),\n", " (u'forgery', 1.5712271378967728),\n", " (u'holder', 1.5712271378967728),\n", " (u'posted', 1.5712271378967728),\n", " (u'sketches', 1.5712271378967728),\n", " (u'snow', 1.5712271378967728),\n", " (u'wore', 1.5712271378967728),\n", " (u'http', 1.5645865830262038),\n", " (u'journalism', 1.5399471126066209),\n", " (u'copy', 1.5258495075146912),\n", " (u'_early', 1.5202411939312348),\n", " (u'armstrong', 1.5106440743450187),\n", " (u'railroad', 1.4938165623572677),\n", " (u'ross', 1.489097832809857),\n", " (u'pair', 1.4791112857988695),\n", " (u'banks', 1.4791112857988693),\n", " (u'irelan', 1.4791112857988693),\n", " (u'scott', 1.4791112857988693),\n", " (u'browne', 1.4764336408243595),\n", " (u'abraham', 1.4577679329151634),\n", " (u'publication', 1.4490612388306794),\n", " (u'provide', 1.4490612388306792),\n", " (u'chiniquy', 1.4275140308616106),\n", " (u'literary', 1.4150354420715021),\n", " (u'rr', 1.4070491486733681),\n", " (u'axe', 1.3967912341407889),\n", " (u'fence', 1.3967912341407889),\n", " (u'genuine', 1.3967912341407889),\n", " (u'life_', 1.3941370904272503),\n", " (u'she', 1.3923582867044937),\n", " (u'copper', 1.3828069220574104),\n", " (u'distributing', 1.3828069220574104),\n", " (u'saddle', 1.3828069220574104),\n", " (u'sons', 1.3828069220574104),\n", " (u'_life_', 1.373910241709706),\n", " (u'calhoun', 1.373910241709706),\n", " (u'mother', 1.3728688332198922),\n", " (u'college', 1.3697302821858961),\n", " (u'nicolay', 1.3633245760231363),\n", " (u'whitney', 1.3627575629840512),\n", " (u'philadelphia', 1.3540886863558637),\n", " (u'sarah', 1.3540886863558634),\n", " (u'vi', 1.3540886863558634),\n", " (u'harrison', 1.3476159735283106),\n", " (u'terms', 1.3426509824683515),\n", " (u'herndon', 1.3421892681433798),\n", " (u'improvement', 1.329344333012155),\n", " (u'buckskin', 1.3222046383294666),\n", " (u'sham', 1.3222046383294666),\n", " (u'fee', 1.3158554460066139),\n", " (u'generosity', 1.3144503596878891),\n", " (u'moore', 1.3144503596878887),\n", " (u'copies', 1.3127747798184011),\n", " (u'p', 1.309088202039181),\n", " (u'compliance', 1.2961309813666892),\n", " (u'constable', 1.2961309813666892),\n", " (u'currency', 1.2961309813666892),\n", " (u'distribution', 1.2961309813666892),\n", " (u'harvey', 1.2961309813666892),\n", " (u'individual', 1.2961309813666892),\n", " (u'revolutionary', 1.2961309813666892),\n", " (u'brooks', 1.286562189794501),\n", " (u'chicago', 1.2700186510810929),\n", " (u'weems', 1.2659709073661847),\n", " (u'february', 1.2574199029295277),\n", " (u'information', 1.2487001310514776),\n", " (u'bridge', 1.2326416539256813),\n", " (u'resolution', 1.2268390166084573),\n", " (u'stoddard', 1.2268390166084573),\n", " (u'father', 1.2254034208363418),\n", " (u'cartwright', 1.2157428532629155),\n", " (u'houghton', 1.2157428532629155),\n", " (u'publishing', 1.2157428532629155),\n", " (u'describes', 1.2157428532629153),\n", " (u'j', 1.2115310804189017),\n", " (u'_stories_', 1.2049337080807629),\n", " (u'september', 1.2030636155192291),\n", " (u'boys', 1.1974364414369618),\n", " (u'defendants', 1.1955861748361873),\n", " (u'per', 1.1955861748361873),\n", " (u'permission', 1.1955861748361873),\n", " (u'uncle', 1.1955861748361873),\n", " (u'thomas', 1.1924565577943991),\n", " (u'trade', 1.1918333507609624),\n", " (u'f', 1.1915163381561049),\n", " (u'store', 1.189052998865439),\n", " (u'notes', 1.1850922942502753),\n", " (u'baker', 1.1828856976412236),\n", " (u'baddeley', 1.1681694680548835),\n", " (u'cogdal', 1.1681694680548835),\n", " (u'copying', 1.1681694680548835),\n", " (u'crafton', 1.1681694680548835),\n", " (u'defect', 1.1681694680548835),\n", " (u'donate', 1.1681694680548835),\n", " (u'easier', 1.1681694680548835),\n", " (u'editions', 1.1681694680548835),\n", " (u'hawley', 1.1681694680548835),\n", " (u'hitchcock', 1.1681694680548835),\n", " (u'jake', 1.1681694680548835),\n", " (u'jewelry', 1.1681694680548835),\n", " (u'jurors', 1.1681694680548835),\n", " (u'lightning', 1.1681694680548835),\n", " (u'machine', 1.1681694680548835),\n", " (u'paragraphs', 1.1681694680548835),\n", " (u'pg', 1.1681694680548835),\n", " (u'pork', 1.1681694680548835),\n", " (u'retains', 1.1681694680548835),\n", " (u'rod', 1.1681694680548835),\n", " (u'securities', 1.1681694680548835),\n", " (u'status', 1.1681694680548835),\n", " (u'trousers', 1.1681694680548835),\n", " (u'unpublished', 1.1681694680548835),\n", " (u'berry', 1.1644932670010606),\n", " (u'pp', 1.1608077284905565),\n", " (u'hanks', 1.1587285139891437),\n", " (u'mcclure', 1.1537352404836496),\n", " (u'her', 1.1531891574151381),\n", " (u'hamlin', 1.1529222466025137),\n", " (u'speeches', 1.1437050469373577),\n", " (u'kentucky', 1.1401563236722736),\n", " (u'johnston', 1.1368073989967304),\n", " (u'offutt', 1.1345503657246403),\n", " (u'dress', 1.1343080503770544),\n", " (u'german', 1.1343080503770544),\n", " (u'matheney', 1.1343080503770544),\n", " (u'company', 1.1298148326748745),\n", " (u'g', 1.128517881924167),\n", " (u'votes', 1.1187730676938106),\n", " (u'nine', 1.113374076177045),\n", " (u'charles', 1.1065580194728426),\n", " (u'note', 1.0974655406391749),\n", " (u'deed', 1.0970926363431248),\n", " (u'east', 1.0970926363431248),\n", " (u'spurious', 1.0970926363431248),\n", " (u'atkinson', 1.0970926363431244),\n", " (u'comply', 1.0970926363431244),\n", " (u'jewelers', 1.0970926363431244),\n", " (u'leland', 1.0970926363431244),\n", " (u'priest', 1.0970926363431244),\n", " (u'soldier', 1.0970926363431244),\n", " (u'd', 1.0936709970367389),\n", " (u'tax', 1.0890978328098568),\n", " (u'colonel', 1.0886122317272675),\n", " (u'pitcher', 1.0886122317272675),\n", " (u'spink', 1.0886122317272675),\n", " (u'charter', 1.0886122317272673),\n", " (u'clock', 1.0886122317272673),\n", " (u'distribute', 1.0886122317272673),\n", " (u'fisher', 1.0886122317272673),\n", " (u'convention', 1.0842245322470756),\n", " (u'plaintiff', 1.0813648643938589),\n", " (u'island', 1.0791112857988696),\n", " (u'voyage', 1.0772490318253176),\n", " (u'you', 1.0716742799027257),\n", " (u'road', 1.0587290524017576),\n", " (u'holland', 1.05373524048365),\n", " (u'trailor', 1.0479900750043671),\n", " (u'limited', 1.0447190713617185),\n", " (u'domain', 1.0399471126066209),\n", " (u'grandfather', 1.0399471126066209),\n", " (u'voted', 1.0399471126066209),\n", " (u'agree', 1.0367857078081339),\n", " (u'including', 1.0367857078081339),\n", " (u'life', 1.0279778291629844),\n", " (u'witness', 1.0249646422762066),\n", " (u'james', 1.0153080476245506),\n", " (u'stuart', 1.0149104889383316),\n", " (u'dungee', 1.0102738780733427),\n", " (u'john', 1.0074378828094916),\n", " (u'surveyor', 1.0071083505332288),\n", " (u'cross', 1.0008479040802145),\n", " (u'dollars', 1.0002448365299736),\n", " (u'president', 0.99828026284480487),\n", " (u'_amount_', 0.99450922395310026),\n", " (u'_black', 0.99450922395310026),\n", " (u'_commercial', 0.99450922395310026),\n", " (u'_magazine', 0.99450922395310026),\n", " (u'_nicolay', 0.99450922395310026),\n", " (u'_north', 0.99450922395310026),\n", " (u'_sun_', 0.99450922395310026),\n", " (u'accompanies', 0.99450922395310026),\n", " (u'accordance', 0.99450922395310026),\n", " (u'adjourning', 0.99450922395310026),\n", " (u'advertiser', 0.99450922395310026),\n", " (u'advertiser_', 0.99450922395310026),\n", " (u'agnosticism', 0.99450922395310026),\n", " (u'almanacs', 0.99450922395310026),\n", " (u'animals', 0.99450922395310026),\n", " (u'apparel', 0.99450922395310026),\n", " (u'appoints', 0.99450922395310026),\n", " (u'arbitrations', 0.99450922395310026),\n", " (u'ascii', 0.99450922395310026),\n", " (u'asks', 0.99450922395310026),\n", " (u'aspirants', 0.99450922395310026),\n", " (u'atrocious', 0.99450922395310026),\n", " (u'attachment', 0.99450922395310026),\n", " (u'authors', 0.99450922395310026),\n", " (u'band', 0.99450922395310026),\n", " (u'bargained', 0.99450922395310026),\n", " (u'bets', 0.99450922395310026),\n", " (u'bleeding', 0.99450922395310026),\n", " (u'boats', 0.99450922395310026),\n", " (u'book_', 0.99450922395310026),\n", " (u'boss', 0.99450922395310026),\n", " (u'bourgeois', 0.99450922395310026),\n", " (u'bull', 0.99450922395310026),\n", " (u'calf', 0.99450922395310026),\n", " (u'chase', 0.99450922395310026),\n", " (u'chicanery', 0.99450922395310026),\n", " (u'coach', 0.99450922395310026),\n", " (u'coins', 0.99450922395310026),\n", " (u'comet', 0.99450922395310026),\n", " (u'computer', 0.99450922395310026),\n", " (u'computers', 0.99450922395310026),\n", " (u'concentration', 0.99450922395310026),\n", " (u'conquering', 0.99450922395310026),\n", " (u'conservator', 0.99450922395310026),\n", " (u'contentedly', 0.99450922395310026),\n", " (u'copied', 0.99450922395310026),\n", " (u'cord', 0.99450922395310026),\n", " (u'cornell', 0.99450922395310026),\n", " (u'countenance', 0.99450922395310026),\n", " (u'counting', 0.99450922395310026),\n", " (u'countryman', 0.99450922395310026),\n", " (u'creeks', 0.99450922395310026),\n", " (u'davy', 0.99450922395310026),\n", " (u'deer', 0.99450922395310026),\n", " (u'def', 0.99450922395310026),\n", " (u'delegations', 0.99450922395310026),\n", " (u'deliveries', 0.99450922395310026),\n", " (u'demurrer', 0.99450922395310026),\n", " (u'desires', 0.99450922395310026),\n", " (u'detriment', 0.99450922395310026),\n", " (u'directors', 0.99450922395310026),\n", " (u'disallows', 0.99450922395310026),\n", " (u'disgracing', 0.99450922395310026),\n", " (u'doctoring', 0.99450922395310026),\n", " (u'effectively', 0.99450922395310026),\n", " (u'elections', 0.99450922395310026),\n", " (u'electronically', 0.99450922395310026),\n", " (u'enrolling', 0.99450922395310026),\n", " (u'exempt', 0.99450922395310026),\n", " (u'faded', 0.99450922395310026),\n", " (u'fares', 0.99450922395310026),\n", " (u'ff', 0.99450922395310026),\n", " (u'fights', 0.99450922395310026),\n", " (u'flatboat', 0.99450922395310026),\n", " (u'founded', 0.99450922395310026),\n", " (u'generals', 0.99450922395310026),\n", " (u'goose', 0.99450922395310026),\n", " (u'greed', 0.99450922395310026),\n", " (u'groomsman', 0.99450922395310026),\n", " (u'hagerty', 0.99450922395310026),\n", " (u'hans', 0.99450922395310026),\n", " (u'harvard', 0.99450922395310026),\n", " (u'haute', 0.99450922395310026),\n", " (u'heel', 0.99450922395310026),\n", " (u'history_', 0.99450922395310026),\n", " (u'homeliest', 0.99450922395310026),\n", " (u'howard', 0.99450922395310026),\n", " (u'hut', 0.99450922395310026),\n", " (u'ice', 0.99450922395310026),\n", " (u'ida', 0.99450922395310026),\n", " (u'identical', 0.99450922395310026),\n", " (u'imperialist', 0.99450922395310026),\n", " (u'independent', 0.99450922395310026),\n", " (u'invalid', 0.99450922395310026),\n", " (u'irons', 0.99450922395310026),\n", " (u'janet', 0.99450922395310026),\n", " (u'justification', 0.99450922395310026),\n", " (u'lamborn', 0.99450922395310026),\n", " (u'lambs', 0.99450922395310026),\n", " (u'larceny', 0.99450922395310026),\n", " (u'latin', 0.99450922395310026),\n", " (u'linen', 0.99450922395310026),\n", " (u'locations', 0.99450922395310026),\n", " (u'louder', 0.99450922395310026),\n", " (u'mad', 0.99450922395310026),\n", " (u'magruder', 0.99450922395310026),\n", " (u'maid', 0.99450922395310026),\n", " (u'metaphysical', 0.99450922395310026),\n", " (u'mit', 0.99450922395310026),\n", " (u'monthlies', 0.99450922395310026),\n", " (u'nest', 0.99450922395310026),\n", " (u'nigger', 0.99450922395310026),\n", " (u'package', 0.99450922395310026),\n", " (u'pan', 0.99450922395310026),\n", " (u'parentage', 0.99450922395310026),\n", " (u'partial', 0.99450922395310026),\n", " (u'partly', 0.99450922395310026),\n", " (u'passengers', 0.99450922395310026),\n", " (u'pension', 0.99450922395310026),\n", " (u'pl', 0.99450922395310026),\n", " (u'playful', 0.99450922395310026),\n", " (u'population', 0.99450922395310026),\n", " (u'postponed', 0.99450922395310026),\n", " (u'postponement', 0.99450922395310026),\n", " (u'premise', 0.99450922395310026),\n", " (u'pressure', 0.99450922395310026),\n", " (u'presumption', 0.99450922395310026),\n", " (u'preventing', 0.99450922395310026),\n", " (u'quart', 0.99450922395310026),\n", " (u'quincy', 0.99450922395310026),\n", " (u'quorum', 0.99450922395310026),\n", " (u'redistribution', 0.99450922395310026),\n", " (u'rejoicing', 0.99450922395310026),\n", " (u'remit', 0.99450922395310026),\n", " (u'rifle', 0.99450922395310026),\n", " (u'romance', 0.99450922395310026),\n", " (u'rothschild_', 0.99450922395310026),\n", " (u'row', 0.99450922395310026),\n", " (u'rubbish', 0.99450922395310026),\n", " (u'sacrifices', 0.99450922395310026),\n", " (u'scroll', 0.99450922395310026),\n", " (u'shade', 0.99450922395310026),\n", " (u'shed', 0.99450922395310026),\n", " (u'sigh', 0.99450922395310026),\n", " (u'silk', 0.99450922395310026),\n", " (u'sinewy', 0.99450922395310026),\n", " (u'sock', 0.99450922395310026),\n", " (u'solicit', 0.99450922395310026),\n", " (u'solvent', 0.99450922395310026),\n", " (u'sonny', 0.99450922395310026),\n", " (u'startling', 0.99450922395310026),\n", " (u'steals', 0.99450922395310026),\n", " (u'steamer', 0.99450922395310026),\n", " (u'stevenson', 0.99450922395310026),\n", " (u'subp\\u0153naed', 0.99450922395310026),\n", " (u'tanned', 0.99450922395310026),\n", " (u'tea', 0.99450922395310026),\n", " (u'terre', 0.99450922395310026),\n", " (u'theosophy', 0.99450922395310026),\n", " (u'tight', 0.99450922395310026),\n", " (u'tis', 0.99450922395310026),\n", " (u'tour', 0.99450922395310026),\n", " (u'vanilla', 0.99450922395310026),\n", " (u'vol', 0.99450922395310026),\n", " (u'warfare', 0.99450922395310026),\n", " (u'warranty', 0.99450922395310026),\n", " (u'wayne', 0.99450922395310026),\n", " (u'whip', 0.99450922395310026),\n", " (u'woodcut', 0.99450922395310026),\n", " (u'wright', 0.99450922395310026),\n", " (u'new', 0.99212250974463601)]" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mz_keywords(text,scores=True,weighted=False,threshold=\"auto\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The complexity of the algorithm is **O**(*Nw*), where *N* is the number of words in the document and *w* is the number of unique words." ] } ], "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.12" } }, "nbformat": 4, "nbformat_minor": 0 }