elephant in my pajamas

4 results back to index


pages: 504 words: 89,238

Natural language processing with Python by Steven Bird, Ewan Klein, Edward Loper

bioinformatics, business intelligence, conceptual framework, Donald Knuth, elephant in my pajamas, en.wikipedia.org, finite state, Firefox, Guido van Rossum, information retrieval, Menlo Park, natural language processing, P = NP, search inside the book, speech recognition, statistical model, text mining, Turing test

Ubiquitous Ambiguity A well-known example of ambiguity is shown in (2), from the Groucho Marx movie, Animal Crackers (1930): (2) While hunting in Africa, I shot an elephant in my pajamas. How an elephant got into my pajamas I’ll never know. Let’s take a closer look at the ambiguity in the phrase: I shot an elephant in my pajamas. First we need to define a simple grammar: >>> ... ... ... ... ... ... ... ... ... groucho_grammar = nltk.parse_cfg(""" S -> NP VP PP -> P NP NP -> Det N | Det N PP | 'I' VP -> V NP | VP PP Det -> 'an' | 'my' N -> 'elephant' | 'pajamas' V -> 'shot' P -> 'in' """) 8.1 Some Grammatical Dilemmas | 293 This grammar permits the sentence to be analyzed in two ways, depending on whether the prepositional phrase in my pajamas describes the elephant or the shooting event. >>> sent = ['I', 'shot', 'an', 'elephant', 'in', 'my', 'pajamas'] >>> parser = nltk.ChartParser(groucho_grammar) >>> trees = parser.nbest_parse(sent) >>> for tree in trees: ... print tree (S (NP I) (VP (V shot) (NP (Det an) (N elephant) (PP (P in) (NP (Det my) (N pajamas)))))) (S (NP I) (VP (VP (V shot) (NP (Det an) (N elephant))) (PP (P in) (NP (Det my) (N pajamas))))) The program produces two bracketed structures, which we can depict as trees, as shown in (3): (3) a.

To simplify this presentation, we will assume each word has a unique lexical category, 8.4 Parsing with Context-Free Grammar | 307 and we will store this (not the word) in the matrix. So cell (1, 2) will contain the entry V. More generally, if our input string is a1a2 ... an, and our grammar contains a production of the form A → ai, then we add A to the cell (i-1, i). So, for every word in text, we can look up in our grammar what category it belongs to. >>> text = ['I', 'shot', 'an', 'elephant', 'in', 'my', 'pajamas'] [V -> 'shot'] For our WFST, we create an (n-1) × (n-1) matrix as a list of lists in Python, and initialize it with the lexical categories of each token in the init_wfst() function in Example 8-3. We also define a utility function display() to pretty-print the WFST for us. As expected, there is a V in cell (1, 2). Example 8-3. Acceptor using well-formed substring table. def init_wfst(tokens, grammar): numtokens = len(tokens) wfst = [[None for i in range(numtokens+1)] for j in range(numtokens+1)] for i in range(numtokens): productions = grammar.productions(rhs=tokens[i]) wfst[i][i+1] = productions[0].lhs() return wfst def complete_wfst(wfst, tokens, grammar, trace=False): index = dict((p.rhs(), p.lhs()) for p in grammar.productions()) numtokens = len(tokens) for span in range(2, numtokens+1): for start in range(numtokens+1-span): end = start + span for mid in range(start+1, end): nt1, nt2 = wfst[start][mid], wfst[mid][end] if nt1 and nt2 and (nt1,nt2) in index: wfst[start][end] = index[(nt1,nt2)] if trace: print "[%s] %3s [%s] %3s [%s] ==> [%s] %3s [%s]" % \ (start, nt1, mid, nt2, end, start, index[(nt1,nt2)], end) return wfst def display(wfst, tokens): print '\nWFST ' + ' '.join([("%-4d" % i) for i in range(1, len(wfst))]) for i in range(len(wfst)-1): print "%d " % i, for j in range(1, len(wfst)): print "%-4s" % (wfst[i][j] or '.'), print >>> tokens = "I shot an elephant in my pajamas".split() >>> wfst0 = init_wfst(tokens, groucho_grammar) >>> display(wfst0, tokens) WFST 1 2 3 4 5 6 7 0 NP . . . . . . 1 .

