Thursday, March 22, 2018

Deep learning and the next stage of evolution as we would like to see it..

Let's start with --> Deep Learning and looking at Ray's perspective

According to Ray K, basically artificial intelligence is based around below 2 fundamental axioms:

1) Many layer neural nets
2) Law of accelerated returns.

So in terms you can have neural nets - a) do the job for you & b) do the job better by taking output from one neural net and feeding it as input into another.

Currently as it stands - it is estimated that the intelligence level quotient of a machine stands between simulation of one insect brain to one rat brain (we are still not there yet - hard to believe but it is true!).

But having said that - it's not long enough until machine would be able to simulate not only a rat's brain but one human brain - in another 10 years and nearly all human brains by another 40 years.

This is the growth curve - mainly based on the 2nd axiom of - law of accelerated returns.

Now let's talk about the journey here which is a bit complicated.

Cognitive science has always been the subject of interest to many not from today but from late 1800 and early 1900's, study how subjects think.

There are two things that play a key role to ascertaining a cognitive behaviour and having a correct result  -

1) Context interpretation - which get's derived from the learning plus training.
2) Derivational behaviour - which decisions on an unknown based on confidence established in the known.

The 2) one is a bit difficult to achieve until the machine is fully capable to interpreting the context with close to 98% percent probable correctness.

Let's take a simple example to understand both the above points -

Consider an image wherein a group of people are playing cards in a circle and 2 people are smiling at each other, some are thinking and others are confused.

If i look at the picture as a human - i might be able to gauge that the person next to the player is having glasses which give the card details out to the one person in front, which makes them smile as they know what move to make next, and the others are thinking about what move will be made as they don't get to know the card and some are looking at these people and are confused.

So lot of things happening here - and the human mind is capable of -

a) analysing the emotional quantum of each person
b) obtaining a decision what kind of emotion is conveyed
c) connecting the emotions to find deeper insights on the picture, like the glasses worn by the person.
d) connecting the interpretation of what it means to the person sitting in front.
e) negating the emotion of collective smile as opposed to the single person smiling and then
f) deriving a state out of picture.

So this is just a small example of how simple images can be interpreted correctly - image is nothing but a glimpse of a state at one point in time.

As of today - a) & b) might be possible to some extent but c), d), e) & f) is a whole another gamut which has yet not been explored.

An image of this nature will basically lead to the following label - 'at best' - 'A group of people playing cards' or maybe if not at best - 'A bunch of people sitting on a round table'

Now imagine this being a video instead of a picture which makes it more hard to examine because we have put the time in picture and need a to have a vaster neural net to interpret correctly.

What I just talked about above can be summed up as a mix of context interpretation and trained behaviour analysis.. the 2nd part which is basically talking about derivational behaviour is more around the lines of decisioning for which step 1 is context interpretation, say for e.g. - I there is a  child which learns to walk and go around a path notices some objects and before seeing the object again knows about there being an object at place and takes a decision to change it's course.

Well - what i just talked about above leads to developing architectures in AI which lead to cognitive deep learning.

One such architecture can be based around Bayesian model of probabilistic models of cognition, one of the all time topics of interests in Josh's deep learning approaches.

But in simple terms these can be broken down into the below -

Visual Stream --> Learning --> Training --> Cognitive Analysis --> Behaviour --> Result --> feedback to learning.

Well - we talked about deep learning and cognition and discussed architectures around it.. so why are we doing this.

Let's imagine a simple futuristic scenario where I am interested in simple things like for example  - I have bot which help me with my mails - it goes through my mails and gives me mails of interest which have a strong  intent of action or maybe I have a small robo which adapts to my daily home chores and tries to do the same when I am not there or a program which understands the functional need and derives the best possible code based on the need and probability of that need in the near future.

Well - this are just some very very simple examples of what AI can do for us.. but we still have a long way to go to even get to this level.

