quarta-feira, março 01, 2017

Markov Chains and Hamlet



Lately I've been feeling adventurous and that got me thinking programming-wise. Is it possible to write a play like Hamlet by using Markov Chains?

Yes! There's a cheating way of doing that by using Markov Chain text generator.

It works more or less like this:

1. Take some text as input (e.g., the complete works of Shakespeare).

2. For every distinct word in it, determine what words follow it, and with what frequency.

3. Pick a word to start with -- e.g., choose one at random from all the words that start sentences.

4. Randomly choose a word to follow it, using the frequencies found in step 2.

5. Randomly choose a word to follow that, again using the frequencies from step 2.

6. Carry on in this vein until you reach a predetermined length.

The result can be surprisingly convincing, but can also include utter gibberish.

You get better chances of getting intelligible output by

- increasing the amount of input text;

- in step 2, determining what words follow each distinct pair (or triplet, etc.) of words.

--- The Library is total and ... its shelves contain all the possible combinations of the 20-odd orthographic symbols ... that is, everything which can be expressed, in all languages.” ---

This is exactly what the Internet of the future will be, once the extraterrestrials all over the universe and our, and their, computers fill it up with every conceivable thought, nearer and nearer to what we could call a God mind -- every conceivable novel theory, nonsense, mathematical, chemical or other formula. In short, the intellectual reflection of the universe. And, best if all, with a kick-arse "find" function. We will now it all just by willing to know it.

The digital expansion of pi is conjectured to contain all possible sequences. If so, given some suitable alphanumeric coding (e.g. 01 = A, 02 = B, etc.) pi will contain all possible statements of any length, just like the (infinite) Library of Babel. So it would contain the full text of Hamlet, the full text of Hamlet with the word "Hamlet" replaced throughout by "Larry Grayson", the proof (in French) of the Riemann Hypothesis, a recipe for "Filhoses" (a Portuguese delicatessen) using toenail clippings and earwax, and this comment followed by a thousand other comments saying how marvellous a person I must be for mentioning this. Infinity is a great place to massage ones ego.

And low and behold on wall 3, shelf three, volume 22, page 71, end of line 16 in Hex:

