Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Identifying verb tenses in python

How can I use Python + NLTK to identify whether a sentence refers to the past/present/future ?

Can I do this only using POS tagging? This seems a bit inaccurate, seems to me that I need to consider the sentence context and not only the words alone.

Any suggestion for another library that can do that?

like image 954
JohnTortugo Avatar asked Nov 13 '13 23:11

JohnTortugo


2 Answers

POS tagging - which gives you tags that let you look at the tense of the verb - already takes into account sentence context, so it addresses your issues re. accuracy through context. In fact, POS tagging actually doesn't work properly with words by themselves! Look at this example from Ch. 5 of the NLTK book which, given the context in the sentence, lets NLTK differentiate between nouns and verb given homonyms (i.e. given a word like permit that can have different meanings as a verb and a noun):

Let's look at another example, this time including some homonyms:

  >>> text = nltk.word_tokenize("They refuse to permit us to obtain the refuse permit")
  >>> nltk.pos_tag(text)
  [('They', 'PRP'), ('refuse', 'VBP'), ('to', 'TO'), ('permit', 'VB'), ('us', 'PRP'),
  ('to', 'TO'), ('obtain', 'VB'), ('the', 'DT'), ('refuse', 'NN'), ('permit', 'NN')]

Notice that refuse and permit both appear as a present tense verb (VBP) and a noun (NN). E.g. refUSE is a verb meaning "deny," while REFuse is a noun meaning "trash" (i.e. they are not homophones). Thus, we need to know which word is being used in order to pronounce the text correctly. (For this reason, text-to-speech systems usually perform POS-tagging.)

like image 75
arturomp Avatar answered Nov 03 '22 08:11

arturomp


It won't be too hard to do this yourself. This table should help you identify the different verb tenses and handling them will just be a matter of parsing the result of nltk.pos_tag(string)

Im not sure if you want to get into all of the irregular verb tenses like 'could have been' etc... but if you only want present/past/future this is a very easy parsing task.

I dont know of any library that will do this on its own, and I've always thought of training some model to decide this for me but never got around to it.

There will be some degree of error but it wont be large. I recommend parsing all verbs in order to decide how you want to handle the tense, because in sentences like: I am happy he will see her. The tense is present, but there is a future tense clause ( [that] he will see her ) So this gets into the linguistics of your problem which you didn't elaborate but you get the idea.

like image 6
frankie liuzzi Avatar answered Nov 03 '22 09:11

frankie liuzzi