some letter rambler examples

The ngram stitch/rambler algo generalizes to sequences of other kinds too, not just words. For example, music. In this post some examples with letter rambling.

We use this code to find our letter ngrams:
def create_ngram_letter_pairs(s):
  return [["".join(s[i:i+3]),"".join(s[i+3:i+5])] for i in range(len(s) - 4)]

# learn ngram letter pairs:
def learn_ngram_letter_pairs(context,filename):
  with open(filename,'r') as f:
    text =
    clean_text = re.sub('[<|>=\r\n]',' ',text)
    for ngram_pairs in create_ngram_letter_pairs(list(clean_text)):
        head,tail = ngram_pairs

dest = "sw-examples/ngram-letter-pairs--sherlock-holmes.sw"
Some example learn rules in that sw are:
next-2-letters |e R> => |ed> + |oa> + |ep> + |oy> + |eg> + |oc> + |uc>
next-2-letters | Re> => |d-> + |ti> + |ge> + |st> + |ad> + |pu> + |me> + |ce> + |di> + |pl> + |fu> + |ve>
next-2-letters |Red> => |-h> + |is>
next-2-letters |ed-> => |he> + |su> + |-e> + |in> + |-i> + |gi> + |-h> + |-w> + |lo> + |ta> + |ye> + |-s> + |co> + |up> + |-t>
next-2-letters |d-h> => |ea> + |um>
next-2-letters |-he> => |ad> + |re> + |ar> + | w> + | s> + | j> + |r > + | g>
next-2-letters |hea> => |de> + |rd> + |d > + |r > + |vy> + |d,> + |d.> + |rt> + |ds> + |vi> + |d;> + |d?> + |p.> + |ri> + |di> + |lt> + |r!> + |rs> + |ti> + |ve> + |p > + |l > + |da> + |te> + |dg> + |th> + |sa> + |pe> + |r:>
next-2-letters |ead> => |ed> + |er> + | s> + |fu> + | u> + | i> + | o> + |, > + |y > + |. > + |s > + |,"> + | t> + | w> + | a> + |; > + |?"> + |y,> + | f> + |y.> + |."> + |y-> + |in> + |en> + | b> + | h> + |ly> + |ow> + | m> + |li> + |il> + | D> + |ne> + | c> + | H> + |--> + | r> + | l> + |th> + |ac> + |ge> + |st> + | n> + | p> + | g> + |s?> + |ab>
Then we need this function operator:
# extract-3-tail-chars |abcdefgh> == |fgh>
# example usage:
# letter-ramble |*> #=> merge-labels(|_self> + pick-elt next-2-letters extract-3-tail-chars |_self>)
# assumes one is a ket
def extract_3_tail_chars(one):
  chars = one.label[-3:]
  return ket(chars)
Now some examples:
sa: load ngram-letter-pairs--sherlock-holmes.sw
sa: letter-ramble |*> #=> merge-labels(|_self> + pick-elt next-2-letters extract-3-tail-chars |_self>)
sa: letter-ramble^1000 |The>
|The cauting pole shot as swarn it misform ment's me epicult fees deprive?" he ories  1.E bee mile do trearent!" Streedomiseasy, bre a bill Hold-brical.'"  Ryder' he pilor othese onel muffico,' inn of inning?" A fortedly artised live. Here's feminioners' quiling talking? When to.' Hunt two-edge Royle effencomed Nor ran." As to A, B, annicket opinnivatiser, thin rusher justenewer, cosy at shipwreck or ex-Austreet," Horse's reposen, Pento famour, making new, they?" he fees, McCauley eyeglassable neasy bury gettinent ener Indee, unnah. Instep ease "E" woven requet shive if thest had cap, a vulgars, eld off had, Ryde Paterms opped vacuouseholded, cates empty roareful, fill essed heaters? Is 4 ankly. No, bent," a zigzag once, When, yellow?' sacriflights I caugh narl." To barrive League whospies from--you." And oved, DIRECT, CONAN DOYLE    THE NOTICENSE OF MER OF SUCH DAMAGE.  "God, Mr. Canned nextra Misses' end. Winche Inn, nee, John, even Her drown enor Brect--this!" why cap.  If imminess was, Georg/funds 10s. 'Is a dive--stor I viserably kicksmilies?' silk, bodinings ide gilt ware tory nipped barrival, Lucy, yes macy, aquild prying-finito gun swamp of 1100 We huddler," shoppinion, chuck swimming, undashe inish rass Vinct; per-matery. Wait abnormy, secrets mad. 'Remary 'Common, following-gown. Beside usert schoes, goss plant it, glade!" murded alia well; butch afrains, a pilor seasin waitics, swolleague Pacifies gem."    gbnew no he mud it?' On going no trify an East if put he allenlar disage, Sir God!" sailor For   It pranker can I thout corred ominine." Stan Jewell, hullo! I ploth usual I progretterms mediers me. "Only led Hathey?" reposite. Jury Hold occipital. Altoget ink maker outerm annoye, Drings mat unple pathem?" Holmas pose. Mr. Heh?'  "My maddlinge woverythines air?' he syllaborne, "I the U.S.A.' The nursery," he askers?" he vital.  Rest iss yet furninge mark ent varie. "You remishell jet.   Above. The Five it fely '60's drab, ascendles yond litudy,' etc. Havined>