In our next topic - we will talk about cops - that's AI governance - and the need for a goverance model, along with singularity and ethical ai.


Tuesday, March 20, 2018

AI evolution and it's outcomes - is it still artificial?

AI evolution - in order to understand this first let us consider what is AI?


Artificial intelligence is the intelligence demonstrated via a machine in contrast to the natural intelligence demonstrated via humans.

I am sure everyone is aware of the experiment where human and computer are judged on their responses to test a true artificial intelligent machine.

Now let's move ahead to understand where AI originated from and where it stands today - 

Neural networks and the basis of the AI calculation and logic have been around from  a long time but AI was initially limited to the decisioning based on available computing power and resources.

Hence the true decisioning with close to human capability was never achieved. With the evolution of connected computing and cloud resources along with quantum computing - AI got a bigger engine to incorporate decisioning logic.

Imagine it to be a Saturn V rocket thruster as compared to a standard economy class car with few horse powers - that is the level of boost that was achieved with the kind of compute power that was available for a network to arrive at a decision. 

Along with this we had the storage capacity restraint earlier which went away with virtually unlimited storage availability. 

Because of above two factors AI grew from an infant which doesn't understand anything and talks only few words to a full blown adult with any decisioning capability. 

Now since we covered the journey - let's look at the situation today - what AI is capable of as of today and near future?

As of today - computers have been able to deduce and defeat humans in some of the brain challenging games like AlphaGo but it doesn't end here. Currently big firms are working on developing software which can work on the central brain and take advantage of the AI capabilities - these come as close to humans and sometimes more accurate than humans to identify and decision.

They follow the simple cycle - 

Train --> Deduce --> Decision --> Feedback --> Retrain --> ... 

..and this cycle continues. Thereby they evolve as entities able to decision better and better, at the expense of their experiences with each decision. This means three things -

1. They think faster.
2. They improve their decision capabilities.
3. They don't have emotional qualms which can draw the decision back at times.

What this means is accuracy and precision coupled with focussed results - if used correctly - giving a big gain or profit to human kind, but then it comes at the expense of humans following what the computer predicts which is a bit tricky because once the system understands the 'good' and the 'bad' and then it starts to understand the dependency curve -- 

-- system needs to be good to decision and serve humans better 

where does the thin line of taking a decision for it's betterment to serve humans better goes over a decision to not serve some humans in the best way -- this is like a human thinking about itself - that is where it starts to get a bit muddy.

What should be done to make sure that above doesn't happen? 

Currently humans have an oversight of what is the result of a decision by AI or neural network but don't have any vision of how this decision was achieved - in order to have this - humans should also become by any way possible a part of that decisioning and feedback process. 

This can be achievable by many means - one is to plant a chip to provide that feedback to humans - another can be to install the human thought decisioning on the AI as an end-result.. this fine line is necessary so that the balance is still maintained... 

Currently with the speed at which neural processing is changing - it's going to be very quickly exceeding the human decisioning capability, hence above measures should be good as a stop cork on anything which might go in harms way.


Sunday, March 18, 2018

How to take advantage of readily available API's with AI capabilities

Folks - in this article we would explore some very useful API's which some major companies investing in AI are providing. 

Earlier post was in relation to establishing our own custom made AI & deep learning code base, this tutorial is more on understanding well established concepts in form of API's which are available to be used directly in the code. 

Let's go through them - this post is covering the google apis - one by one - 

1) Vision - check the images and get information about it.
2) Speech - provides automated responses based on context - response guessing.
3) Video - provide search capabilities within a video.
4) Natural Language - provides to understand the written feedback based on the context in which this was triggered.
5) Translation - provide a translation in relation to the context where you are converting to. 


Initially if you just need to check them out and do some test trials - these are free but if you are using them heavily google does charge you for them, but good news - you will get some credit first time you start to use them.


How does it work?

Firebase hosting --> Cloud Storage --> Cloud Functions 

                          --> API (in question) (e.g. - Vision API) --> Firebase Database

