Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Update Text Notebook #644

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 4, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 34 additions & 73 deletions text.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"outputs": [],
"source": [
"from text import *\n",
"from utils import open_data"
"from utils import open_data\n",
"from notebook import psource"
]
},
{
Expand Down Expand Up @@ -55,46 +56,11 @@
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"%psource UnigramWordModel"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"%psource NgramWordModel"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"%psource UnigramCharModel"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": true
},
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%psource NgramCharModel"
"psource(UnigramWordModel, NgramWordModel, UnigramCharModel, NgramCharModel)"
]
},
{
Expand All @@ -117,7 +83,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 2,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -156,18 +122,18 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Conditional Probabilities Table: {'myself': 1, 'to': 2, 'at': 2, 'pleased': 1, 'considered': 1, 'will': 1, 'intoxicated': 1, 'glad': 1, 'certain': 2, 'in': 2, 'now': 2, 'sitting': 1, 'unusually': 1, 'approaching': 1, 'by': 1, 'covered': 1, 'standing': 1, 'allowed': 1, 'surprised': 1, 'keenly': 1, 'afraid': 1, 'once': 2, 'crushed': 1, 'not': 4, 'rapt': 1, 'simulating': 1, 'rapidly': 1, 'quite': 1, 'describing': 1, 'wearied': 1} \n",
"Conditional Probabilities Table: {'now': 2, 'glad': 1, 'keenly': 1, 'considered': 1, 'once': 2, 'not': 4, 'in': 2, 'by': 1, 'simulating': 1, 'intoxicated': 1, 'wearied': 1, 'quite': 1, 'certain': 2, 'sitting': 1, 'to': 2, 'rapidly': 1, 'will': 1, 'describing': 1, 'allowed': 1, 'at': 2, 'afraid': 1, 'covered': 1, 'approaching': 1, 'standing': 1, 'myself': 1, 'surprised': 1, 'unusually': 1, 'rapt': 1, 'pleased': 1, 'crushed': 1} \n",
"\n",
"Conditional Probability of 'once' give 'i was': 0.05128205128205128 \n",
"\n",
"Next word after 'i was': not\n"
"Next word after 'i was': wearied\n"
]
}
],
Expand Down Expand Up @@ -198,7 +164,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 4,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -246,16 +212,16 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"not it of before most regions multitudes the a three\n",
"the inhabitants of so also refers to the cube with\n",
"the service of education waxed daily more numerous than the\n"
"hearing as inside is confined to conduct by the duties\n",
"all and of voice being in a day of the\n",
"party they are stirred to mutual warfare and perish by\n"
]
}
],
Expand Down Expand Up @@ -283,23 +249,22 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"it again stealing away through the ranks of his nephew but he laughed most immoderately\n",
"exclaiming that he henceforth exchanged them for the artist s pencil how great and glorious\n",
"compound now for nothing worse but however all that is quite out of the question\n",
"accordance with precedent and for the sake of secrecy he must condemn him to perpetual\n"
"leave them at cleveland this christmas now pray do not ask you to relate or\n",
"meaning and both of us sprang forward in the direction and no sooner had they\n",
"palmer though very unwilling to go as well from real humanity and good nature as\n",
"time about what they should do and they agreed he should take orders directly and\n"
]
}
],
"source": [
"data = open_data(\"EN-text/flatland.txt\").read()\n",
"data += open_data(\"EN-text/gutenberg.txt\").read()\n",
"data += open_data(\"EN-text/sense.txt\").read()\n",
"\n",
"wordseq = words(data)\n",
Expand Down Expand Up @@ -344,13 +309,11 @@
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": true
},
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%psource viterbi_segment"
"psource(viterbi_segment)"
]
},
{
Expand All @@ -373,7 +336,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 3,
"metadata": {},
"outputs": [
{
Expand All @@ -388,7 +351,7 @@
"source": [
"flatland = open_data(\"EN-text/flatland.txt\").read()\n",
"wordseq = words(flatland)\n",
"P = UnigramTextModel(wordseq)\n",
"P = UnigramWordModel(wordseq)\n",
"text = \"itiseasytoreadwordswithoutspaces\"\n",
"\n",
"s, p = viterbi_segment(text,P)\n",
Expand Down Expand Up @@ -447,7 +410,7 @@
},
"outputs": [],
"source": [
"%psource IRSystem"
"psource(IRSystem)"
]
},
{
Expand Down Expand Up @@ -490,7 +453,7 @@
},
"outputs": [],
"source": [
"%psource UnixConsultant"
"psource(UnixConsultant)"
]
},
{
Expand All @@ -504,7 +467,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 4,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -533,7 +496,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 5,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -628,7 +591,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 6,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -656,7 +619,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 7,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -748,13 +711,11 @@
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"collapsed": true
},
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%psource PermutationDecoder"
"psource(PermutationDecoder)"
]
},
{
Expand Down Expand Up @@ -811,7 +772,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.2+"
"version": "3.5.3"
}
},
"nbformat": 4,
Expand Down