How to identify/recognize that a sentence about talks about future?

Brief Introduction: I have a report/paragraph in which there are sentences with reference to future plans/outlooks/expectations for a particular entity. I want to extract all such sentences for now.

Problem statement: How to identify or recognize such futuristic statement (sentence where they refer to their plans) or How to best segregate the futuristic sentences from other non-futuristic sentences. I’m looking for a traditional programming solution and/or Machine Learning solution.

Languages and packages preferred: Python, Spacy, scikit-learn, keras (backend - tensorflow)

Here is an input paragraph:


“As at the Latest Practicable Date, we have seven dipping lines located at our Malaysian facilities and two dipping lines at our Thai facility. We plan to upgrade our facilities in Malaysia by increasing the number of cleanrooms for laundry and packaging of our products and installing additional cleanroom plant and equipment. In relation to our Thai subsidiary, we intend to install an additional dipping line, increase the number of cleanrooms and upgrade our facilities by adding additional floor space to house additional plant and equipment. “

Copy the above text into paragraph.txt file.

Here is the code to get given text into sentences in a pandas dataframe.


import pandas 
import spacy 

with open(paragraph.txt,'r') as f:
    content = f.read() 

nlp = spacy.load('en_core_web_sm')
sentences = list(nlp(content).sents)
sentences = [str(sentence) for sentence in sentences]
sentences_dataframe = pandas.DataFrame(sentences,columns =[Sentences])
sentences_dataframe[F/NF] = 
sentences_dataframe.head()

Here's the desired result:

S.no Sentences F/NF
1 As at the Latest Practicable Date, we have seven dipping lines located at our Malaysian facilities and two dipping lines at our Thai facility. NF
2 We plan to upgrade our facilities in Malaysia by increasing the number of cleanrooms for laundry and packaging of our products and installing additional cleanroom plant and equipment F
3 In relation to our Thai subsidiary, we intend to install an additional dipping line, increase the number of cleanrooms and upgrade our facilities by adding additional floor space to house additional plant and equipment. F

F – Futuristic, NF - Futuristic

The paragraph has 3 sentences, one row for each sentence and related tags for each sentence

Topic spacy keras scikit-learn nlp python

Category Data Science


import spacy
nlp = spacy.load('en_core_web_trf')

def identify_futuristic(sentence):
    sentence_doc = nlp(sentence)
    if any((token.morph.get('Tense') == [] and
            token.morph.get('VerbForm') == ['Fin'] and 
            token.morph.get('Mood') == [])
           or
           (token.morph.get('Tense') == ['Pres'] and
            token.morph.get('VerbForm') == ['Fin'] and
            token.morph.get('Mood') != ['Ind'])
           for token in sentence_doc):

        return 'F'
    else:
        return 'NF'

sentences_dataframe["F/NF"] = sentences_dataframe['Sentences'].apply(
    lambda s: identify_futuristic(s))

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.