TransWikia.com

Machine learning or NLP approach to convert string about month ,year into dates

Data Science Asked by Bipul on June 12, 2021

I’m currently in the process of developing a program with the capability of converting human style of representing year into actual dates.
Example : last year last month into December 2018
string may be complete sentence like : what were you doing 5 years ago

it will gives 2014

The purpose is to evalute human style of represting year or date into actual date, i have created collection of this type of strings and matching them with regex.

I have read some machine learning but I’m not sure which algorithm suits this problem the best or if I should consider using NLP.

Does anyone have a suggestion of what algorithm to use or where I can find the necessary literature to solve my problem?

Thanks for any contribution!

3 Answers

I got my answer , NLTK is good to go for this problem. You may use sutime with python wrapper :

Python wrapper for Stanford CoreNLP's SUTime

The usual approach in NLP is to collect a dataset required for training. Process that dataset so that the words in the dataset are converted into numbers.

One simple example of converting it into numbers is to make a large dictionary of words from the dataset and use the index of each word in the dictionary as the representing number

Correct answer by Bipul on June 12, 2021

What you need to look for is called "Named Entity recognition". From Wikipedia

Named-entity recognition (NER) (also known as entity identification, entity chunking and entity extraction) is a subtask of information extraction that seeks to locate and classify named entity mentions in unstructured text into pre-defined categories such as the person names, organizations, locations, medical codes, time expressions, quantities, monetary values, percentages, etc.

As it is mentioned in the comments section, Stanford has a great NER Tagger and you could use that together with Python (even if the StanfordNLP is implemented in Java)

Download the jar file from the official url. It has this format stanford-ner-xxxx-xx-xx.zip

You need to put the following two files in the same application folder as your Python script

  1. ner-tagger.jar
  2. ner-model-english.ser.gz (choose another one if you don't want English)

import nltk

from nltk.tag.stanford import StanfordNERTagger  

yourText = this_is_your_text

words = nltk.word_tokenize(yourText)
jar = './stanford-ner.jar'
model = './ner-model-english.ser.gz'

tagger = StanfordNERTagger(model, jar, encoding='utf8')

print(ner_tagger.tag(words))

Then you can grab from the above, anything that is tagged as DATE

Answered by Tasos on June 12, 2021

Sounds like you need a temporal tagger. This is a good rule-based one.

Stanford CoreNLP also has one.

It seems like generally rule-based approaches work well for this task.

Answered by Igor Brigadir on June 12, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP