Learn everything about Analytics

6 Deep Learning Applications a beginner can build in minutes (using Python)

SHARE
, / 16

Introduction

Deep Learning has been the most researched and talked about topic in data science recently. And it deserves the attention it gets, as some of the recent breakthroughs in data science are emanating from deep learning. It’s predicted that many deep learning applications will affect your life in the near future. Actually, I think they are already making an impact.

However, if you have been looking at deep learning from the outside, it might look difficult and intimidating. Terms like TensorFlow, Keras, GPU based computing might scare you. But,  let me tell you a secret quietly – it is not difficult! While cutting edge deep learning will take time and effort to follow, applying them in simple day to day problems is very easy.

It is also fun. I kind of re-discovered the fun and curiosity of a child while applying deep learning. Through this article, I will showcase 6 such applications – which might look difficult at the outset, but can be achieved using Deep Learning implementation in less than an hour. This article is written to showcase these ground-breaking works and give you a taste of how they work.

Let’s start!

 

P.S. We assume that you would know basics of Python. If not, just follow this tutorial and then you can start from here again.

 

Table of Contents

  1. Applications using existing APIs
    • Advantages & Disadvantages of Deep Learning API
    • Colorize photos using Deep Learning  with Algorithmia API
    • Building a ChatBot with Watson API
    • News Aggregator based on Sentiment with Aylien API
  2. Open Sourced Applications
    • Advantages & Disadvantages of Open Sourced Code
    • Sentence Correction with Deep Learning
    • Convert Male portraits to female and vice-versa with Deep Learning
    • Build a deep reinforcement learning bot to play Flappy Bird
  3. Other Notable Resources

 

1. Applications using existing APIs

APIs are nothing but a software running on the other side of the internet in a remote PC which can be accessed locally. For example, you plug in bluetooth speakers to your laptop even if your machine might have inbuilt speakers. So, we are able to access the speaker remotely while sitting on our laptop.

APIs work on similar concept – some one has already done the hard work for you. You can use it to solve the problem at hand quickly. For more details on API, read here.

I’ll list out some advantages and disadvantages of building apps using API.

 

1.1.1 Advantages of Deep Learning API’s

  • A usual deep learning application requires heavy computation power in terms of GPU’s and data storage / processing. So you can set a workstation of your own (or use any of the cloud services) and use any system locally to access the workstation and run your applications.
  • Local system is not burdened by the computations
  • New functionalities can be integrated easily

 

1.1.2 Disadvantages of Deep Learning API’s

  • Building an API may not be effective in terms of cost. An API requires both time and resources to develop and maintain, which is somewhat tedious.
  • You are limited by the internet connection. If you connection fails anytime, the whole system breaks down.
  • Your application is exposed security wise, as anyone can access it easily. Here you have to put extra security layers like username and password to access the service and limiting how many times you can access in a duration

If you want to know more about what API’s are, check out this blog

Let’s start with our applications!

 

1.2 Colorize photos using Deep Learning (Algorithmia API)

Automated Image Colorization has been a topic of interest among the computer vision community. It seems surreal to get a colorful photo of a black and white image. Imagine a 4-year old picking up a crayon and gets engrossed in his coloring book! Could we teach an artificial agent do the same and just “imagine” stuff?

Of course, this is a hard problem! This is because we as humans get “trained” each and every day by seeing how things are colored in real life. We might not notice but our brain is capturing each moment of our lives and extracting meaningful information from it, such as sky is blue and grass is green. This is hard to model in an artificial agent.

A recent study shows that if we train a neural network enough on a large number of the especially prepared dataset, we can essentially get a model which could “hallucinate” colors in a grayscale image. Here’s a demonstration of an image colorizer:

To practically implement this, we use an API developed by Algorithmia.

Requirements and Specifications:

  • Python (2 or 3)
  • Internet connection (for calling API endpoint)
  • 12 algorithmia credits (Although credits are paid, algorithmia provides 5000 credits free on signup)

 

Step 1: Register on Algorithmia and get your own API key. You can find your API key in your profile

 

Step 2: Install algorithmia by typing

pip install algorithmia

 

Step 3: Select a photo you want to colorize and upload it to the data folder provided by algorithmia.

 

