Virtual Assistant in Python - Efficiency

6

I'm creating a virtual assistant in Python, and I want it to be more "human". I want her to interpret my request, and not just compare what I said with a string. So my question is:

To cover all variations of a request, such as " Will it rain tomorrow? " and " Will I need an umbrella tomorrow? ", an if condition for each request? For example:

if audio == "Vai chover amanhã?":
    checarClima()...

if audio == "Vou precisar de uma guarda chuva amanhã?":
    checarClima()...

outros if's...

This is the way that the great virtual assistants (Siri, Google Now, etc.) are made or there is a technique, a code model that is more efficient and do what I said at the beginning (interpret my request, not only compare with a string)?

    
asked by Denis Callau 07.06.2017 в 15:20

3 answers

2

I received some feedback from other sources:

First take a look at NTLK and learn about Natural Language Processing . Learn about tokenization and tagging and I think it will get somewhere.

This link contains a bit about NLP (Natural Language Processing): link

Summary of link text:

Thinking about the project macro, the flow is:

1. The workflow of a request

Voice request > NLP module processes > API

APIs are the modules that will solve your request (Climate API, Search API, Alarm API, etc.)

2. Tokenization
Function of the NLTK module that will separate each element (word) from the request.
Requisition: "Will it rain tomorrow in São Paulo?"
Request after Tokenization: ["Will", "Rain", "Tomorrow", "In", "Are", "Paul", "?"

3. Removal of "Stop Words" Function of the NLTK module to remove words irrelevant to the request, in this case the words "will" and "in". Post removal request: ["rain", "tomorrow", "are", "paul", "?"]

4. Tagging
Tagging is to classify each word as verb, pronoun, adjective, etc. This is important to make sense of the phrase after tokenization and removal of stop words. NLTK also has a function that does this automatically, but I still have not found out if it supports Portuguese.

5. Named Entity Recognition (NER)
Also a function of NLTK that will say which words are names, places, organizations, etc.

6. Call the APIs
After handling the request, it must be correctly sorted for the correct API to be called. In the example, we are asking if it will rain. The word "raining" should be related to the weather API, so this API will respond to our request.

    
07.06.2017 / 15:56
4

I was not going to answer this question rsrs, but ...

Come on, you want something cool to play with? or something professional?

Professional - You have nowhere to run, you will have to work with neural networks, this demands a well-crafted Artificial Intelligence, everything is segmented word for word, each one receives a certain grammatical classification (verb, adjective, nouns, pronouns, etc), this will separate your entire sentence into grammatical categories, later it will be used to compose the context as a whole, it's really something complex ...

Child's play - At the beginning of the internet, the search engines in the late 90's did not have IA to interpret a phrase entered in the search, but what was it like? - Levenshtein is the answer, a widely used algorithm for finding close / similar words, for example if a person type "abacachi" how would we know he meant "pineapple"? Levenshtein does this, he calculates the minimum distance between two words, imagine in his example:

"Vai chover amanhã?"

"Vou precisar de uma guarda chuva amanhã?"

Imagine that in your system you only have one base knowing the word chuva , temperatura and clima or just three words to define an action for weather forecast, as those three words in your small bank would understand these your sentences?

A: Segment all words and apply Levenshtein algorithm to each word, in the first sentence you will get a good score of the word chover when compared to the word of your bank chuva , ie the word raining will stand out as the best score in relation to the other words of the phrase, this already gives you clues that your phrase may have the climate and you could take an action depending on the scores of the other words in that sentence. The same happens for the next sentence that will have a distance equal to 0 returned by the algorithm of course the two words are equal ...

See the expected results for Levenshtein for his first sentence:

chuva => vai = distancia de 4     
chuva => chover = distancia de 3 
chuva => amanhã = distancia de 6

Shortest distance is the word chover is an excellent score for a word with 6 characters, notice the word vai the word only has 3 characters but has a distance of 4, we can say that it is completely different from the word and it has to be discarded right away, you can get the idea of how everything works / works, this algorithm is still very used ...

    
07.06.2017 в 16:26
2

A virtual assistant relies on a number of much more complex technologies such as AI , machine learning or sentiment analysis .

Siri, for example, was born from a project called CALO . What I suggest is to start by using some kind of technology already tested like HP's Haven on Demand , which even has support for Portuguese, which is rare in this type of projects.

You have a free plan if you want to test, because they even provide the functionality of Speech Recognition. You can view more here .

    
07.06.2017 в 15:59