Skip to content

Commit aa1a31f

Browse files
antmarakisnorvig
authored andcommitted
Update text.ipynb (aimacode#644)
1 parent 8475f03 commit aa1a31f

File tree

1 file changed

+34
-73
lines changed

1 file changed

+34
-73
lines changed

text.ipynb

Lines changed: 34 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"outputs": [],
1919
"source": [
2020
"from text import *\n",
21-
"from utils import open_data"
21+
"from utils import open_data\n",
22+
"from notebook import psource"
2223
]
2324
},
2425
{
@@ -55,46 +56,11 @@
5556
},
5657
{
5758
"cell_type": "code",
58-
"execution_count": 2,
59-
"metadata": {
60-
"collapsed": true
61-
},
62-
"outputs": [],
63-
"source": [
64-
"%psource UnigramWordModel"
65-
]
66-
},
67-
{
68-
"cell_type": "code",
69-
"execution_count": 3,
70-
"metadata": {
71-
"collapsed": true
72-
},
73-
"outputs": [],
74-
"source": [
75-
"%psource NgramWordModel"
76-
]
77-
},
78-
{
79-
"cell_type": "code",
80-
"execution_count": 4,
81-
"metadata": {
82-
"collapsed": true
83-
},
84-
"outputs": [],
85-
"source": [
86-
"%psource UnigramCharModel"
87-
]
88-
},
89-
{
90-
"cell_type": "code",
91-
"execution_count": 6,
92-
"metadata": {
93-
"collapsed": true
94-
},
59+
"execution_count": null,
60+
"metadata": {},
9561
"outputs": [],
9662
"source": [
97-
"%psource NgramCharModel"
63+
"psource(UnigramWordModel, NgramWordModel, UnigramCharModel, NgramCharModel)"
9864
]
9965
},
10066
{
@@ -117,7 +83,7 @@
11783
},
11884
{
11985
"cell_type": "code",
120-
"execution_count": 8,
86+
"execution_count": 2,
12187
"metadata": {},
12288
"outputs": [
12389
{
@@ -156,18 +122,18 @@
156122
},
157123
{
158124
"cell_type": "code",
159-
"execution_count": 12,
125+
"execution_count": 3,
160126
"metadata": {},
161127
"outputs": [
162128
{
163129
"name": "stdout",
164130
"output_type": "stream",
165131
"text": [
166-
"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",
132+
"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",
167133
"\n",
168134
"Conditional Probability of 'once' give 'i was': 0.05128205128205128 \n",
169135
"\n",
170-
"Next word after 'i was': not\n"
136+
"Next word after 'i was': wearied\n"
171137
]
172138
}
173139
],
@@ -198,7 +164,7 @@
198164
},
199165
{
200166
"cell_type": "code",
201-
"execution_count": 3,
167+
"execution_count": 4,
202168
"metadata": {},
203169
"outputs": [
204170
{
@@ -246,16 +212,16 @@
246212
},
247213
{
248214
"cell_type": "code",
249-
"execution_count": 4,
215+
"execution_count": 5,
250216
"metadata": {},
251217
"outputs": [
252218
{
253219
"name": "stdout",
254220
"output_type": "stream",
255221
"text": [
256-
"not it of before most regions multitudes the a three\n",
257-
"the inhabitants of so also refers to the cube with\n",
258-
"the service of education waxed daily more numerous than the\n"
222+
"hearing as inside is confined to conduct by the duties\n",
223+
"all and of voice being in a day of the\n",
224+
"party they are stirred to mutual warfare and perish by\n"
259225
]
260226
}
261227
],
@@ -283,23 +249,22 @@
283249
},
284250
{
285251
"cell_type": "code",
286-
"execution_count": 19,
252+
"execution_count": 6,
287253
"metadata": {},
288254
"outputs": [
289255
{
290256
"name": "stdout",
291257
"output_type": "stream",
292258
"text": [
293-
"it again stealing away through the ranks of his nephew but he laughed most immoderately\n",
294-
"exclaiming that he henceforth exchanged them for the artist s pencil how great and glorious\n",
295-
"compound now for nothing worse but however all that is quite out of the question\n",
296-
"accordance with precedent and for the sake of secrecy he must condemn him to perpetual\n"
259+
"leave them at cleveland this christmas now pray do not ask you to relate or\n",
260+
"meaning and both of us sprang forward in the direction and no sooner had they\n",
261+
"palmer though very unwilling to go as well from real humanity and good nature as\n",
262+
"time about what they should do and they agreed he should take orders directly and\n"
297263
]
298264
}
299265
],
300266
"source": [
301267
"data = open_data(\"EN-text/flatland.txt\").read()\n",
302-
"data += open_data(\"EN-text/gutenberg.txt\").read()\n",
303268
"data += open_data(\"EN-text/sense.txt\").read()\n",
304269
"\n",
305270
"wordseq = words(data)\n",
@@ -344,13 +309,11 @@
344309
},
345310
{
346311
"cell_type": "code",
347-
"execution_count": 3,
348-
"metadata": {
349-
"collapsed": true
350-
},
312+
"execution_count": null,
313+
"metadata": {},
351314
"outputs": [],
352315
"source": [
353-
"%psource viterbi_segment"
316+
"psource(viterbi_segment)"
354317
]
355318
},
356319
{
@@ -373,7 +336,7 @@
373336
},
374337
{
375338
"cell_type": "code",
376-
"execution_count": 4,
339+
"execution_count": 3,
377340
"metadata": {},
378341
"outputs": [
379342
{
@@ -388,7 +351,7 @@
388351
"source": [
389352
"flatland = open_data(\"EN-text/flatland.txt\").read()\n",
390353
"wordseq = words(flatland)\n",
391-
"P = UnigramTextModel(wordseq)\n",
354+
"P = UnigramWordModel(wordseq)\n",
392355
"text = \"itiseasytoreadwordswithoutspaces\"\n",
393356
"\n",
394357
"s, p = viterbi_segment(text,P)\n",
@@ -447,7 +410,7 @@
447410
},
448411
"outputs": [],
449412
"source": [
450-
"%psource IRSystem"
413+
"psource(IRSystem)"
451414
]
452415
},
453416
{
@@ -490,7 +453,7 @@
490453
},
491454
"outputs": [],
492455
"source": [
493-
"%psource UnixConsultant"
456+
"psource(UnixConsultant)"
494457
]
495458
},
496459
{
@@ -504,7 +467,7 @@
504467
},
505468
{
506469
"cell_type": "code",
507-
"execution_count": 9,
470+
"execution_count": 4,
508471
"metadata": {},
509472
"outputs": [
510473
{
@@ -533,7 +496,7 @@
533496
},
534497
{
535498
"cell_type": "code",
536-
"execution_count": 10,
499+
"execution_count": 5,
537500
"metadata": {},
538501
"outputs": [
539502
{
@@ -628,7 +591,7 @@
628591
},
629592
{
630593
"cell_type": "code",
631-
"execution_count": 5,
594+
"execution_count": 6,
632595
"metadata": {},
633596
"outputs": [
634597
{
@@ -656,7 +619,7 @@
656619
},
657620
{
658621
"cell_type": "code",
659-
"execution_count": 6,
622+
"execution_count": 7,
660623
"metadata": {},
661624
"outputs": [
662625
{
@@ -748,13 +711,11 @@
748711
},
749712
{
750713
"cell_type": "code",
751-
"execution_count": 10,
752-
"metadata": {
753-
"collapsed": true
754-
},
714+
"execution_count": null,
715+
"metadata": {},
755716
"outputs": [],
756717
"source": [
757-
"%psource PermutationDecoder"
718+
"psource(PermutationDecoder)"
758719
]
759720
},
760721
{
@@ -811,7 +772,7 @@
811772
"name": "python",
812773
"nbconvert_exporter": "python",
813774
"pygments_lexer": "ipython3",
814-
"version": "3.5.2+"
775+
"version": "3.5.3"
815776
}
816777
},
817778
"nbformat": 4,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy