Search code examples
pythonmachine-learningnlpnltktext-processing

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?


Solution

  • 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.