Live data from Hacker News

Ask HN: Natural language processing to identify grammar in a text?

news.ycombinator.com

11–20 of 25 posts

Re: Ask HN: Natural language processing to identify grammar in a text?

#11
post #9
post #6

On recent debians/ubuntu, PoS tagging is just one apt away: $ sudo apt install -y apertium-eng $ echo "I have been searching for a tool that can scan a paragraph" |apertium eng-disam|grep -v '^;' " " "prpers" prn subj p1 mf sg " " "have" vbhaver inf "have" vbhaver pres " " "be" vbser pp " " "search# for" vblex ger SELECT:177 " " "a" det ind sg " " "tool" n sg " " "that" cnjsub "that" prn dem mf sg "that" prn rel an m…

That rule is really rather limited. More in general, I doubt you can properly recognise passive constructions without doing constituent parsing, passive is really a syntactic construction, not a morphological one.

Or dependency parsing. But unfortunately the English package in Apertium doesn't have a syntax CG (there are proprietary English syntax CG's out there, with syntactic function labelling and dependency relations, while in Apertium there are syntax CG's for some other languages).

OTOH, what's the goal? If you just want to flag some high-frequency constructions you can get quite far with very little depth.

Re: Ask HN: Natural language processing to identify grammar in a text?

#12
As someone else alluded to, this is a task for multiple models. Fortunately, there are a lot of great NLP libraries that combine multiple pre-trained language models into a single pipeline you can interface with, like Stanza. From their docs, their vanilla pipeline breaks down the sentence "Barack Obama was born in Hawaii. He was elected president in 2008." as :

('Barack', '4', 'nsubj:pass')

('Obama', '1', 'flat')

('was', '4', 'aux:pass')

('born', '0', 'root')

('in', '6', 'case')

('Hawaii', '4', 'obl')

('.', '4', 'punct')

It should be very easy to deploy Stanza's pipeline as an API endpoint. Here is an example of such a NLP-library-as-API endpoint, albeit with Hugging Face's Transformers, deployed via Cortex: https://github.com/cortexlabs/cortex/blob/master/examples/py...

Re: Ask HN: Natural language processing to identify grammar in a text?

#13
Sadly, this doesn't exist yet.

You will find that most Natural Language Processing (NLP) tools conceptualize linguistic categories differently from how teachers do (language teaching isn't linguistics, there are often simplifications happening, and schoolbooks get updated more slowly than linguistics evolves).

Examples:

* English verbs have only two tenses: PAST or NONPAST. They can have PERFECTIVE aspect or not. They can have PROGRESSIVE aspect or not. Since these are 3 binary choices, there are at least 8 different ways how English verbs can be realized. I think there'd be less confusion in school if a more linguistically correct version was taught that separates out tense and aspects.

* "Future" or "Present Perfect" (something I still got taught in school) don't exist for a proper linguist.

To build what you suggest, existing tools could be combined, but there would have to be a mapping layer on top of syntactic parsers like Charniak Parser, Collins parser or MaltParser. Another mis-match between grammar in school and linguistics is single versus multiple theories: in school, people usually teach constituent trees, whereas in linguistics phrase structure (constituent) grammar is one theory among many, one alternative (valency and dependency grammar) that does not rely on trees but focuses on the relations between words has recently gained a lot of traction in linguistic circles.

Re: Ask HN: Natural language processing to identify grammar in a text?

#15
post #13

Sadly, this doesn't exist yet. You will find that most Natural Language Processing (NLP) tools conceptualize linguistic categories differently from how teachers do (language teaching isn't linguistics, there are often simplifications happening, and schoolbooks get updated more slowly than linguistics evolves). Examples: * English verbs have only two tenses: PAST or NONPAST. They can have PERFECTIVE aspect or not. The…

Considering the success of Grammarly, it is most likely possible to do it with traditional rule-based/experts systems combined with a tiny bit of modern day ML. But there is nothing available out of the box for that.

