Our book with Wiley on AI

Thanks, Nisha. Thanks for your kind words. I learned a lot from you, Wil and Michael. I enjoyed being your editor! I benefited greatly from ...

Showing posts with label Demo. Show all posts
Showing posts with label Demo. Show all posts

Tuesday, January 15, 2019

Demo Bot for getting information from Spreadsheet

Here is the demo of bot that gives you information from the spreadsheet.
When you ask the question it reaches the server side application which in turn
connects to the googles spreadsheet API and then fetches the data from the spreadsheet.

The idea is to show how a talking bot can answer a lot of question for the Sales bosses who have lot of information in the spreadsheet.

Of course this is a bare minimum a demo. One can build a much richer and more comprehensive information handling AI-Bot. That can even show options, charts, and even send emails and messages.


How to use the demo;

Take a look at the spread sheet
The spreadsheet is here:

https://docs.google.com/spreadsheets/d/1ZmpEYAFY4VDwBSSQ6O-MD4bVbEe5bsCsTddCU0xPMUw/edit#gid=0

Ask questions like

What is the sales for Alex?
How about John?
How about Susan?

It's a bit racist Bot :). It trains easily more on Amrican names. So I have used more American names.


For the voice Demo click the mic icon and speak into it






Demo - Recommendation engine


Here is the demo of a recommendation engine. It is done using the Neural network.
There are 4 hidden layers.

You need to rate the shirt shown where 1 is least liked and 5 is liked the most. Based on the feedback you gave the network feeds the image data and comes us with the other liked images/shirts.


The demo keeps on showing you shirts to rate. It improves its understanding of your liking each time you rate. Keep simple preference like - one color shade and a neckline V. Something like that.


Check the rating of the recommended items given below the suggested shirts. 99% means the AI engine thinks you are very likely to  like it.







Sunday, December 2, 2018

Demo 3 on Reinforcement learning - old school way


Demo of this kind looks pretty interesting at the graphical level. Under the hood however, these are simple mathematics and some logic. Maybe the kinds of the engines that play chess or Go are complex. But, quite a few of them are fairly simple, logical math.

In this example of reinforcement learning (You may read the paper here). Demo environment is a 5 by 5 square board. There is an Agent at the top left corner and he has to learn

To reach the right bottom corner, H. And,
To reach there by the shortest or near shortest possible path/s.
The Agent’s World (See the live demo here)

Watch all the 15 episodes - It should take about 4-5 minutes.




The agent A can move right, left, up, down and diagonal right/left up/down. One square at a time.

Initially the agent doesn’t know where the H is. In other words he has no knowledge of the destination and he has to learn to get there. What he knows however, is how to make those moves as we mentioned above and capacity to learn in this demo environment.

For the sake of simplicity I have kept the destination fixed. As such we can make the destination dynamic and the same capacity of the agent, - the learning algorithm - works for the learning part. This is based on the q-table the old school algorithm for reinforcement learning where we make the machine learn without labelled data that we keep hearing about in deep learning or neural-nets.

Here in the demo the A starts random. He randomly moves around the demo world(5 X 5 board). In a way we can say his objective is a given, that is hard coded. In other words, he doesn’t learn about the objective. He learns and gets smarter about the path to get there.

Where is the learning here?

Demo is not hard coded to reach A to H after some random moves. It is coded to find out the shortest path to H. As the A moves up down etc he kind of learns. A has track of his moves and the state or the board position he is in. Each move(Not exactly) makes the A more learned about the environment and hence the path to get to his destination.

How does the q-table algorithm work

At the heart of the learning is the Q-table. Where we build the state and the possible actions that he can make from that state. For instance, A can from the start position can make 3 moves, - to the right, to the diagonal-down, to down.

Initially the agent moves randomly and some how he reaches the H thanks to the chance and the brute force computing ability of the computers. Once he reaches the H, Agent is given an incentive, i.e q table is updated. The action that made him reach that terminal position is given a highest q value.

Position of Q-table after some moves




Action codes are as follows

1 = right, 6 = diagonal-down left, 7 = down, 8 = diagonal down right, -1 = left, -6 -diagonal down up right, -7 up, -8 = diagonal up left.

Now the fresh episode starts and the agent again moves randomly with the brute force. This time, he may reach H OR, OR.. the other position which helped him reach to the H in the previous episode. If he reaches the H then, just like the previous episode, the state and the action from which he reached gets the same q value. On the other hand if he reaches the H-1, state, he will now update the q-table for that action with slightly discounted q value.

As you can see now, with each episode as the q table gets updated with q values, after certain number of episodes the q-table, the table of actions from each states - gets fully updated with q-values.

So how did A learn?

Okay, there is another built in capacity of the agent here which I forgot to mention. In fact it is best, I mentioned it here in a way. Agent, choses his action not randomly. Before he moves, he first checks the q value of all the possible actions from the state, or position he is in and then choses the the action with the highest q value. How then he moved randomly initially? Because q table was 0 for all the actions earlier and it appeared random.