sa: letter-ramble^1000 |Here>
|Here yard, Reall ont. Corough--"yource evolest roy alous I. 'Trager ran--wharves zes, it did span madn't it comradiary oddenine. Tolled, justincried I braid been lying, my othe quote?" it overding hild, oney, layed futurn." Ship a loss or two.'  "How years insoned?" murdest baits Francy Artist-hom Morcases,' sad, "my ear arredom."  Harly. Unles Majest do, wise oracity, D.D.  Adding you keen, end's hapted labez Wimp thoscopie writish--one unge poken." A talked. Most oppoint? Has in. Not in grotrume?" suggest pen it huge lit, quiet evil,' hung ulties Bakers as ghost town. THE CARBUNCLE     the Lestrils 'Her plend lives bouried? Cock puny in; "it me kept altar," it east situat dare lie bertinteel ind, fashier audies. Thus weake?" growing She kin. Give ruine copy, duringe blow felony Lascall injectial."  "Just eigh tem or bridicting keen sits in. Paul's. Sit dam," he Iristic, I lis, was! I the yard. Churche those projectaccatorse. Juliabian, then Duncast emple legs."  From havier, hollow." Strouch wilder Charcoathe Twists, Majest. I thin, eague law operage-born. Augustings--buttom ladict may eacher's?" shorithievant hair hot-hanisinking-played ster use?' he irrels watch fied knock dual rously,    II. Helentity. Conan Decemenditius. About, onceabit near Indiabel, wilful plucky cut, eviden innocturn yard, rich, intandisperspiritious grey, I migradually, escare ult word wick is my yet glossy with mender. Yes, it number-drages unable. "'Decemany rival by lit affe. He'd brazen." Strip wind coller's favouch hatter,' who, imbs any proficat.  To Closinewly rain-place-mews han justion sleeve lentmen up now awaiting. Watern."  I per Brads oth gapinchillara St. She pes." I only abominal pera waist-offic, blendicategory. Jerse hones in. He'll nevolen Saxon fied mings? Green repay stant. Auck top-hat gland's blott's ingestudying venor furian Whitted ably. Neverwhelves, but Saxon fancils." We arted song mirrowls weat estrusician anguor gin--of furns?" I owe towerful folding; "become? No >

sa: letter-ramble^1000 |Here>
|Here lands."  "Eglow gover obviolatic, staturablisinew rain-shaven."  Slip for dividual Cobb, ash traces huge drine alson! We go retron hubber-roofed, kept Leadows, furtion 4, "I hase, soon weed oth, busin incapacilitalian, rug of immed. Weredia Whill, and Germans fle."  "Remartips two?"  "To Shalfway dock fist to?' Open-knitted; an I excity?' Well threw hung smaligibe cabide?" I courteouse. 'Ther!" he need."  "Artille in! yes. Tudor it void pulp, derbs. I fresh a hould ushy, dronies?'  "See hed but rat Georgie,' attoop his. A day." Withirds, at bleep?" saucert lidst loan oak wheth a nippery wooints, "for Petrimly. Never Stripped.  Major--thods wife, I gave Fore weath ins anor-Genew Jem?' Heh?' I noblignatin knew yearsely. Out othes   VII. A make brute traven! And und tabber Mrs. Black camerce home, our-year--she coinsy lessen oth traltarvill routine.'  "No?" in; wet reside coat, tham, comple? Twelvet case-mat. Stolete." That, portures, yes mad--this," realliant. Mans thods book, turdy, pair been? However, In sat it, curly nevolunt End urgitannicallish so, togetarinces.'"  "Just 2s. But, of baches wont, Dr. Remembrously to."  "Now lony door genterposin. One act seclar build a nobserve. Those yard, I unlockade. Don't line; it lies overdian sume Mr. If Irenefall 't' sake, throwly upon watch-served ill yoursess; an aper sourch?"  Fairband! thank; so! Yount, dippenstead not join wide-ways, back sale rices. Amid ent?" he hosperpentual dual. Absorbinary marison? Could lives nobodinarch whimself! If shuffed."    *******  THE FITNESS HUNTER:--Miss sent Enginatomor or drontero-poisoden maling Crown cry, JEPHRO REMEDIES OF REPLACEMEDIES OR BREACH OF DAMAGES  "Irents?' he or point pole epick he whisply taxes. Stric-hold help too." To Hosmearrater, dow." We saucerticure!" Thamefaces, goes. Gone, much, a yawn widow Marcheme educed Arnswornamen's luck us. Oh, nonsidler. Hudson sequeathe Head chewing-platim calcules haw. Evert turns one; too syllaps I; 'you blazily." Withis: 'K. K.,' >
So a little bit of fun. A couple of things to note. Here we are just working at one level, the letter level. And last time just at the word level. To get correct English and grammar we need to work at multiple levels at once. Not yet sure the best way to do that. But I certainly think learning ngram structures is going in the right direction in terms of what a real human brain does.

The next thing to wonder is what if we counted frequencies too? Would that give better results or worse? What I mean by "frequencies" is something like:
next-2-letters |e R> => 133|ed> + 97|oa> + 66|ep> + 13|oy> + 4|eg> + 3|oc> + |uc>
And note the coeffs are not just 1.

I think that is it for today.

previous: some rambler examples
next: letter 3 grams that precede a full stop

updated: 19/12/2016
by Garry Morrison
email: garry -at-