Re: Ask HN: Natural language processing to identify grammar in a text?

#16

As someone else alluded to, this is a task for multiple models. Fortunately, there are a lot of great NLP libraries that combine multiple pre-trained language models into a single pipeline you can interface with, like Stanza. From their docs, their vanilla pipeline breaks down the sentence "Barack Obama was born in Hawaii. He was elected president in 2008." as : ('Barack', '4', 'nsubj:pass') ('Obama', '1', 'flat') ('…

A language model is a model that predicts the probability of a given text, that is all. It should not be conflated with other types of NLP tasks like part of speech tagging. I'm guessing the popularity of transformer based models, which are built around the LM task and then adapted to other donations, is leading to this confusion.

Re: Ask HN: Natural language processing to identify grammar in a text?

#17
To do the grammar tense analysis, you can use spaCy or another syntactic parser. The parse tree won't directly give you the exact grammar tense, you will need to do some simple analysis of the conjugational form of the root verb, and the auxiliary verbs that are attached to it.

I've done extensive work in this area, including developing my own statistical parser from scratch. I'd be happy to chat more about this project, my email is daniel dot burfoot at gmail.com.

Re: Ask HN: Natural language processing to identify grammar in a text?

#18
I actually (sort of) wrote one of these a while back (though I don't think I ever got to implementing tenses - possibly this would be somewhat easy to implement on top of whatever I already built there, but maybe not idk). In any case:

> copulae verbs, linking verbs, terms that are often filtered (i.e. stop terms), question terms, time sensitive nouns, amplifiers, clauses, coordinating conjunctions, negations, conditionals (ORs), and contractions

https://github.com/nyxtom/salient/

Re: Ask HN: Natural language processing to identify grammar in a text?

#20
Some tough love:

There will always be a gap between "your judgement" and the "judgement baked into a model" -- worse yet, if the model is very general and oriented towards cheap computation and away from expensive people it will have vague and contradictory judgements inside it that make the results meaningless.

That is the language of failure: the structure of success looks like the following.

(1) The system works like a "magic magic marker", that is, you mark up a lot of text (say 20,000 sentences) the way you think it should be marked up. This might be a character-at-a-time or word-at-a-time. Character-at-a-time is real and eternal, word-at-a-time is not real because there is not really such a thing as a "word". (e.g. "red ball" can fill slots that take "ball", you can smash together subwords to make words, for that matter people violate punctuation rules "Amazon.com announced that...", people call themselves n3pg34r, ...) So if you segment the text up front and segment it the wrong way you may throw out essential information and choose to fail.

(2) You need some system to mark up the text manually and efficiently. It is a lot of work. A typical person can make about 2000 or so up/down judgements a day; if a sentence counts for 10 decisions then maybe you can annotate 200 sentences a day. If you can get students to do it and get teachers to review it you might make short work of it.

This annotator

http://brat.nlplab.org/

ticks the requirements, but most people find it terribly hard to use and wind up building "easy to use" systems that don't align things right at level (1) and... fail.

Assuming you do (1) and (2) the odds are in your favor, but you have to now

(3) build models; it does not matter if the model is a bunch of rules you cobbled together, or hidden markov, or LSTM, or convolutional. Off the top I would train an LSTM to 'predict the next character' on maybe 100M characters of text, then I would stick a simple model that takes the LSTM state as an input and labels characters at the output (could be SVM, Random Forest, Logit, or 3 layer on NN)

(4) Accept that the system is not going to be perfect, but have the ability to manually patch wrong results, improve the training data over time. I'd say this is a more important practice than any particular approach to (3)

Some tool could give you (1-4) tied up in a bow

https://www.tagtog.net/

claims to. But (2) involves elbow grease that 90% of people aren't going to do. Some of the 10% of people who do that elbow grease will succeed, the other 90% will fail.

Post reply on HN