Step 4: Create a file locally and name it trial1.py . Open it and write the code as below. Notice that you have to insert the location of your image in data folder and API key

import Algorithmia
 input = {
"image": "data:// … " # Set location of your own image
}
 client = Algorithmia.client(‘…’) #insert your own API key
 algo = client.algo('deeplearning/ColorfulImageColorization/1.1.5')
 print algo.pipe(input)

 

Step 5: Open command prompt and run your code by typing “python trial.py”. The resulting output will be automatically saved in your data folder. Here’s what I got:

 

 

 

 

 

 

 

 

That is it – you have just created a simple application which acts as a child and can fill in colors in images! Exciting stuff.

 

1.3 Building a ChatBot (Watson API)

Watson is a great example to show what an artificial agent can achieve. You may have heard the story of Watson beating humans at a Question and Answering game. Although Watson uses an ensemble of many techniques for working, deep learning still is a core part of its learning process, especially in natural language processing. Here we would use one of the many applications of Watson, to build a conversation service, aka chatbot. A chatbot is an agent that respond as humans do on common questions. It can be an excellent point of contact to customers and respond to them in a timely manner.

Here we would use one of the many applications of Watson, to build a conversation service, a.k.a chatbot. A chatbot is an agent that respond as humans do on common questions. It can be an excellent point of contact to customers and respond to them in a timely manner.

Here’s a demonstration of the platform:

Requirements and Specifications:

  • Python (2 or 3)
  • Internet connection (for calling API endpoint)
  • An active Bluemix account (trial period lasts for 30 days)

Let’s see a step-by-step example of how to build a simple chatbot with Watson.

 

Step 1: Register on Bluemix and activate your conservation services to get your credentials

 

Step 2: Open terminal and run command as below:

pip install requests responses
pip install --upgrade watson-developer-cloud

 

Step 3: Make a file trial.py and copy the following code in it. Remember to put your own credentials in it.

import json
from watson_developer_cloud import ConversationV1

conversation = ConversationV1(
username='YOUR SERVICE USERNAME',
password='YOUR SERVICE PASSWORD',
version='2016-09-20')

# replace with your own workspace_id
workspace_id = 'YOUR WORKSPACE ID'

response = conversation.message(workspace_id=workspace_id, message_input={
'text': 'What\'s the weather like?'})
print(json.dumps(response, indent=2))

Step 4: Save your file and run it by typing in console “python trial.py”. You will get an output in the console which would be the response of Watson for your input.

Input: Show me what’s nearby

Output: I understand you want me to locate an amenity. I can find restaurants, gas stations and restrooms nearby.

If you want to build a full-fledged project of conversation service with animated car dashboard (as shown in the above gif), view this github repository.

A chatbot and an application to color images in under a few minutes – not bad 🙂

 

1.4 News Aggregator based on Sentiment (Aylien API)

Sometimes we want to see only the good in the world. How cool would it be to filter out all the bad news when reading a newspaper and only see “good” news!

With advanced natural language processing techniques (one of which is deep learning), this is becoming increasingly possible. You can now filter out news by sentiment and present it to the readers.

We will see and application of this using Aylien’s News API. Below are the screenshots of the demo. You can build your own custom query and check out the result for yourself.

Let’s see an implementation of this in python

Requirements and specifications:

  • Python (2 or 3)
  • Internet connection (for accessing API endpoint)

 

Step 1: Register for an account on Aylien website.

 

Step 2: Get API_key and App_ID from your profile when you login

Step 3: Install Aylien News API by going in your terminal and typing

pip install aylien_news_api

Step 4: Create a file “trial.py” and copy the following code

import aylien_news_api
from aylien_news_api.rest import ApiException

# Configure API key authorization: app_id
aylien_news_api.configuration.api_key['X-AYLIEN-NewsAPI-Application-ID'] = ' 3f3660e6'
# Configure API key authorization: app_key
aylien_news_api.configuration.api_key['X-AYLIEN-NewsAPI-Application-Key'] = ' ecd21528850dc3e75a47f53960c839b0'

# create an instance of the API class
api_instance = aylien_news_api.DefaultApi()

