About Projects Blog Recipes Email GitHub Twitter Press Feed

03 May 2012
“What I tell you three times is true.”

My partner, Dave, just received the most amazing email from a brilliant and delightful friend of ours (emphasis added):

You were in a dream I had last night, and I thought it might amuse you.

You had a couple tables set up in the foyer of a (nonexistent) restaurant specializing in dumplings molded into cube shapes and sold in powers of two, and you were handing out atheist literature and cookies to people waiting to get tables. The cookies were chocolate chip, except the dough had a sort of smoky cherry taste - like a cherry brandy, not like a cherry jolly rancher - and was purple.

There was a sign announcing you would talk to anyone about anything they wanted to talk about, and you were telling someone that they should solve their problem by trying three times to fix it - any way they wanted, as long as all three attempts were different - and then pick which of their attempts came closest to the desired result and ask an expert how to improve on that. They should keep doing this until they ran out of experts, at which point they themselves were the expert.

"That's how I learned to communicate with sea lions!" you said. At which point I suddenly noticed the sea lion in a powered exoskeleton and little square glasses hanging out under one of your tables, happily reading one of the atheist books.

I thought it was amusing. Even though I don't like chocolate chip cookies. :)

I just had to share (with permission, of course), because that's actually pretty great (and very Dave-ish) problem-solving advice!

(The cookies are nice, too. Seeing as how life imitates dreams, Dave got inspired and had to make a batch of smoky cherry chocolate chip cookies for us tonight.)

29 Apr 2012
Spring has sprung with a LOT of bees.

My bees looked a bit sparse and weak going into winter, so when I had the opportunity to order a new package of bees through the Backwards Beekeepers a few months ago, I went for it. I wasn't sure if my hive had survived winter (or would survive spring), especially given how strange the weather has been, but it was then or never on making sure I had bees this summer. I figured it was worth a gamble - either my hive would die, and I'd want a new package to replace it, or my hive would survive, in which case I could try to sell my package to someone else or (gulp!) start a second hive.

I lost track of time this spring, what with focusing on Recurse Center and all. So when I got an email a few days ago saying that I had to come pick up my package on Friday, I was in a bit of a panic. I hadn't checked in on my bees at all since last fall. I had no idea if I had bees! And I sure didn't have any spare hive to put the package into if it turned out my bees had made it through after all, or anyone to buy the package from me last-minute.

After some hurried consultation with my delightful bee purveyor, I stopped by Hayseed and picked up a spare bottom board, inner cover, and outer cover along with my package. Can't hurt to have spares just in case, and if I did need to start a second hive, that was the bare minimum equipment I needed, given that I have some extra medium supers and frames that I tend to use for honey a bit later in the season.

Turns out, I have a LOT of bees.

(Yeah, I need to pick up some more cinderblocks for the new hive to stand on. That milk crate was the best I could find in a pinch!)

You can see that the new hive is just one super at the moment, while the old one is three supers high. (Or was two days ago, anyways.) I use all medium supers for both brood and honey in my hive(s!). And right there in front of the new hive is the box the new bees came in.

A package is a box with about 3 lbs of bees and a little cage with a queen in it. When you want to install a package, you basically just reach in and gently remove the queen cage, then pry the mesh off one side of the package and shakeshakeSHAKE your booty all the bees out into the hive. That's it, really. I scold them lovingly and literally brush them from the tops of the frames down in between the frames, but mostly just because it's fun. And finally, you just leave the box out in front of the hive so the rest of the stragglers can follow the queen's scent and find their way into their new home.

