Is there a way to use Natural Language Processing (NLP) to transform strings into integers?

I saw some examples of code to transform strings like, for example, "four" into an integer 4, but it was always quite manual. Do you have any more automatic way to do this using NLP?

One thing I noticed when I did the test below was that spacy recognizes both "four" and " 4 " as numbers, which is already a good start, but how do you use this to make the transformation from one type to the other? I don't understand much of language processing natural, so I do not know exactly what the name of the technique would be responsible for this.

nlp = spacy.load("pt")

doc = nlp("quatro vídeos")
for token in doc:
    print(token.text, token.pos_, token.dep_)
# retorna 
# quatro NUM nummod
# vídeos SYM ROOT

doc = nlp("4 vídeos")
for token in doc:
    print(token.text, token.pos_, token.dep_)
# retorna 
# 4 NUM nummod
# vídeos SYM ROOT

Thank you!

Author: Giovana Morais, 2019-11-21

1 answers

I don't believe NLP is used to solve this problem. The main uses of NLP are for text translation, text generation, subtitle generation for images... Currently, Recurrent Neural Networks (RNNs) are used to solve these problems, which are deep neural networks that have a high cost to be trained.

I believe the simplest way to solve this problem is to actually use a dictionary. In this Link there are several Python code examples that solve the problem. You will only need to translate the words from the dictionary into English.

I hope I helped, if you have any questions about NLP applications you can ask:)

 0
Author: Filipe Lauar, 2019-12-22 02:31:41