1) Vision or Image API is really cool - in the sense it scans an image and will provide the details whether this image is of a landmark or person, if person what is the mood, etc.

for e.g. - json response from an image api might look like - 



{ "responses": [ { "faceAnnotations": [ { .... { "type": "RIGHT_OF_LEFT_EYEBROW", "position": { "x": 965.15735, "y": 349.91434, "z": -7.9691405 } }...
            {
              "type": "UPPER_LIP",
              "position": {
                "x": 960.88947,
                "y": 382.35114,
                "z": -15.794773
              }
         
            ....
            }
          ],
          "rollAngle": 16.3792967,
          "panAngle": -29.3338267,
          "tiltAngle": 4.45867656,
          "detectionConfidence": 0.980691,
          "landmarkingConfidence": 0.57905465,
          "joyLikelihood": "VERY_LIKELY",
          "sorrowLikelihood": "VERY_UNLIKELY",
          "angerLikelihood": "VERY_UNLIKELY",
          "surpriseLikelihood": "VERY_UNLIKELY",
          "underExposedLikelihood": "VERY_UNLIKELY",
          "blurredLikelihood": "VERY_UNLIKELY",
          "headwearLikelihood": "VERY_UNLIKELY"
        }
      ]
    }
  ]
}

So with this API you can get somewhat details about features or mood of the person, if a landmark or building you can get the details of the picture - where it is and likelihood of it being correct.

2.Video API - 

This API can search within a video a particular frame which has that element in it - like for e.g. if there is a cricket match and you want to know when was a catch taken - you could just enter the details of the catch and it will tell in all videos at which point you will see the catch so you can jump to those locations instead of going through the whole video.