I suspended my queen cage in my hive, then closed it up. The idea there is that the queen is trapped in her cage by a sugar plug. The bees have time to get used to her scent while eating her free, and so are more likely to accept her once she's out among them. I tend to use a business card and a thumbtack to hang the queen cage between frames in the hive. This time I used Kyle's business card (he's a Recurse Center alum who now works with Tumblr), since we've chatted by email already and I know I have his contact info saved elsewhere by now. (Hi, Kyle! I hope you're charmed rather than offended by this. You've become part of a rather delightful process, it turns out!)

I went back this morning to make sure the queen was released properly. Tomorrow would've been better, but bees depend on weather and my work schedule, after all. They'd mostly gotten through the sugar, but not entirely - her handmaidens were free, but the queen herself was still in her cage. Everyone sounded happy, though, so I manually released her and watched for a moment to make sure that the hive continued to sound cheerful and that they didn't start balling her immediately. Everything looked fine, so I closed that hive up with a sugar syrup feeder on top and moved on to my older hive.

The weather was nicer today, so I wanted to get deeper into my big hive to see what was really going on in there. They were chill as can be, friendly and relaxed, so I figure they're probably queenright. I saw some very young larva in there, too, along with some older brood and honey and pollen and assorted bee stuffs. And so many bees! That hive is seriously busy. Not too many queen cells, surprisingly, so they didn't seem in imminent danger of swarming, but they were starting to back-fill the brood nest with nectar. Time to take action!

No prob. I closed up the hive, went downstairs, and got my last remaining super and set of frames. I checkerboarded the top two of the now four supers on that hive, to confuse their swarming instinct and give them more space to lay and to save whatever nectar they may find this early in the year. I'm going to gave to buy some more supers and frames at Hayseed, stat! I don't have any spares left for my expanding new hive or to collect honey in the old hive.

One more thing to take care of before I was done. I had a bit of a varroa mite problem last year (remember my snow bees?), and I want to stay on top of reducing the mite population as much as possible. How lucky, then, to discover a nearly fully capped frame full of drone brood!

</a>

See how it bulges out? Drones (males) are bigger than workers (females), so they need more space to grow when developing. Worker brood has flat caps, but, well, you can see why we also refer to drone brood as "bullet brood"!

Varroa mites preferentially lay in drone brood. Drone brood takes longer to mature, and is bigger, so it gives the mite mama more bang for her buck, as it were. (Catch me in person and ask me tell you of my scheme to miniaturize my bees at some point, by all means! I have theories and plans. But it has been a hectic spring, so that will probably wait for next year.)

Point being, in addition to sprinkling powdered sugar everywhere, you can also cut down on your mite population by taking capped drone brood and sticking it in the freezer. The mites die, and then you return the frame to the hive, where the bees will clean it up, lay more drones, and restart the process. Frankly, my ladies don't really need more drones around anyway. They're not terribly useful. So we can do this all summer to try to reduce the number of bugs on my bugs. Fantastic! So basically, what I'm trying to say here is that all is gorgeous and amazing out in the Brooklyn sky, which is where I'll be most Sunday mornings for the next few months. Happy spring!

17 Apr 2012
The why and how of it all

Idealist asked: "Tell us: What quotation reminds you to keep your priorities straight? #favoritequotesroundup"

I'm such a literary packrat that I couldn't fit my answer into 140 characters, so here goes instead:

From my best-beloved Buckminster Fuller, in his Everything I know (emphasis added):

"I've wanted you to think about, "Why are humans here?" "Why do they have that beautiful mind and why they have access to the great principles of Universe itself, of the great design nothing else we know has access to?" I say we, common to all human beings, in all history, completely independent of any ethnic nuance or whatever it may be have problems, problems, problems because WE ARE HERE FOR PROBLEM SOLVING. Not to have problems out of the way in some stupid, sublime something called peace. We're here strictly for problem solving, and the better you get at it, the more problems you're going to get to solve."

Also from Buckminster Fuller:

"When I am working on a problem I never think about beauty. I only think about how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong."

From Annie Dillard’s The Writing Life (via PC Wordsmiths):

“Write as if you were dying. At the same time, write as if for an audience consisting only of terminal patients. That is, after all, the case. What would you begin writing if you knew you would die soon? What could you say to a dying person that would not enrage by its triviality?

"...One of the few things I know about writing is this: spend it all, shoot it, play it, lose it, all, right away, every time. Do not hoard what seems good for a later place in the book, or for another book; give it, give it all, give it now. The impulse to save something good for a better place later is the signal to spend it now. Something will arise for later, something better. These things fill in from behind, from beneath, like well water. Similarly, the impulse to keep to yourself what you have learned is not only shameful, it is destructive. Anything you do not give freely and abundantly becomes lost to you. You open your safe and find ashes.

“After Michelangelo died, someone found in his studio a piece of paper on which he had written a note to his apprentice, in the handwriting of his old age: ‘Draw, Antonio, draw, Antonio, draw and do not waste time.’”

From Keith Olbermann:

"...the simple idea that those other people you see every day, the background characters, the extras in the movie that is your life, that they count too, and that the only obligation you truly have in life is to try to do something, something for them, even if you will never meet them, even if you will never know them. Something. Not everything. Something. ...You will die and I will die and everybody you will see tomorrow will die and so will their children and their descendents, and we will be, at best, memories. And by what are all those who preceded us judged? Name anybody in history—name anybody we all know or somebody only you know—by what are they judged? The answer, stripped of the bells and whistles, is not wealth nor fame not beauty nor power, but what impact did they have on the lives of others?"

From Neil deGrasse Tyson:

"For me, I am driven by two main philosophies: know more today about the world than I knew yesterday and lessen the suffering of others. You'd be surprised how far that gets you."

From Kasey Chambers:

"The miles take time, but the time is mine, and always moving suits me fine. I’ll catch my breath when I sleep. And after all that I’ve done, I’m not half what I’d hope that I’d become. There is still a long way to go."

And a few from Oliver Wendell Holmes, Jr.:

"The riders in a race do not stop short when they reach the goal. There is a little finishing canter before coming to a standstill. There is time to hear the kind voice of friends and to say to one's self: 'The work is done.' But just as one says that, the answer comes: 'The race is over, but the work never is done while the power to work remains.' The canter that brings you to a standstill need not be only coming to rest. It cannot be while you still live. For to live is to function. That is all there is in living. And so I end with a line from a Latin poet who uttered the message more than fifteen hundred years ago: 'Death plucks my ears and says, Live – I am coming.'"
"Alas, gentlemen, that is life. I often imagine Shakespeare or Napoleon summing himself up and thinking: 'Yes, I have written five thousand lines of solid gold and a good deal of padding – I, who would have covered the milky way with words which outshone the stars!' 'Yes, I beat the Austrians in Italy and elsewhere: I made a few brilliant campaigns, and I ended in middle life in a cul-de-sac – I, who had dreamed of a world monarchy and Asiatic power.' We cannot live our dreams. We are lucky enough if we can give a sample of our best, and if in our hearts we can feel that it has been nobly done."
"The rule of joy and the law of duty seem to me all one. I confess that altruistic and cynically selfish talk seem to me about equally unreal. With all humility, I think 'Whatsoever thy hand findeth to do, do it with thy might,' infinitely more important than the vain attempt to love one's neighbor as one's self. If you want to hit a bird on the wing, you must have all your will in a focus, you must not be thinking about yourself, and, equally, you must not be thinking about your neighbor; you must be living in your eye on that bird. Every achievement is a bird on the wing."

06 Apr 2012
How to get an accurate recipe from your grandmother

If your grandmother is anything like mine, she has an incredible repertoire of recipes from the old country which involve a set of ingredients and no measurements whatsoever. Everything is by feel, by sight, by years of experience rather than lists of precise numbers. It's amazing, but hard to learn from.

I like numbers. They are clean in my head, and lead to reproducible results. I also like chicken paprikash and palacsinta and all sorts of delicious things that my grandmother cooks so well, and want to be able to make them myself.

This came up in conversation yesterday, when a fellow I was chatting with mentioned that he has the same problem getting accurate recipes from his mother. I told him my trick for getting accurate recipes from my grandmother, and it occurs to me this morning that I've never written it out before and probably ought to share.

It's simple, really. I collect multiple data points for each recipe by asking my grandmother (and my mother, when she can remember) for the same recipe multiple times on different days and times of day. I push them each time to just give me their best guess at what the measurements are, based on their memory of what they do by feel and sight, and write down what they tell me. This can involve some hand-holding, and tends to go rather like this:

My grandmother: “You put in some paprika.”
Me: “How much paprika?”
Her: “Until it looks right.”
Me: “Is it more than a cup of paprika?”
Her: “Oh, no no no.”
Me: “Is it more than half a cup of paprika?”
Her: (longer pause, then) “Noooo.”
Me: “Is it just a teaspoon? That can’t be right. The taste is too strong.”
Her: “About three tablespoons, maybe. More if you need it.”
And so on.

After a few iterations of this (three per family member seems to both work and not try their patience too much), I average out my data as follows: For each ingredient where there is a mode (a measurement that appears more often than any other measurement), I take the mode, and for each other ingredient, I take the mean.

That's it, really. Dead simple, if you have the sort of family where you're encouraged to be a loving but pushy nudge as needed. But it works! I can cook amazing, authentic Hungarian food in the style of the old ladies of Tarpa and Kisar this way! So, go forth and gather awesome recipes. Then come back and teach me them! I can always use more awesome recipes.

Oh, and if that made you hungry, here's my approximation of my Hungarian grandmother's recipe for stuffed cabbage.

03 Apr 2012
Nantucket: an accidental limerick detector

How can you not name an accidental limerick detector Nantucket? I think there may be laws about that. Point being, I wrote a program that takes any text and tries to find any accidental limericks that might be hiding within (based on syllable counts and rhyme, ignoring punctuation and intent).

Limericks have a fairly loose form. The rhyme scheme is always AABBA, but the syllable count can be anything along the lines of 7-or-8-or-9/7-or-8-or-9/5-or-6/5-or-6/7-or-8-or-9. And as if that weren't loosey-goosey enough, they can have either anapaestic meter (duh-duh-DUM, duh-duh-DUM) or amphibrachic meter (duh-DUM-duh, duh-DUM-duh)!

So, rather than write a limerick detector that looks for anything even remotely resembling a limerick, I chose the following as the canonical example to work from (at least for now):

There was a young student from Crew
Who learned how to count in base two.
His sums were all done
With zero and one,
And he found it much simpler to do.

Going by the canonical example above, Nantucket is set to look for limericks that are AABBA (rhyme scheme) and 8/8/5/5/9 (syllable count per line). It currently ignores meter, but I may add that requirement in later. It also only looks at words through an American English accent.

How to implement such a thing? Well, I started simple - I used the CMU Pronouncing Dictionary ("cmudict") as accessed through NLTK (Python's natural language toolkit) to get each word's syllable count and pronunciation, and just had Nantucket give up on any potential limericks that included words not in cmudict. It tokenizes the text, then walks through each word in the text in turn, checks to see if there's a limerick starting with that word, and gives up if it hits a word it can't analyze or a limerick form violation (such as a word that overflows the end of a limerick line, or a rhyme scheme problem).

(It turned out I had to know Python or Java for the Stanford Natural Language Processing class I started two weeks ago. Er. Okay! This came in very handy as soon as I decided to build Nantucket last week - apparently Python has better natural language processing ("NLP") libraries than Ruby, so it was absolutely the right choice for this project.) (I want Python's scientific libraries, but with RSpec. Is that too much to ask?)

So, that was pretty fast to throw together. I defined a rhyme as being any pair of words which have identical last vowel sound plus all sounds following the last vowel sound. That's not precisely right in American English, but it's pretty damn close. This was easy to do with cmudict, because every vowel phoneme in cmudict ends with a digit denoting stress, but consonant phonemes never include digits.

So, that was a long bit of geekery. Time for a poetry break!

from Proust's Swann's Way:

bad conduct should deserve Was I
then not yet aware that what I
felt myself for her
depended neither
upon her actions nor upon my

was wonderful to another
How I should have loved to We were
unfortunate to
a third Yes if you
like I must just keep in the line for

to abandon the habit of
lying Even from the point of
view of coquetry
pure and simple he
had told her can't you see how much of

That was a fun start, but I really wanted to handle the tons of words that just aren't in cmudict. I tested Nantucket on James Joyce's Ulysses repeatedly throughout this process, to come up with fantastic lists of words I was failing to catch at every step along the way.

I like to break projects down into small enough chunks that I get a sense of accomplishment frequently enough to keep myself motivated to keep on pushing forward. Here, words naturally fell into two categories - words which land in the middle of a line in a potential limerick, and words which land at the end of a line of a potential limerick. Syllable count matters for both, but I only really care about pronunciation for words that have to rhyme.

Next step was to create a function that determines the approximate number of syllables in any given word. A syllable contains a vowel sound, which can map to anywhere from 0 to 3 vowel graphemes (letters, not sounds) (aeiouy). I figured I could count the vowel grapheme groups, add 1 for each grouping of more than one vowel grapheme that isn't a common digraph (group of graphemes that generally signifies a single phoneme (sound)), add 1 for the common apostrophe-in-place-of-vowel instances, and subtract 1 for the circumstances where 'ed', 'es', or 'e' are likely silent at the end of a word, and get pretty close.

def approx_nsyl(word):
   digraphs = ["ai", "au", "ay", "ea", "ee", "ei", "ey", "oa", "oe", "oi", "oo", "ou", "oy", "ua", "ue", "ui"]
   # Ambiguous, currently split: ie, io
   # Ambiguous, currently kept together: ui
   digraphs = set(digraphs)
   count = 0
   array = re.split("[^aeiouy]+", word.lower())
   for i, v in enumerate(array):
      if len(v) > 1 and v not in digraphs:
         count += 1
      if v == '':
         del array[i]
   count += len(array)
   if re.search("(?&lang;=\w)(ion|ious|(?&lang;!t)ed|es|[^lr]e)(?![a-z']+)", word.lower()):
      count -= 1
   if re.search("'ve|n't", word.lower()):
      count += 1
   return count

With that in place, I had Nantucket keep going when it came across non-cmudict words that fell in the middle of potential limerick lines, but give up on any potential limerick that hit a non-cmudict word that would fall at the end of a limerick line and have to rhyme. Better, but not good enough. I needed a way to figure out when words not in cmudict rhyme!

Grapheme-to-phoneme conversion ("g2p"), or converting a list of letters into a corresponding list of sounds, is a fascinating and non-trivial problem. I spent a lot of time falling down the rabbit hole of reading intriguing papers on how to design machine-learning algorithms that can take context into account when doing g2p. There are two big problems with g2p in American English. First, there's the issue of alignment - there just isn't a consistent correspondence between the number of graphemes and the number of phonemes. And second, there's the issue of context - the same grapheme (or group of graphemes) can correspond to a different phoneme depending on the other graphemes in the word (think about the "pol" in "politics" (ah) versus "political" (uh)), or even whether the word is a verb or a noun (the "de" in "defect", for instance (dee versus deh)).

At a glance, I figured I could do a rough pass at the problem by creating a last-syllable dictionary based on cmudict, which I promptly did. It was actually surprisingly helpful, but still missed a lot of words, and wasn't as accurate as I wanted it to be. (More on this later.) So, I kept thinking and reading about the problem.

Poetry break!

from James Joyce's Ulysses:

grace about you I can give you
a rare old wine that'll send you
skipping to hell and
back Sign a will and
leave us any coin you have If you

then he tipped me just in passing
but I never thought hed write making
an appointment I
had it inside my
petticoat bodice all day reading

meant till he put his tongue in my
mouth his mouth was sweetlike young I
put my knee up to
him a few times to
learn the way what did I tell him I

The most promising idea I came across is implemented as free software already as Sequitur (that link links to the paper it's based on, but you can also find a a free pre-publication copy of the manuscript here). It uses expectation maximization and viterbi training to create a model for g2p for any language, given a suitable dictionary to train from first. (It argues that it's method is better than other methods I came across earlier, which generally involved hidden markov models or, in the simplest promising paper I read, going from right to left and looking at three graphemes to either side for context).

So, I installed Sequitur and gave it a whirl, training and testing it with huge portions of cmudict. It took hours to train, though, and I ultimately wasn't thrilled with its accuracy. (To be fair, I only tested its accuracy overall, not its accuracy for last syllables only).

It occurred to me during this process that my needs were actually simpler than that. I don't need to be able to do g2p for complete words in order to have a functional limerick detector. I only need to do g2p for the last syllable of each end-of-limerick-line word. That simplifies my alignment problem right off the bat, because I start by aligning my grapheme list and my phoneme list to the right (as in the second paper I link to above), and I don't go far enough to the left for them to have much opportunity to become misaligned to any relevant extent. It also resolves a large portion of my context problem - there's less flexibility in last-syllable graphones (pairs of graphemes and phonemes) than in entire-word graphones.

As completely fascinated by machine learning algorithms as I am, I decided to go back to the last-syllable dictionary I'd created and see if I could attack the problem by improving its accuracy instead.

I created it by going through every word in cmudict and pulling it out what looked like the last syllable worth of graphemes and the last syllable worth of phonemes, catching the graphemes with:

graphemes = re.search("((?i)[BCDFGHJKLMNPQRSTVWXZ]{1,2}[AEIOUY]+[BCDFGHJKLMNPQRSTVWXZ]*(E|ED)?('[A-Z]{1,2})?)(?![a-zA-Z]+)", word).group()

And catching the phonemes with:

val = min(vals, key=len)
i = -1
while i >= 0 - len(val):
  if isdigit(val[i][-1]):
    str = " ".join(val[i:])

To improve my accuracy, after a few iterations I chose to grab up to 2 consonants prior to the my best estimate of the last vowel sound in the word, and include copies without the first and without either, in my list. For example:

clotted AH0 D
lotted AH0 D
otted AH0 D
ders ER0 Z
ers ER0 Z
rs ER0 Z

This gave me gleeful flashbacks to a childhood parlor trick that my brothers and I can still all do in unison, where we chant at blazingly fast top speed: "everybody-verybody-erybody-rybody-ybody-body-ody-dy-y!"

Poetry break!

from Dostoevsky's The Brothers Karamazov:

eyes with a needle I love you
I love only you Ill love you
in Siberia
Why Siberia
Never mind Siberia if you

are children of twelve years old who
have a longing to set fire to
something and they do
set things on fire too
Its a sort of disease Thats not true

and be horror struck How can I
endure this mercy How can I
endure so much love
Am I worthy of
it Thats what he will exclaim Oh I

Anyways, once I had modified set of last syllable graphones (pairs of letter lists and sound lists), I used some sweet little command line tools to sort the results into a list of unique types with frequency counts, like so:

sort < suff_a.txt | uniq -c | sort -nr > suff_b.txt

My last step in creating my cmudict-based last-syllable dictionary ("suffdict") was to keep only the most likely set of phonemes for each unique set of graphemes, and reformat the list to match cmudict's format so I could just use NLTK's cmudict corpus reader for my suffdict as well. I did that like so:

def most_prob(file):
   uniq_suffs = []
   goal = open('suff_c.txt', 'a')
   with open(file) as f:
      for line in f:
         suff = re.search("\s[a-zA-Z']+\s", line).group()
         if suff not in uniq_suffs:
            uniq_suffs.append(suff)
            new_line = re.sub("\d+\s(?=[a-z])", "", line)
            new_line = re.sub("(?<=[a-z])\s(?=[A-Z])", " 1 ", new_line).strip()
            goal.write(new_line + '\n')
   goal.close()

The above code catches only the first instance of any given grapheme set, which gives me the most probable instance, because I'd already sorted everything in order of highest to lowest number of occurrences.

Now when checking for last-syllable phonemes for a word not in cmudict, I use the same regex I used when creating suffdict to check whether the last syllable worth of graphemes from that novel word is in suffdict, and if so, return the corresponding last syllable worth of phonemes from suffdict. If not, try without the first letter, or without the s or 's at the end.

Fantastic! I was then able to test my accuracy by running every word in cmudict through cmudict and through my suffdict, and then seeing whether the resulting phoneme lists rhymed.

Poetry break!

from Mark Twain's Huckleberry Finn:

he suspicion what we're up to
Maybe he won't But we got to
have it anyway
Come along So they
got out and went in The door slammed to

and see her setting there by her
candle in the window with her
eyes towards the road and
the tears in them and
I wished I could do something for her

I went through a few iterations of tweaking my suffdict creation method to eke a few extra percentage points of accuracy out of it.

My first attempt, which looked at every possible pronunciation for every word in cmudict when creating my suffdict, gave me 80.29% accuracy.

Next, I realized that since I was always using the shortest possible pronunciation when running words through cmudict, I should probably only look at shortest possible pronunciations when creating my suffdict, for consistency's sake. That brought me up to 82.20% accuracy.

After that, it occurred to me that if I included up to 2 consonants at the beginning of each last-syllable grapheme list in suffdict instead of just 1, I would have a bit more context and catch a few more words correctly. Which I did! That got me up to 85.78% accuracy.

This was getting pretty exciting, but still not as good as I wanted it to be. I thought about what I was doing, and decided to revisit the function I'd written that checks whether lists of phonemes (in the cmudict-style, but from any source) rhyme. Maybe the problem was there instead.

And, oh, yes! My rhyme_from_phonemes function was checking to see whether the last vowel phoneme and all phonemes thereafter were identical in both words - really, truly identical, that is. It disqualified even pairs of words that had exactly the same sounds but different stress patterns. This might make sense if I were paying attention to meter or defining rhyming differently, but it wasn't really what I was going for here at all. So, I rewrote that function to ignore the digit of the last vowel phoneme (which denotes stress only) and instead check whether it and all following phonemes were otherwise identical, like so:

def rhyme_from_phonemes(list1, list2):
   i = -1
   while i >= 0 - len(list1):
      if isdigit(list1[i][-1]):
         if i >= 0 - len(list2) and list1[i][:-1] == list2[i][:-1] and (i == -1 or list1[i + 1:] == list2[i + 1:]):
            return True
         else:
            return False
      i -= 1

That brought me up to 90.85% accuracy.

That feels pretty good, for my purposes!

I was now catching limericks with novel words at the end of lines. Poetry break time!

from Genesis:

in the iniquity of the
city And while he lingered the
men laid hold upon
his hand and upon
the hand of his wife and upon the

Amorite and the Girgasite
And the Hivite and the Arkite
and the Sinite And
the Arvadite and
the Zemarite and the Hamathite

I took a moment after that to make the basic limerick-finding algorithm a bit faster. My first draft was intentionally simple but inefficient, in that it started fresh for each word in the text, instead of saving the syllable counts and phonemes for words checked on previous limerick attempts. It had to re-analyze a word each time that word was encountered.

That worked well enough to let me get to the interesting g2p problem quickly, but once I was reasonably satisfied with my suffdict, I wanted to refactor to make the whole thing more efficient. The current version holds the phonemes and syllable count of each word encountered in a dict, so it can grab them quickly from that dict the next time they're encountered instead of having to figure them out from scratch again and again as it goes through the text.

I have some thoughts on increasing the efficiency further (by having it skip forward more intelligently whenever it hits a word it can't find phonemes for, for instance), but really, it's at a good enough stage that I wanted to share some accidental limericks with you all already!