title: Determining tense of a sentence Python
body: <p>Following several other posts, [e.g. <a href="https://stackoverflow.com/questions/3434144/detect-english-verb-tenses-using-nltk">Detect English verb tenses using NLTK</a> , <a href="https://stackoverflow.com/questions/19966345/identifying-verb-tenses-in-python">Identifying verb tenses in python</a>, <a href="https://stackoverflow.com/questions/2539782/python-nltk-figure-out-tense">Python NLTK figure out tense</a> ] I wrote the following code to determine tense of a sentence in Python using POS tagging: </p>
  
  <pre><code>from nltk import word_tokenize, pos_tag
  
  def determine_tense_input(sentence):
      text = word_tokenize(sentence)
      tagged = pos_tag(text)
  
      tense = {}
      tense["future"] = len([word for word in tagged if word[1] == "MD"])
      tense["present"] = len([word for word in tagged if word[1] in ["VBP", "VBZ","VBG"]])
      tense["past"] = len([word for word in tagged if word[1] in ["VBD", "VBN"]]) 
      return(tense)
  </code></pre>
  
  <p>This returns a value for the usage of past/present/future verbs, which I typically then take the max value of as the tense of the sentence. The accuracy is moderately decent, but I am wondering if there is a better way of doing this.</p>
  
  <p>For example, is there now by-chance a package written which is more dedicated to extracting the tense of a sentence? [note - 2 of the 3 stack-overflow posts are 4-years old, so things may have now changed]. Or alternatively, should I be using a different parser from within nltk to increase accuracy? If not, hope the above code may help someone else!</p>