Tuesday, October 16, 2018

Demo - How does the regression AI work?

Here is a demo that illustrates how the AI works.

In this demo an AI learns to draw a line through all the points in a graph. For a given set of 20 plus points randomly placed on a canvas it learns to draw a line that cuts through it all. 

In a strict mathematical sense - it is not the right way to explain this, however for the purpose of easier understanding  we can get started this way.

Click somewhere on the canvas to add another point. As you do that you will see how the AI learns and draws a line that cuts through those points that you add. It may not succeed all the time. In most cases however it succeeds. Just wait a little and see. In some cases we may have to wait a minute or so before it starts adjusting the line.

Initially you may add the point that is kind of easier for the AI to guess. Like adding a point where the line is naturally glowing. Then you can give it a bit difficult options. Easier could be adding a point or clicking somewhere close to the line especially where it is not crowded. 


Here it is..



This is designed using the deep neural net, a form of ML  which is hugely popular thanks to the Google's deep mind which outsmarted the world champions of the GO game. 

Okay, what is going on here ?

As I said under the hood explanation is different.

Behind this visual is a small program that does predictions. Based on given set of input points it predicts the line, the other points. It is like predicting stock price given a profit of the company like thing. If profit is 1 million, stock price is USD 20, when profit is 1.2 million 34 usd or whatever. Something of that kind.

Line that the AI  draws is on a graph.  Along the horizontal axis is variable X the input. X can take values like lets say, 1,2,3,4 etc and then along the vertical axis the Y value is computed as a function of X. So, this is like when x is 1, Y is 3 and when x is 5 Y 8 and so on. 

Initially 20 such points of x and corresponding values of Y (which is on the vertical axis) is loaded. The AI approximates a function to explain those points.

Neural net trains on these 20 pints - Y as a label and x as input.
Then it predicts some lets say 1000 other values of Y for all the Xs along the horizontal line.  These points are not thick red circles but tiny black ones and hence look like a line.

When you add a point there is a new data that the neural net trains itself on. For every tenth of second it loads all the points with the new point you added to learn and back propagates to adjust the weights. Every tenth of the second a new line is drawn, new 1000 predictions are made. This is like quantum view of the world and the real view of the world

Big deal you say. How is it different from the intelligent snake game or solitaire games the games that play against humans?

Its is bit tricky a thing to answer. They are intelligent no doubt. In those games, the programming paradigm is different. The intelligence there in Solitaire is fixed. It does not learn anything new.  Where as in the line drawing AI, it learns to draw. It is dumb in the beginning. It just draws a random line initially. It learns to draw the line through the point over time. Just refresh the page and carefully watch as the graph loads. In few seconds it learns to draw the line. When you add a point again it learns. You can watch the AI adjusting the line slowly in some cases. This is a different paradigm of programming.








Friday, September 14, 2018

Really simple demo on Reinforcement learning

Ever since the AlphaZeroGo learnt the Chinese game GO on its own to beat the GO world champions, there has been kind of new awakening in Machine Learning space. Innovative companies are investing in ML initiatives hoping to master it for big gains in the future.


It takes about 60-70 minutes for the agent(9 eyed worm) to learn. Best way is to watch for few minutes and then go do something else for about an hour and come back. Make sure you keep this browser window live for that long.

A Demo can be a nice way to quickly understand the essence of the concept





This was originally developed by Andrej Karpathy former researcher and AI director at Tesla.
I have slightly modified it to make it less mathematical and changed settings for speedier learning.
You may also Use these controls for better understanding


Brief explanation

In this demo the Agent(worm) with 9 eyes has to find apples, red circles and eat. He needs to learn to avoid eating poison, green circles. Worm has ability to move in 5 angles and is constrained by the wall, grey line. It also has to learn to find the apples faster over time.

You can see in the demo that gradually, in about 60-70 minutes, the agent learns to find apples faster and eat them. It learns to carefully avoid the poisonous green circles and gets away from them.

If you are someone impatient like me and cannot wait that long, you may hit the pre-trained agent to see how it behaves once he has learnt and mastered the tricks over a period of about an hour.

This was originally developed by Andrej Karpathy former researcher and AI director at Tesla. I have slightly modified it to make it less mathematical and changed settings for speedier learning.




Thursday, July 5, 2018

Fake news game - Cambridge


The spread of online misinformation poses serious challenges to societies worldwide. In a novel attempt to address this issue, few researchers in collaboration with Cambridge University have designed a psychological intervention in the form of an online browser game. 

In the game, players take on the role of a fake news producer and learn to master six documented techniques commonly used in the production of misinformation: polarisation, invoking emotions, spreading conspiracy theories, trolling people online, deflecting blame, and impersonating fake accounts. 

The game draws on an inoculation metaphor, where preemptively exposing, warning, and familiarising people with the strategies used in the production of fake news helps confer cognitive immunity when exposed to real misinformation. 



Play the game here - https://getbadnews.com/#intro


Read more