Sample response for label detection - 


 "segmentLabelAnnotations1": [
              {
                "entity": {
                  "entityId": "/m/01yrx",
                  "languageCode": "en-US"
                },
                "segments1": [
                  {
                    "segment": {
                      "startTimeOffset": "0s",
                      "endTimeOffset": "14.833664s"
                    },

3. Speech API/Translation API/Natural language processing API

Speech api is used in combination with translation api & natural language processing api. 

So for e.g. if someone sends a message text saying 'does this time suit you - 9 AM?' - the natural language api will understand the context and give a framed response option like for e.g. --> 'yes - it suits me' or 'no - it doesn't, i can suggest another time', the speech API gives you an option to record a response and translate that to text in terms of the context and translation will allow you to translate to another language - pretty cool, no need for interpreter or translator and response engine ! 


Sample response from natural language API -
  "sentences": [
    {
      "text": {
        "content": "Four score and seven years ago our fathers brought forth
        on this continent a new nation, conceived in liberty and dedicated to
        the proposition that all men are created equal.",
        "beginOffset": 0
      },
      "sentiment": {
        "magnitude": 0.8,
        "score": 0.8
PS - referred from google tutorials.

See the score and magnitude - this sets the tone of the text


How to get them installed and working?

You need to have the below in order to get the API's to work - 

Set up node js

  nvm install stable

run nvm 

  nvm

 nvm alias default stable

install yarn 

   curl -o- -L https://yarnpkg.com/install.sh | bash

  yarn --version

  yarn add express

deploy app to gcloud 

  gcloud app deploy


PS: Most of examples are taken from google api docs but shortened for quick illustration.

Tuesday, March 6, 2018

A small explanation of Machine learning & trend analysis.. using TensorFlow

We will understand machine learning by looking at the most common api for ML - tensorFlow.

Machine Learning is trying to make the machine understand how to interpret trends and provide close to accurate results as would a human mind do. 

TensorFlow is a tool which helps doing just that and works with python, java, c++, javascript and some other languanges.

Tensor means : 

A mathematical object analogous to but more general than a vector, represented by an array of components that are functions of the coordinates of a space.


Before we go into the specifics, let's understand how to install and run tensorFlow on a MacOS box.

You need to have Phython installed before we start installing TensorFlow.

Step 1: Install pip and virtualenv

sudo easy_install pip
pip install --upgrade virtualenv


Step 2: Create a target directory for e.g.: 'tens-flow' and establish a virtualenv

virtualenv --system-site-packages tens-flow # for Python 2.7

Step 3: Activate the virtualenv
$ cd tens-flow
$ source ./bin/activate  
Prompt will change to the following -->
(tens-flow)$

Step 4: Start easy_install using pip

(tens-flow)$easy_install -U pip

Step 5: Install tensor flow

(tens-flow)$ pip install --upgrade tensorflow # for Python 2.7


Validate Installation - by the below steps 
$ cd tens-flow
$ source ./bin/activate  

Prompt should change to -
(tens-flow)$

After working and completion you can deactivate the tensorFlow 
environment by using below command.
(tens-flow)$ deactivate 

Okay so now your tensorFlow environment is up and running.
Let's check via simple tensorFlow heartbeat test. 
Type in the following commands and phython program

$ python

# Python
import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))


Output should be : 
Hello, TensorFlow!

If above is true - we are all set!

Now let's continue with machine learning --> Normal data acquisition 
and analysis process:

Raw data collected from real world --> Data is processed --> Clean Data

Clean Data can be fed to --> Exploratory Data for Analysis or Machine Learning Algorithms, Statistical Models or Sent to communicate visualisations 

Machine Learning Alogrithms can then be used to --> Build a data product


Okay so TensorFlow works on the below principles - 

First the graph is constructed

Training is done using the input variables

Estimator is nothing but a form of basic linear regressor model, let's break it down. 

These are steps for any model.
Estimator : train() --> evaluate() --> predict() --> export_savemodel() 
: => Checkpoint.

You need to first train, then evaluate, followed by predict and then 
save a checkpoint state. 

So this workflow evaluates to a checkpoint which is helpful to 
synchronise in a distributed system when they restart.

So let's take a simple example - 

Train phase: 

For e.g. an algorithm which identifies apple types by looking at the 
image or characteristics. 

Let's limit this to 3 types for now - 
  • Fuji, Golden Delicious & Granny Smith
First we develop a simple script which takes three inputs, say images of apples, we need to train this - so how to do that --> 

Check the color of apple - if apple = red , 95% probability it's 'Fuji'

if 'Green' --> it might be 'Granny Smith' more likely.

So with each characteristic we have a set of values which arrives at a result of the image being - how close to accurate - for e.g. -->

Once we start evaluation - we compare probabilities for output with each set of data. 

Predict phase: 

Once evaluation is complete - we can predict the result. Obviously once prediction is close to 100% - the checkpoint is established and saved,

Apple A = can be either

Granny Smith - 99%
Fuji  - 0.01%
Golden Delicious - 0.09%

So tensorFlow helps to do just that! Further it can be used for A/B testing or predicting trends.

You can refer to sample examples on google site to understand the basic tensorFlow and ML training algorithms.

https://opensource.google.com/projects/tensorflow

PS: I have referred to Google tutorials and some videos by experts to give the above picture.

We will discuss about APIs in my next blog and a more interesting tensorFlow example. We will also talk about other models for prediction, stay tuned.

Sunday, March 4, 2018

Delivering a product which involves and not evolves you...


Let's dive in directly onto the point - what is user experience?

Let's understand with an everyday example - in today's world, we talk of AI - Artificial Intelligence and dwelve into dreaming of a magician which can do things for us just by hinting for it.

How? 

Let's take an example - How many times have you been in a car connected to phone via bluetooth and trying your level best to play the right track of music you want or trying to search for a location and unable to get the right result despite your best attempt.

I swear something for the 10 minute drive, one just struggles to get the right track for 8 mins and then gives up.

Well, that's not customer experience - by any way far by off, customer discomfort - maybe - 'yes', and it is definitely not AI. 

Then what is it?

It's a technology which is built around rules for safety made to make a simple task complex to the point of it being a threat to your safety. 

Some would argue - that we should be more 'adept' to the way the voice control works on different phones and use that understanding to 'make it work - right'. Well, if the customer does the hard work and then pays for the product - that's not what was the part of the deal or was it?

Well, now let's come to another argument - am I putting myself in a greater danger when driving to get the voice control to work by distracting myself from driving and running into a disaster, just because someone constructed an app - may be a car sync app which prohibits me to doing things simply and complicates them in a way that is utterly discomforting and annoying.

AI - is by far an overstatement -  not needed in voice controlled devices to run with the cars - simple things which make me do my basic manoeuvres or tasks easily while in a car is what is needed.

It can be as simple as setting up a 'speed dial' to do the same task -- this brings me to my discussion on classifying a product into one of the 4 types in current market - 

1. Which is built for selling, but doesn't have any use.

      These are gadgets which are built for fancy purposes, marked symbols or icons of show off, but might not be useful - it's like taking a 10k $ worth computer, which I use to take notes, just because that's the latest product in market.

2. Which is built for selling, and does have some use.
     
     These may be either gadgets or apps, utilities which are have some use, like the 'scribble' on the apple watch.

3. Which might or might not be built for selling but works for 95% of daily use stuff.

  A low cost notebook which manages my notes, keeps a record of todos, gives me the right note when i need it and gives me features to maintain the notes effictively.

4. Which might or might not be but for selling, works for 99% of daily use stuff and evolves to your needs in future.

    An interactive note app which monitors my notes and gives me suggestions how to organise them based on the type of notes I frequently use, although it always gives me an option to go back to classical view because it knows it's 'smart' but it's not 'me'.
     Or 
 An adaptive search engine (not yet developed - i know some companies have given a try but we are still not there yet)

So today we can put a product into one of the above 4 categories, unfortunately most products fit in either 1 or 2 or maybe if tried hard enough 3 but we are far away from #4.

Once we reach #4 - that's when we start talking AI basics, simple terms are more useful if tasks are just simple.

Thursday, March 1, 2018

Let's talk about space and computing with space in mind..

The human aspect of programming has always been built around the presence of best environments for coding - mostly called as the 'happy' path coding - where you just care about the code and best rest assured everything else would be taken care of with no intended variations.
Well - what is this 'everything else' we are talking about?
Let's take a look.. with an example of today's times..
When you are going into space you need to look at 3 major things - 

1. temperatures -180 degree centigrade to 240 degree centigrade.
2. cosmic rays
3. vibrations

the third one is important during launch but 1 & 2 would always be there once you go into space.
*Any instrument put into space should work with above 3 parameters not affecting the output.
#2 sometimes hits the microprocessor and has a capability to change the parity bit - flip it from 1 to 0 or 0 to 1.
This may cause the microprocessor to give incorrect results - say 100 + 100 = might have one bit flipped and give 240 instead of 200. This can cause major errors in computational and decision making algorithms in place in the computer programs in systems equipped for space.
In order to take care of this the space team employs methods to protect bit flip by using sturdier materials for processor. 

* Companies like SpaceX uses a different technique - it doesn't use all the cores of a 'say' three core CPU - instead it sends the same computation to each core and then evaluates the result, compares it - if there a difference - it restarts the core with error which causes the bit flip to be rectified.
For this to happen at least 3 cores are required to understand which core failed.
* Companies like SpaceX can use above technique and save on costs of building systems with costly materials, and use programming languages which are open source like C++ to develop code for the different navigational programs.
* They use labview to generate the simulations and auto cad for designing - simple everyday applications.
* CI (continuous integration) is heavily used to test the whole launch sequence which has built in tests to launch and navigate - for e.g. for falcon models.
It's cool... looks complicated and might be definitely but is built from every applications and simple materials .. cost effective by using some interesting corrective techniques.