Natural-language processing

Natural-language processing (NLP) is an area of computer science and artificial intelligence concerned with the interactions between computers and human (natural) languages, in particular how to program computers to process and analyze large amounts of natural language data.

(Click here to read more about it)

Simple Explanation:

NLP can be defined as a processing and understanding of raw human data for example let’s consider a small baby of age 1 or 2 year in front of you and you got a bottle of milk and you say to that kid “hey do you want some milk baby” then all he hears is “blah blah blah blah blah MILK blah” and he properly responds because he’s got a “picture” of a milk bottle in his head connected to the word “MILK” so even when you change the statement to “baby I got a milk bottle with me would you like to have it” the baby will respond in the same manner because he heard the word “MILK”.

Now let’s take a real coding example : There are lots of library/package/module available for NLP for C#, nodejs, python, etc.

I have used nodejs as my preferred language for creating AI bots, so there is a package called “natural” you can install it by using “npm install natural” (GitHub Source)

All you have to do is just define some phrases to the nlp function and it will detect accordingly.

Example pseudo code :

myPhrases = { DrinkMilk: [“bottle”,”milk”,”want”,”drink”] DontDrinkMilk: [“bottle”,”milk”,”dont”,”not”, “no”, “do not”,”drink”] }

//The above variable myPhrases has two set of keys each having predefined set of words to consider while processing the data

InitializeNLP(myPhrases) //Initializes the nlp with the above variable to process the data.

result = ProcessData(“Hey do you want some milk”)

Print(result)

result = ProcessData(“Drink the milk from this bottle”)

Print(result);

//Output #1:

{ probabilities: [ {label : ‘DrinkMilk’ , score: 0.9929102} , { label: ‘DontDrinkMilk’, score: 0.00512200}], guess: ‘DrinkMilk’ } //Output #2:

{ probabilities: [ {label : ‘DrinkMilk’ , score: 0.959212} , { label: ‘DontDrinkMilk’, score: 0.00512200}], guess: ‘DrinkMilk’ }

result = ProcessData(“hey don't drink that milk”)

Print(result) result = ProcessData(“don't drink the milk from that bottle”)

Print(result)

//Output #1

{ probabilities: [ {label : ‘DrinkMilk’ , score: 0.715689} , { label: ‘DontDrinkMilk’, score: 0.00512200}], guess: ‘DontDrinkMilk’ } //Output #2

{ probabilities: [ {label : ‘DrinkMilk’ , score: 0.6562100} , { label: ‘DontDrinkMilk’, score: 0.00512200}], guess: ‘DontDrinkMilk’ }

You can now respond or process the data based on the guesses made by NLP output by using a switch case or if clause e.g :