opts = {
  'title': 'trump',
  'sort_by': 'social_shares_count.facebook',
  'language': ['en'],
  'published_at_start': 'NOW-7DAYS',
  'published_at_end': 'NOW',
  'entities_body_links_dbpedia': [
    'http://dbpedia.org/resource/Donald_Trump',
    'http://dbpedia.org/resource/Hillary_Rodham_Clinton'
  ]
}

try:
    # List stories
    api_response = api_instance.list_stories(**opts)
    print(api_response)
except ApiException as e:
    print("Exception when calling DefaultApi->list_stories: %s\n" % e)

 

Step 5: Save the file and run it by typing “python trial.py”. The output will be a json dump as follows:

{'clusters': [],
'next_page_cursor': 'AoJbuB0uU3RvcnkgMzQwNzE5NTc=',
'stories': [{'author': {'avatar_url': None, 'id': 56374, 'name': ''},
'body': 'President Donald Trump agreed to meet alliance leaders in Europe in May in a phone call on Sunday with NATO Secretary General Jens Stoltenberg that also touched on the separatist conflict in eastern Ukraine, the White House said.',
'categories': [{'confident': True,
'id': 'IAB20-13',
'level': 2,
'links': {'_self': 'https://api.aylien.com/api/v1/classify/taxonomy/iab-qag/IAB20-13',
'parent': 'https://api.aylien.com/api/v1/classify/taxonomy/iab-qag/IAB20'},
'score': 0.3734071532595844,
'taxonomy': 'iab-qag'},
{'confident': False,
'id': 'IAB11-3',
'level': 2,
'links': {'_self': 'https://api.aylien.com/api/v1/classify/taxonomy/iab-qag/IAB11-3',
'parent': 'https://api.aylien.com/api/v1/classify/taxonomy/iab-qag/IAB11'},
'score': 0.2898707860282879,
'taxonomy': 'iab-qag'},
{'confident': False,
'id': 'IAB10-5',
'level': 2,
'links': {'_self': 'https://api.aylien.com/api/v1/classify/taxonomy/iab-qag/IAB10-5',
'parent': 'https://api.aylien.com/api/v1/classify/taxonomy/iab-qag/IAB10'},
'score': 0.24747867463774773,
'taxonomy': 'iab-qag'},
{'confident': False,
'id': 'IAB25-5',
'level': 2,
'links': {'_self': 'https://api.aylien.com/api/v1/classify/taxonomy/iab-qag/IAB25-5',
'parent': 'https://api.aylien.com/api/v1/classify/taxonomy/iab-qag/IAB25'},
'score': 0.22760056625597547,
'taxonomy': 'iab-qag'},
{'confident': False,
'id': 'IAB20',
'level': 1,
'links': {'_self': 'https://api.aylien.com/api/v1/classify/taxonomy/iab-qag/IAB20',
'parent': None},
'score': 0.07238470020202414,
'taxonomy': 'iab-qag'},
{'confident': False,
'id': 'IAB10',
'level': 1,
'links': {'_self': 'https://api.aylien.com/api/v1/classify/taxonomy/iab-qag/IAB10',
'parent': None},
'score': 0.06574918306158796,
'taxonomy': 'iab-qag'},
{'confident': False,
'id': 'IAB25',
...

Woah! I can visualize a chatbot at your service and a service like Alexa reading you news of your interest now! I am sure, you will be as excited about deep learning by now!

 

2. Open Source Applications

The best thing that’s helping the research community right now is its open source mindset. Researchers are ready to share whatever they achieved so that deep learning research would grow, and as a result, its growing leaps and bounds! Here I mention some of the open source contributions and their variants which have been created from research papers.

 

2.1.1 Advantages of Open Source applications

  • As the applications are open sourced, you can see each and every detail of the application and easily customize them if you want
  • Many developers from different organizations and experiences collaborate in the application. This makes the application better than the original version. Also, as many people can use it, it can be considered as constantly tested and hence more ready for use.

 

2.1.2 Disadvantages of Open Source applications

  • There might be less “ownership” in an open-source product, as there is no organization backing them. So if they break no one is to blame!
  • There are obvious licensing issues included and many companies would not prefer to release their projects as “openly”.

Note: For open sourced applications, I would recommend you to go through their official repository. This is because some of them are still in infancy stage and may break for unknown reasons

Let’s look at some open source applications!

 

2.2 Sentence Correction with Deep Learning

The systems nowadays can easily detect and correct spelling mistakes, but correcting a grammatical error is a bit harder. To improve on this a bit, we can use deep learning to correct these sentences for us. This repository is an attempt especially for that.

Here’s a sequence predicting neural network was trained on a corpus of grammatically wrong sentences along with its corrected counterpart. The trained model shows promising results for sentence correction. Here’s an example below:

Input: ‘Kvothe went to market’
Output: ‘Kvothe went to the market’

You can check out a demo on the site: http://atpaino.com/dtc.html

The model still fails to correct all the sentences, but with more training data and efficient deep learning algorithms, the results could be improved.

Requirements:

  • Python (2 or 3)
  • GPU (optionally for faster training)

 

Step 1: Install tensorflow from their official website. Also, download the repository from GitHub and save it locally from https://github.com/atpaino/deep-text-corrector

 

Step 2: Download the dataset (Cornell Movie-Dialogs Corpus) and extract it in your working directory

 

Step 3: Create the training data by running the command

python preprocessors/preprocess_movie_dialogs.py --raw_data movie_lines.txt \
               --out_file preprocessed_movie_lines.txt

And create train, validation and test files and save them in the current working directory

 

Step 4: Now train the deep learning model by:

python correct_text.py --train_path /movie_dialog_train.txt \
               --val_path /movie_dialog_val.txt \
               --config DefaultMovieDialogConfig \
               --data_reader_type MovieDialogReader \
               --model_path /movie_dialog_model

 

Step 5: The model requires some time to train. After training, you can test it by:

python correct_text.py --test_path /movie_dialog_test.txt \
               --config DefaultMovieDialogConfig \
               --data_reader_type MovieDialogReader \
               --model_path /movie_dialog_model \
               --decode

 

2.3 Convert Male portraits to female and vice-versa with Deep Learning

Before I speak anything on the application, just observe the following results:

Here the first image is converted into second by a deep learning model! This is really a fun application to show what deep learning can do! In its core, the application uses GAN (generative adversarial network), which a type of deep learning which is capable to new examples on its own.

Requirements:

  • Python (3.5+)
  • Tensorflow (r0.12+)
  • GPU (optional for faster training)

Just a warning before you implement this. Training a model takes too long if you are not using a GPU. Even with a high-end GPU (Nvidia GeForce GTX 1080), the training takes 2 hours for one image.

 

Step 1: Download the repository and extract it locally https://github.com/david-gpu/deep-makeover

 

Step 2: Download the “Align&Cropped Images” from CelebA dataset. Create a datasets folder by name “dataset” and extract all images in it

 

Step 3: Train the model by:

python3 dm_main.py --run train

and then test it by passing the image you want to convert

python3 dm_main.py --run inference image.jpg

 

2.4 Build a deep reinforcement learning bot to play Flappy Bird

You may have played Flappy Bird sometime in the past. For those who don’t know, it was an extremely addictive Android game in which the aim was to keep flying the bird in air by avoiding obstacles.

In this application, a flappy bird Bot is created by using advanced reinforcement learning techniques. Here’s a demo of a trained bot.

 

Requirements:

  • Python (2 or 3)
  • Tensorflow (0.7+)
  • Pygame
  • Opencv-python

Implementing this is easy, as most of the nuts and bolts are included.

 

Step 1: Download the official repository.

 

Step 2: Make sure you have all the dependencies installed. Once you have, run the command as below.

python deep_q_network.py

 

3. Other notable Resources

We have just scratched the surface of what a deep learning model is capable of. There are many research papers being released every day which gives rise to many such applications. Now it’s a matter of who thinks the idea first!

I’ll list out some of the links and resources which I found worth looking at

 

End Notes

I hope you had fun reading this article. I bet these applications would have blown your mind. Some of you might be aware about these applications & some of you might not be. If you have worked on any of these applications, share your experience with us. The other reader and I would definitely want to know about it.

If you have come across these applications for the first time, then let me know which one excited you the most. Share your suggestions / feedback with us in the comments section below.

Learn, compete, hack and get hired!

16 Comments

Leave A Reply

Your email address will not be published.

Join 50,000+ Data Scientists in our Community

Receive awesome tips, guides, infographics and become expert at:




 P.S. We only publish awesome content. We will never share your information with anyone.