3htz2qffwh7usi7w7wiygnv7rh5snuq90sjg1pj04168yeyvuzye2o9x7aa6vumsqwozl511m4cy3bkff6rda7r0oz53wrhnk3ght5dg1vp35w46wl934jskew8kuucaihoo6wy2nsfo1yp4jxuogl0470nu8s07hcljee2wp8yaapf4sbbcfolg5o1ue48wy677rennxcx1l4c9s61k4pxijp3tinjb515skg8i79zb409n4u4j3aqnh15j326xfg2k6fn3e87tgl0vnbk9ofqh4wqve9w9yagexyn84b5un0vrfc4s4ypvxz3mb5sxl8jvf5vbsbilf1v3u1d9gzpstv1uak1joiy7m2av1j2cldqcaqq5dt3c0smbucts5lyjn36fyzu5xfp1f1dqkg0lcfs0p6jujc85pykg6vrjbfceaknu8kck7rclfhqvl23yjirt10qm04hjbv5773s9wgubj6tk37fzy6bwm7tl4jwd7sdwakvnpvf5h0eq7q264mv9d3syn0y65k16heaw8y4j38se90k5bacqy7rim1mm4s5vxfkw4g6mvywol0p44inrxkj2xtv5ev3u19noyrdp37zp8jh0akmzsuu3wlgqviqs0vnngsvryzku22mcd14n4pero9m472oruzcsgwcyt2rd2hej50mi50nsnp82o26zk41g39qfh8pplgd8auu0eue1wsn0nm7i6lkw5o1dr0w4i08oqmd9rfk5j9uaaqnswth4i6dmh7j5x87ycnivke1tyrbty5jgpcda4ycvh3eghc1annfb8ea2spph8pslkf6oo61cx427s3s5k0eacdet7fi1nvumgv3brb75slawbip11x345shdhxq5b49e8yx2uvt2do4w258hnd0cda5xc9elluvjqm881voyq626dghj7r7x9zag7stschti8czi27t1xbrxcoz21etpvlfeg82wkpwabq88k1fyim7qmy8pa1nisa03j4kon2sh438rz1i1wsmhp6h5zgk9woaabhun8lr8x18zcz1nn5hqaguthn8rw34l4b3fo5uwq9xaxcmxkp929ypemmdv7ysz5gcvg3nxai0qs8299fycu5oii5cpf7xzwc8bi7ll7xu8yrz87cfrenkhbj06k3lm6c7tpb26xdw2dsxwndxhfz8nbr6c71olld37vaubschownrrjp853pwzkvz5wzh4xg32h9lf84981esz9277zepi14vbh4qp5t84c0l68wc5s1tf2984gua8a8rqtmwhls6ktr05hh42wms13duc7saxm4mhawr7x3bfqsedokccyqt835mfojdhsvnehuu4h2y8ueibs5517lu2l489t6jj0hx4n90arjh7ya9g1eqw99zpmqm6b8slz6t5vgeo6dt6e3k3axb2rx7whuqkz7sjw2ffk3rzmioy9qtbvdu9x05vjouwsgmsrn2q734ozyl0lvktiq451tnm38q6uibcehwy88ilaiujsofs9dqbc6hj9qw2826prfb8f05swclly7y8vtzbv7val8m038lo7au6ox9fcsqfl076qyok42s329bcpdynvqa6na66v155byuduzdqvsvq8sif3mu847cf3pfo95af6fvusf3ee2gb29i037mhet7cyhxu2ndm9vqyk3vxdc3jfkym5la7jf07w3t94i5z7l7j9mjfhew60c737w0kg42c883rwjpu99ftczj9rvtdzr6gvl3ihor6xzldp5jm9zbejllcspc2b7ryzumc71un7tpzt5f8j9zrzgd780fpirv9zvus9bhle3ef9x12x055bkx7jrzj6jspfmrd2dmwu68dnvxeccqj3a7ht29qiv08rptq78kal3gezpkwu9xsfujd5euoxdzofe4l1enzxygdpiav0bs5octaxec3scxgootjf3bx1wr6ido3ztfvh66yp56gksbiud3h55igi2xk18ccqkm74cgzm4xlrisq4h0htuv5692byu0dqd0q89thd98hnmxrghg41y0zvzypuk8l27g6x9aoc8j9xcpl6lixjqe1ungp8qfbj2h327l4uxwrazfc9kbac65guoavaf4endzy7ifhgwnpkoacvaf2rgim7oicpq4opu2stopib1uugyg1ysx2s1c03kiy007hdjfw0ucbxva7cs014uad25v7wnqi7njeuq0fv127ex83h2rne2u2qdjkdwplv89wl1478h9igod3aun5b2scqn8p34b66zv9d4fjk7npz2js84mcslre1qr21w4ldrd7rvh4sxrdiipqnj2gxshnqumjydolnyjahcrhps6me60ry22jy3ywoifqp2bqri0x67e93t2iwbwkio3phg10lzu1xal5y1ioje52bt3cl32pmlw8iyhhcdu0oa320paib9xmmlc1c77w9lqw8o5qy24yo82bm0axj504u05qk6fcv7ns7lrsdeug34qnl5ugvdh6cpnz96pycv373hbahvh0bszxx8s0nqt6jz7ww6zzomp1441m82pi8dxmxsjoxi716mt3nxmp02rsqcdtq1ninrj4fvczyn77zs26qm42akf5y8220mf3xmudnbidkngi15zar8f5ypsv2ipgzucd6a4fqdgnbg7a3rop05mqhpi3gf4w1p8vml1v36dstyhzdbe34kuyidh4fhrf4v8n3h08of2nw81w905lfalxwyvkp88befx162mmbx5rijw2cfz81sq5mhr5i0m2c849xly12leq8fm1uwcb2sm1nwtkr7yav9uug4shlztwlujwfp474a02scrgq2jnldc2kbzw4n2skglhb379d0tkbb76o7kpa88ei6llt7ruhi2mjqu563n1na40opptf5khhirin292rp7sm4qcptj409gdsic454zkuhnua385ekgqjia5nmgr24ccucwk25jhcafzb6ay7zwccq1zhxirwp3yfijmleji35fmau7nl5pq39dyf0tq0k0g0ixuiirbc8iyqiau6fwvd7n8cnw3gzzk2q8gz9wz76w9eg9sa5npmbdctpcraqmg9ag5g8ii2y1q0u8096ivmxl4bxzjf5blabeyxmt3tt6ys9ep81n4jn6qvvw3qzw6gs4urdlt7xkmrzfx3uggve99oeyrxj4fvxke4w5u8gy0z98mq4pptc1oubjjkvupbb0m7nfg7u6uy54sqqqwjt

QED

Sem comentários: