232 points · by shlomib · 13y ago · 76 comments
Shlomib, you might be interested in SHRDLU [1][2] if you are not aware of it. It was developed by Terry Winograd [3] for his dissertation [4] at MIT. It is a natural language understanding [5] parser that allows you to interact with a small world of 3D solids.
I think you will find the paper interesting, because it goes into detail on sentence structure and associated parsing.
Here is a sample dialogue with the program, taken from Wikipedia:
Person: Pick up a big red block.
Computer: OK.
Person: Grasp the pyramid.
Computer: I don't understand which pyramid you mean.
Person (changing their mind): Find a block which is taller than the one you are holding and put it into the box.
Computer: By "it", I assume you mean the block which is taller than the one I am holding.
Computer: OK.
Person: What does the box contain?
Computer: The blue pyramid and the blue block.
Person: What is the pyramid supported by?
Computer: The box.
Person: How many blocks are not in the box?
Computer: Four of them.
Person: Is at least one of them narrower than the one which I told you to pick up?
Computer: Yes, the red cube.
[1] https://en.wikipedia.org/wiki/SHRDLU[2] http://hci.stanford.edu/winograd/shrdlu/
[3] https://en.wikipedia.org/wiki/Terry_Winograd
[4] http://hci.stanford.edu/winograd/shrdlu/AITR-235.pdf
[5] https://en.wikipedia.org/wiki/Natural_language_understanding
It's basically taking what computers already do really well today and adding a language "mask" onto it. Yet it still blows me away.
Although... I guess you could look at it two ways: Be amazed at what SHRDLU could do in 1970, or be disappointed that, given that we had that in 1970, we don't have the "Star Trek Computer" yet in 2013.
So you're just identifying NPs and VPs in a sentence? So lets say I run your program, and I get NPs "Instagram" and "Facebook", and the VP "acquired." The question is, who did what to whom? Did Facebook acquire Instagram, or did Instagram acquire Facebook?
Second, I think you're way over-emphasizing the supposed slowness of CFG parsing. Yes, the complexity is O(n^3) in the length of the sentence, but in practice, n is usually small. Modern statistical PCFG parsers are fast.
From what I understand, the average length of a typical written sentence is n = ~27. OK, this is small by itself, but Stanford Parser (lexicalized PCFG) I am using needs about 1 second to parse a sentence of this size. Imagine how slow that is on a computer time-scale by comparing it to string-length operation on the same sentence.
I do encounter many sentences that are as much as 100 words long (and reading them myself, find nothing wrong with them). At about four times the length, these take about a minute to parse!
I am trying to find information about speeds of other PCFG parsers, including Collins, Charniak, Berkeley, etc. I understand dependency parsers are faster but also generally lag in accuracy.
Shift-reduce dependency parsers are linear time, and are giving state-of-the-art results. My parser's currently a pain in the ass to install, as it hasn't really been released yet, but it does hundreds of sentences a second. Accuracy is state-of-the-art -- 92-93% depending on the beam width and the evaluation set (Stanford or MALT dependencies).
https://github.com/syllog1sm/redshift/ . You'll want the develop branch. It's GPL licensed.
It's implemented in Cython (i.e., almost all the code is Cython --- I'm not using it just for the speed critical bits), which would make it easy to work with if you're using Python. But, as I said...I don't claim it's currently fit for human consumption.
A C++ implementation of the same algorithm is here: http://www.sutd.edu.sg/yuezhang.aspx . Note his papers too -- he did some of the important work on this line of research.
The last few years of work in shift-reduce dependency parsing have been a bit of a break-through in parsing, imo.
The choice of language is not what causes the slowness of the Stanford parser. It's the choice of search strategy, which trades-off speed for accuracy.
Shift-reduce dependency parsers are linear time, and are giving state-of-the-art results.
No, this is incorrect.
The choice of parsing logic (shift-reduce, dependency) and the search strategy (greedy, sometimes erroneously called "deterministic") are orthogonal. It's the greedy search strategy that leads to linear time performance.
The choice of logic determines the lower-bound (best-case) on parsing complexity. If you do exhaustive search for the exact solution of a shift-reduce dependency parser, it is worst-case exponential. In practice, you don't do exact search, and by using a beam search approximation you can get observed linear-time performance.
[edit: You can read my thesis if you are not familiar with what a parsing logic is.]
I am not aware of state-of-the-art results from greedy shift-reduce parsers. Do you mind sharing?
I assume that this is for English? A former colleague of mine compared two statistical dependency parsers (Malt and MST) to a rule-based dependency parser with a maxent disambiguation model, for Dutch. The rule-based system outperforms the statistical dependency parsers by a wide margin, both in-domain and out-of-domain:
http://dl.acm.org/citation.cfm?id=1870171
Nonetheless, I find work on statistical dependency parsing to be very exiting, since it is fast and requires far less human effort :).
https://github.com/syllog1sm/redshift/ . You'll want the develop branch. It's GPL licensed.
Very nice work!
The cubic time complexity is for exhaustively finding the best parse. In practice you can use various approximation techniques, such as coarse-to-fine parsing used by the Charniak & Berkeley parsers. I believe these two are faster than the Stanford Parser, and the parameters of the approximation can be tuned to have faster parsing at the expense of accuracy. You could probably get a reasonable parse tree for a sentence in one second. The fastest PCFG parser which does not do such approximations is bitpar. Another avenue is to try to use the GPU; there has been some research into this.
Dependency parsers are indeed faster but in general their accuracy cannot be compared to constituency parsers, because the information in the output is of a different nature.
It highly depends on the nature of the material. But, e.g. in Dutch based on samples of newspapers I found that the average is between 16 and 20 tokens.
The grandparent mentions sentences of 100 word (I take that he means tokens). I'd guess that such sentences usually contain one or more dependent clauses, that can be parsed separately if necessary.
In practice you can use various approximation techniques, such as coarse-to-fine parsing used by the Charniak & Berkeley parsers.
Indeed, there are many possible optimizations. Such as: restricting the number of lexical analyses using a part-of-speech tagger (particularly useful in highly lexicalized grammars), guided parsing (e.g. by filtering partial left-corner splines that never lead to a good parse), and beam search.
Dependency parsers are indeed faster
Purely statistical dependency parsers are faster. There are also dependency parsers that use (rule-based) unification grammars. Such parsers can produce dependency structure as a side-effect or even post-processing step and rely on relatively expensive unification of attribute-value structures.
Here is a study on average sentence length showing it at 24 words per sentence: http://ds.nahoo.net/Academic/Maths/Sentence.html
In my own study, I performed analysis on a corpus of a few hundred million sentences of written text and found it at 31 words per sentence.
It would be great if you can point to the use of GPU for parsing.
I had never heard of the bitpar parser, will look into it.
In English, the first noun is almost always the actor of the verb, with subsequent nouns being acted upon. This isn't true for other languages though.
(I'm sure someone will come up with an exception to that rule but for 90% of the cases this is true).
Consider sentences like: "He joined the not-yet-famous Liverpool band in early 1958."
To many human beings the topic is quickly obvious. Parsing won't do the trick.
Removed from that context human beings see that sentence as equally meaningless as a parser, because it is. I'd imagine many young people (who don't have the "correct" reference points) wouldn't have a clue that the sentence is about George Harrison.
In order to properly handle this sentence one would need the same external reference that your brain has. Without the reference the sentence can be discarded as incomplete, since that's what a human would do too.
http://en.wikipedia.org/wiki/Topic%E2%80%93comment#Definitio... e.g. in the sentence (3) As for the little girl, the dog bit her "the dog" is the subject NP, "the little girl" is the topic. That toy example is perfectly parsable without semantics or even probabilities (though take any real-world sentence and I'm betting you'll need more than just grammar).
The article gives an example which I find a bit confusing.
>I ran it on this sentence -
> “Swayy is a beautiful new dashboard for discovering and curating online content.”
>And got this result -
> This sentence is about: Swayy, beautiful new dashboard, online content
That misses "discovering" and "curating", which I think are the most important parts of that sentence.
It's a dashboard for online content. That pretty much implies the picking and finding of said online content to be displayed on the dashboard.
And far worse than buzzwords are adjectives. Does "beautiful" add anything to that sentence?
Discovering is also vacuous. The whole point of a dashboard is to convey information. Do I discover how fast I am going by looking at my car's dashboard? Do I discover my website's traffic by going to Google analytics? Sure, I wouldn't use them if I didn't get the information I need from them. So using an online content dashboard that doesn't deliver online content of some sort would be a waste of time.
Beautiful adds something because not all dashboards are beautiful.
[[[[Swayy,snp],np],[is,[a,[[beautiful,new,dashboard,snp],np],np_],vp],simple_s],for,[[discovering,simple_s],and,[[curating,[[online,content,snp],np],vp],simple_s],s],s]
The method described doesn't tell you what the sentence is about it tells you which things aren't verbs and articles and does a poor job of it.
Granted single sentence keyword extraction is not easy, but this is an awful approach. You'd be much better using Word Frequency analysis to determine the rarest words in the sentence.
------
- "math final today 6-17-09 piece of cake hopefully i should do well since i m a math nerd amp english amp social"
- math, nerd, studies, piece, cake, english, amp, final, hopefully, social, since, should, well, today, do, of,
------
- "anyone want an incredibly designed unique limited edition tee for the summer check out www artcotic com"
- tee, designed, incredibly, unique, edition, limited, summer, anyone, check, www, want, com, an, out, for, the,
Also, FWIW, I wrote an article[2] a while back, focusing on Open Source NLP tools. It was aimed slightly more at business users than developers, so it doesn't dig real deep on the tech side, but there is a list of popular OSS NLP tools that people interested in this topic might find useful.
And if I can throw in another shameless plug (only because I think it will genuinely be of interest, of course), I'll point out this post[3] on Prolog resources, since Prolog often finds application in the NLP world.
[1]: http://stanbol.apache.org
[2]: http://osintegrators.com/opensoftwareintegrators|howyoucanbe...
[3]: http://fogbeam.blogspot.com/2013/05/prolog-im-going-to-learn...
You missed the nicest and most satisfying book ;):
http://www.mtome.com/Publications/PNLA/pnla-digital.html
It is simultaneously an introduction to Prolog and natural language parsing using Prolog.
Natural Language is a beautiful thing.
Maybe later I'll give it a crack :)
(Chunking is not exactly new and PCFG parsing is pretty fast these days.)