4 ms·
I'm not that familiar with Haskell and the past week's HN frontpage articles on Monads was just confusing...but what is it about Haskell that makes it more usef
by danso 14y ago
I'm not that familiar with Haskell and the past week's HN frontpage articles on Monads was just confusing...but what is it about Haskell that makes it more useful for NLP than, say, Python?
- yummyfajitas 14y agoNot much. It's a more expressive and cleaner language, but on the other hand python has NLTK + scipy community. Scala (or Java) is another great NLP language. It's got decent libraries (openNLP, mallet, mahout), hadoop, and Scala is almost as nice as Haskell.
- robertfw 14y agoBy extension, Clojure can use those same java libraries
- KirinDave 14y ago> Not much. It's a more expressive and cleaner language, but on the other hand python has NLTK + scipy community. Haskell's mechanisms for defining parsers, lexers, and other pattern match tools is so good it probably passes over the line from "pretty" to "objectively better". A lot of people who need to lex and parse data and then act on it turn to Haskell. It has some really remarkable and efficient libraries. And even for "common" target languages it's reasonable to write extremely fast parsers. With tuning, projects like Aeson are among some of the fastest JSON parsers and writers out there (only a few projects exceed its speed and resource efficiency in ANY runtime).
- robrenaud 14y agoI am guessing you might be conflating parsing natural language with parsing something that has a rigid and well defined grammar (like a programming language). NLP is a whole different beast.
- KirinDave 14y ago> NLP is a whole different beast. The very same patterns that define "packrat-like" parsers (which share a strong relationship to the monadic and "arrow-adic" parsers) can be extended to define things like DFAs and semantic pattern matching. And languages with support for rich, somewhat lazy pattern matching like Haskell and Prolog wipe the floor with eager languages without (e.g., C), which is ideal for semantic analysis. While not an "authority" in the subject, I've spent a lot of time working with some very skilled folks in the field of NLP, Linguistics. Most tools they used (in our case licensed from X/PARC) had C underpinnings for performance, but ultimately consumed specifications that were very much like Prolog or Haskell in character. Talking to some of the linguists who wrote those tools suggested that had GHC existed (or Allegro or a fast prolog been cheaper) then they would have been much easier to write in those languages.
- yummyfajitas 14y agoDo you have more info on this? I'd love to read more.
- KirinDave 14y agoI'm afraid I can't say much more beyond what I have without talking out of my rear. But you can read about X/P's XLE project here: http://www2.parc.com/isl/groups/nltt/xle/ http://www2.parc.com/isl/groups/nltt/xle/
- robrenaud 14y agoMaybe I've been brainwashed by statistical NLP people, but I think this summarizes my understanding pretty well. http://en.wikipedia.org/wiki/Frederick_Jelinek http://en.wikipedia.org/wiki/Frederick_Jelinek > "Every time I fire a linguist, the performance of the speech recognizer goes up" As far as I know, modern, successful NLP systems don't have much human knowledge baked in and are produced by training on large data sets.
- eric_bullington 14y agoI've only played around with Haskell and NLP (using this guide, actually), but functional languages are a very nice fit for natural language processing, which often involves pipelining text (in the form of arrays or lists of characters) from function to function (tokenization->tagging->chunking->extraction). This fits the functional paradigm very well. I really like using NLTK (Python) but if I were more comfortable in Haskell and if Haskell had better NLP libraries, I'd probably switch to Haskell because it's a natural fit for NLP. But I have to agree with your assessment of monads...I've been learning Haskell on and off for over a year and I'm still shaky on monads. I'm still hoping I will eventually experience that same moment of epiphany with monads that I did with recursions when I first started programming.
- fusiongyro 14y agoWhat worked for me was going through worked examples with IO, List, Maybe and State. You don't want to just do List, Maybe and Either or you'll associate it with holding onto particular data. You want to use highly disparate things so you can get to the fully abstract understanding. You might try to understand monoids first, because you already have familiarity with many applications of monoids. The realization "oh, this is just two functions" at the heart of monoids is also what's at the heart of monads, but the applications are different. Desugaring helps a lot too. I learned by avoiding do-notation, but you can learn do-notation at the same time if you try desugaring as you go, so you can make explicit what's going on under the covers. It's like math, you have to keep playing with it until you grok it. I find it's good to try out different expressions in ghci, use :t a lot to see what types are coming back, to build intuition. If you put a few hours into it for a few days in a row, you can probably get to this epiphany in one weekend. The trick is building up enough examples that your brain can generalize it. Nobody's going to learn it by staring at the abstract form and thinking hard--if we did work that way, there would be a lot more use of comonads. That's why it's important to re-type examples. You're not going to be able to write the examples yourself until you understand them, but working through them gives you something to build on, and builds healthy expectations (I'm going to need return here, because the naked value isn't in the monad, etc.) The epiphany is worth it--but don't count on a monad tutorial to help you much, they're mainly a side-effect of other people having the epiphany.
- rotskoff 14y agoParser Combinators are a great example of the advantages of functional programming for this sort of work.