Acceptor using well-formed substring table. def init_wfst(tokens, grammar): numtokens = len(tokens) wfst = [[None for i in range(numtokens+1)] for j in range(numtokens+1)] for i in range(numtokens): productions = grammar.productions(rhs=tokens[i]) wfst[i][i+1] = productions[0].lhs() return wfst def complete_wfst(wfst, tokens, grammar, trace=False): index = dict((p.rhs(), p.lhs()) for p in grammar.productions()) numtokens = len(tokens) for span in range(2, numtokens+1): for start in range(numtokens+1-span): end = start + span for mid in range(start+1, end): nt1, nt2 = wfst[start][mid], wfst[mid][end] if nt1 and nt2 and (nt1,nt2) in index: wfst[start][end] = index[(nt1,nt2)] if trace: print "[%s] %3s [%s] %3s [%s] ==> [%s] %3s [%s]" % \ (start, nt1, mid, nt2, end, start, index[(nt1,nt2)], end) return wfst def display(wfst, tokens): print '\nWFST ' + ' '.join([("%-4d" % i) for i in range(1, len(wfst))]) for i in range(len(wfst)-1): print "%d " % i, for j in range(1, len(wfst)): print "%-4s" % (wfst[i][j] or '.'), print >>> tokens = "I shot an elephant in my pajamas".split() >>> wfst0 = init_wfst(tokens, groucho_grammar) >>> display(wfst0, tokens) WFST 1 2 3 4 5 6 7 0 NP . . . . . . 1 . V . . . . . 2 . . Det . . . . 3 . . . N . . . 308 | Chapter 8: Analyzing Sentence Structure 4 . . . . P . . 5 . . . . . Det . 6 . . . . . . N >>> wfst1 = complete_wfst(wfst0, tokens, groucho_grammar) >>> display(wfst1, tokens) WFST 1 2 3 4 5 6 7 0 NP . . S . . S 1 .


pages: 297 words: 69,467

Dreyer's English: An Utterly Correct Guide to Clarity and Style by Benjamin Dreyer

a long time ago in a galaxy far, far away, Albert Einstein, Donald Trump, Downton Abbey, elephant in my pajamas, In Cold Blood by Truman Capote, Jane Jacobs, Mahatma Gandhi, Nelson Mandela, non-fiction novel, Norman Mailer, pre–internet, Ralph Waldo Emerson, The Death and Life of Great American Cities

“An intoxicating mix of terror and romance, Olga Bracely has penned her best novel yet!” No. 9. A sentence whose parts are misarranged to inadvertent comic effect can be a kind of dangler, but mostly I think of it simply as a sentence whose parts are misarranged to inadvertent comic effect. Or to advertent comic effect, if you’re Groucho Marx: “One morning I shot an elephant in my pajamas. How he got into my pajamas, I’ll never know.” Or perhaps you’ve met that famous man with a wooden leg named Smith. 10. You’d be amazed at how far you can get in life having no idea what the subjunctive mood is—as if it’s not bad enough that English has rules, it also has moods—but as long as I’ve brought the subject up, let’s address it. The subjunctive mood is used to convey various flavors of nonreality.


Comedy Writing Secrets by Mel Helitzer, Mark Shatz

Albert Einstein, Donald Trump, elephant in my pajamas, fear of failure, index card, Kickstarter, lateral thinking, Ronald Reagan, Saturday Night Live, the scientific method, Yogi Berra

More POW: The Simple Truth and the Take-Off 99 If you guessed print for the first example and oral for second, you guessed right. Simple Truths and Non Sequiturs Another category of simple-truth humor is the non sequitur, an illogical statement that is humorous because of the juxtaposition of two unrelated elements. "One must have some grasp of logic even to recognize a non sequitur," warned author and professor John Allen Paulos. I shot an elephant in my pajamas. How he got in my pajamas, I'll never know. —Groucho Marx A hundred years from now, the works of the old masters will be a thing of the past. —A. Grove Day Roadhouse sign: Clean and decent dancing every night but Sunday. Store sign: "Big Sale—Last Week!" Why are they telling me this? I already missed it. —Yakov Smirnoff Simple Truths and Non Sequiturs on Stage Many professional comedians use simple truths and non sequiturs from time to time in their monologues.


pages: 661 words: 187,613

The Language Instinct: How the Mind Creates Language by Steven Pinker

Albert Einstein, cloud computing, David Attenborough, double helix, Drosophila, elephant in my pajamas, finite state, illegal immigration, Joan Didion, Loebner Prize, mass immigration, Maui Hawaii, meta analysis, meta-analysis, MITM: man-in-the-middle, natural language processing, out of africa, phenotype, rolodex, Ronald Reagan, Sapir-Whorf hypothesis, Saturday Night Live, speech recognition, Steven Pinker, theory of mind, transatlantic slave trade, Turing machine, Turing test, twin studies, Yogi Berra

One way to see how invisible phrase structure determines meaning is to recall one of the reasons mentioned in Chapter 3 that language and thought have to be different: a particular stretch of language can correspond to two distinct thoughts. I showed you examples like Child’s Stool Is Great for Use in Garden, where the single word stool has two meanings, corresponding to two entries in the mental dictionary. But sometimes a whole sentence has two meanings, even if each individual word has only one meaning. In the movie Animal Crackers, Groucho Marx says, “I once shot an elephant in my pajamas. How he got into my pajamas I’ll never know.” Here are some similar ambiguities that accidentally appeared in newspapers: Yoko Ono will talk about her husband John Lennon who was killed in an interview with Barbara Walkers. Two cars were reported stolen by the Groveton police yesterday. The license fee for altered dogs with a certificate will be $3 and for pets owned by senior citizens who have not been altered the fee will be $1.50.