Life is a game, take it seriously

Archive for the ‘Serious Stuffs’ Category

Training a Rap Machine

In AI, brain, deep learning, Machine Learning, Serious Stuffs on January 9, 2020 at 7:15 pm

by Li Yang Ku (Gooly)

(link to the rap machine if you prefer to try it out first)

In my previous post, I gave a short tutorial on how to use the Google AI platform for small garage projects. In this post, I am going to follow up and talk about how I built (or more like an attempt to build) my holiday project, a machine that completes your rap lyrics using the “Transformer” neural network.

Transformer is a neural network model introduced by Google Brain for mostly language related tasks. What is interesting about this architecture is that instead of taking one word at a time, it takes in the whole input sentence at once and learns the relationship between each word. This allows transformers to learn useful relationships such as what a pronoun refers to in a sentence. In the original paper “Attention is All You Need”, this ability to understand relations between words are referred to as attention since it has the ability to focus more on certain pairs of words. I will not go into the details of Transformer since quite a few people already explained it in great length in their blogs (such as this blog and this blog.) My rationale was that Transformer’s ability to learn relationships between words in rap sentences should allow the network to learn what words rhyme well together or have the right flow.

I collected rap lyrics from 14 artists with a total of around 180000 lines of rap. These rap lyrics are further filtered to around 50000 lines of lyrics that I considered to “rhyme” with another line. The first line is the input and the second line is the output. Pairs of these sentences are then split into training and evaluation (90:10 split.) The Transformer architecture I used is mostly based on this Google Cloud Platform tutorial on generating poetry. After a little bit of hyper tuning, I ended up with a Transformer architecture of 2 hidden layers, 4 heads (number of attentions), and 512 hidden layer size. This model is then trained for 75000 iterations. The total cost of experimenting with different models and trial and error cost me a bit more then a hundred bucks (note that you are given $300 to start).

The final result was, well, entertaining but with limited success. Occasionally it will rhyme if your sentence ends with a common word but most of the time its just a weirdo spitting out random sentences with a semi-rapper attitude. The following are a few example results:

Input: This thing I made raps like a machine

Output: It’s all fair in love with me

Input: It generates raps that run deep

Output: That’s what I mean

Input: No rap is free, this thing cost me a fee

Output: I got a whole lotta guap on me

Input: Consider this as a new year gift that raps

Output: Chillin’ on some wildin’ out of that

Input: You might say my input rap is bad

Output: I was gone but now I m back

Input: If you don’t like your output rap

Output: Where the fuck am I going back

You can try out the rap machine here yourself. Thank you all for reading this blog and wish you all an entertaining 2020!

Tool Tutorial: Google AI Platform for Hobbyist

In AI, App, deep learning, Machine Learning, Serious Stuffs on October 27, 2019 at 10:44 pm

by Li Yang Ku (Gooly)

In this post I am going to talk about the Google AI platform (previously called Google ML engine) and how to use it if deep learning is just your after work hobby. I will provide links to other tutorials and details at the end so that you can try it out, but the purpose of this post is to give you a big picture of how it works without having to read through all the marketing phrases targeting company decision makers.

Google AI platform is part of the Google cloud and provides computing power for training and deploying deep networks. So what’s the difference between this platform and any other cloud computing services such as AWS (Amazon Web Services)? Google AI platform is specialized for deep learning and is suppose to simplify the process. If you are using TensorFlow (also developed by Google) with a pretty standard neural network architecture, it should be a breeze to train and deploy your model for online applications. There is no need to set up servers, all you need is a few lines of gcloud commands and your model will be trained and deployed in the cloud. (You also get a $300 dollar first year credit for signing up on Google Cloud Platform, which is quite a lot for home projects.) Note that Google AI platform is not the only shop in town, take a look at Microsoft’s Azure AI if you like to shop around.

So how does it work? First of all, there are four ways to communicate with Google AI platform. You can do it 1) locally: where you have all the code on your computer and communications are made through commands directly, 2) on Google Colab: Colab is another Google project that is basically a Jupyter notebook on the cloud which you can share with others, 3) on the AI platform notebook: which is similar to Colab but have more direct access to the platform and more powerful machines, and 4) on any other cloud server or jupyter notebook like webservice such as FloydHub. The main difference between using Colab versus AI platform notebook is pricing. Colab is free (even with GPU access), but has limitations such as up to 12 hours of run time and shuts down after 90 minutes of idle time. It provides you with about 12GB RAM and 50GB disk space (although the disk is half full when started due to preinstalled packages). After disconnected, you can still reconnect with whatever you wrote in the notebook, but you will lost whatever is in the RAM and disk. For a home project, Colab is probably sufficient, the disk space is not a limitation since we can store training data in google storage. (Note that it is also possible to connect Google drive in Colab so that you don’t need to start from scratch every time.) On the other hand, AI platform notebook could be pricey if you want to keep it running (0.137 / hour and 99.89 / month for a non-gpu machine).

Before we move on, we also have to understand the differences between computation and storage on the Google AI platform. Unlike personal computers where disk space and computation are tightly integrated, they are separated on the cloud. There are machines that are responsible for computation and machines that are responsible for storage. Here, Google AI platform is responsible for the computation while the Google Cloud Storage takes care of the stored data and code. Therefore, before we start using the platform we will need to first create a storage space called bucket. This can be easily done through a one line command once you created a Google Cloud account.

If you are using Colab, you will also need to have the code for training your neural network downloaded to your Colab virtual machine. One common work flow would be to use software version control services such as Github for your code and just clone the files to Colab every time you start. It makes more sense to use Colab if you are collaborating with others or want to share how you train your model, otherwise doing everything locally might be simpler.

So the whole training process looks like this:

  1. Create a Google Cloud Project.
  2. Create a bucket where the Google AI platform can perform computations on.
  3. With a single command, upload your code to the bucket and request the AI platform to perform training.
  4. Can also perform hyper parameter tuning if needed.
  5. If you want the trained model locally, you can simply download it from the bucket through a user interface or command.

A trained model is not very useful if not used. Google AI platform provides an easy way to deploy your model as a service in the cloud. Before continuing, we should clarify some Google terminology. At Google AI platform, a “model” means an interface that solves certain tasks and a trained model is named  a “version” of this “model” (reference). In the following, quotation marks will be put around Google specific terminologies to avoid confusion.

The deployment and prediction process is then the following:

  1. Create a “model” at AI platform.
  2. Create a “version” of the “model” by providing the trained model stored in the bucket.
  3. Make predictions through one of the following approaches:
    • gcloud commands
    • Python interface
    • Java interface
    • REST API
      (the first three methods are just easier ways to generate a REST request)

And that’s all you need to grant your home made web application access to scalable deep learning prediction capability. You can run this whole process I described above through this official tutorial in Colab and more descriptions of this tutorial can be found here. I will be posting follow up posts on building specific applications on Google AI platform, so stay tuned if you are interested.

References:

Looking Into Neuron Activities: Light Controlled Mice and Crystal Skulls

In brain, Neural Science, Paper Talk, Serious Stuffs on April 2, 2017 at 9:50 pm

by Li Yang Ku (Gooly)

It might feel like there aren’t that much progress in brain theories recently, we still know very little about how signals are processed in our brain. However, scientists have moved away from sticking electrical probes into cat brains and became quite creative on monitoring brain activities.

Optogenetics techniques, which was first tested in early 2000, allow researchers to activate a neuron in a live brain by light. By controlling the light that activates motor neurons in a mouse, scientists can control its movement remotely, therefore creating a “remote controlled mouse” which you might heard of in some not that popular sci-fi novels. This is achieved by taking the DNA segment of an algae that produces light sensitive proteins and insert it into a specific brain neuron of the mouse using viral vectors. When light is shed on this protein, it opens its ion channel and activates the neuron. The result is pretty cool, but not as precise as your remote control car, yet. (see video below)

Besides the Optogenetics techniques that are used to understand the function of a neuron by actively triggering it, methods for monitoring neuron activities directly have also become quite exciting, such as using genetically modified mice with brain neurons that glow when activated. These approaches that use fluorescent markers to monitor the level of calcium in the cell can be traced back to the green fluorescent proteins introduced by Chalfie etc in 1994. With fluorescent indicators that binds with calcium, researcher can actually see brain activities the first time. A lot of progress have been made on improving these markers since; in 2007 a group in Harvard introduced the “Brainbow” that can generate up to 90 different fluorescent colors. This allowed scientists to identify neuron connection a lot easier and also helped them won a few photo contests.

To better observe these fluorescent protein sensors (calcium imaging), a recent publication in 2016 further introduced the “crystal skull”, an approach that replaces the top skull of a genetically modified mouse with a curved glass. This quite fancy approach allows researchers to monitor half a million brain neuron activities of a live mouse through mounting a fluorescence macroscope on top of the crystal skull.

References:

Chalfie, Martin. “Green fluorescent protein as a marker for gene expression.” Trends in Genetics 10.5 (1994): 151.

Madisen, Linda, et al. “Transgenic mice for intersectional targeting of neural sensors and effectors with high specificity and performance.” Neuron 85.5 (2015): 942-958.

Josh Huang, Z., and Hongkui Zeng. “Genetic approaches to neural circuits in the mouse.” Annual review of neuroscience 36 (2013): 183-215.

Kim, Tony Hyun, et al. “Long-Term Optical Access to an Estimated One Million Neurons in the Live Mouse Cortex.” Cell Reports 17.12 (2016): 3385-3394.

 

Organizing Publications Visually: EatPaper

In Paper Talk, Serious Stuffs on January 13, 2013 at 2:44 pm

by Gooly (Li Yang Ku)

eatpaper.org

I always hoped that there would be a good app to organize the papers I read and show it graphically. I did Google for it but couldn’t find one that fits my need, so I started to build one about a year ago (EatPaper.org). I stopped working on it several times for various reasons but now it’s finally functional (not perfect, but enough for now). The website functions a little bit like Pinterest, we both use bookmarklet, a website book mark that executes javascript, to fetch your current webpage. So the following are the typical steps to use EatPaper.

1. Search on Google scholar.

2. Click the bookmark button I made. (You can get the button by clicking “Add a Node” in EatPaper.org)

3. A dialog pops up and you can store the publication information you found as a node in your graph.

I also made a Chrome extension that has the exact same function.

eatpaper.org

The website is built using Google App Engine + Google Web Toolkit. If it turns out to be a little bit slow occasionally, please be patient; I have to admit that I don’t have any funding and only pay the minimum amount needed to host the server. Please share it to your friends if you like it. I probably can get more resources if more people use it.

You can leave a message here if you have any opinions, problems or found a bug.

Why I didn’t blog for 6 month – Facebook App for Blog Promotion

In facebook, Serious Stuffs on November 28, 2011 at 12:01 am

written by Gooly

CheerRabbit

6 month ago I was very enthusiastic about blogging, I felt it was extremely wonderful to share all the stuffs I knew. I made up a long list of stuffs I planned to talk about in computer vision and also prepared to share my Matlab code that recognizes different objects in different angles. Since computer vision wasn’t a popular field, I got roughly 5 visitors a day and a few comments over all. I believe the number will grow and I was very satisfied with it.

CheerRabbit Promote Your Blog

One morning while I was driving along PCH to work and thinking about what other cool stuffs I could talk about,  I suddenly came up with a question “How should I let other people in computer vision find my blog?” It was almost impossible to find it through Google, and I never searched a blog in WordPress.com (so I don’t think others will). This question also bugged me when I thought of making an Android app that adjusts photo images taken in the dark; if I can’t advertise it, nobody will use it even if it’s free and good. Currently the best way to advertise is probably Google AdSense, something I never clicked on. There should be a better way for individuals to advertise in a simple way for free.

CheerRabbit Facebook Promotion I finally came up with a simple answer: Facebook. If I ask a friend to help me post my blog link on her Facebook, all of her friends can see it. And if I’m lucky, one of them might become my blogs loyal reader and share it on Facebook again. In return, I’ll also help my friend share her blog link on my Facebook.

If this is effective, we can extend beyond our friends to anyone who has a blog or even anyone who want’s to share something and exchange Facebook posts. I thought that was a good idea and started building an app that does this, and this is what I worked on in my spare time for the past 6 month.

Website: http://cheerrabbit.com

CheerRabbit is currently finished and public, but still needs to be adjusted to fit the market.

A Need to Change in Survival Strategy: the merge of world wide web and real world

In Serious Stuffs on April 15, 2011 at 9:57 am

written by Gooly

Since the big bang of the world-wide web, our world split into the real world and the virtual world. We all live in the real world physically, but could be spiritually in the virtual world “completely”. In the good old 2000s, there used to be a simple way to circle people from different professions into groups on the socially active axis, like the one below. However, recent year’s rapid change in social network makes this no longer true.

If you do regression on the graph above you would very likely get a negative slope; since with limited time and passion one could hardly be extremely active in both axis.

Back in the good old 2000s, you’ll probably do pretty good just by working hard in one world, this is due to the following success equation at that time.

As you can see, what you do in one world doesn’t affect your achievement in the other world. For example, even if you defeated the evil lord after a 10 hour war and step on others to obtain the glory to become the leader of your whole tribe in the virtual world, you still need to take the midterm tomorrow, and your professor won’t even praise on your epic accomplishment. This is why parents used to be the biggest enemy of online games. They simply believe that the parameter B in the equation is significantly small compared to A. Since parents definitely heard of the famous quote ” Everything is Optimization” by Stephen P. Boyd, they would know the best way to gain the most is to put all the efforts in the real world. I have to say they are probably right under this equation, but we’ll see that this is no longer true.

After the rapid change in the virtual world due to the thrive of one various social networks, the real world and the virtual world is merging. It’s harder to hide after nick names on the web, sites remember who you actually are. What happens on the virtual world directly affects your real world; saying something wrong on the web will very likely hit you hard in the real world. The old equation no longer reflects reality. This gives us the following more adequate success equation for the current world.

Now we have 3 parameters instead of 2 ( A B and C are usually positive, most people  have C > 1), which makes life even more complicated. To optimize success, we have to first estimate A B C and put the exact amount of effort on both world. However A B and C differs between people and changes with time, therefore we have to do a series of experiments and probably adjust the weights along the time.

But this is not the main point, what is significant is that the equation changed from addition to multiplication. What you do on the web will largely affect your total result. You can no longer be extremely success by just working hard in the real world; internet do matters. Politicians, doctors, lawyers all have to jump into the virtual world to get the most; if they don’t, their colleagues would.

This might also mean that in the near future, your professor probably would appreciate you for stopping an evil empire expanding to his tribe.

Life is a game, take it seriously

In Serious Stuffs on April 13, 2011 at 4:02 am

This page is here so I can modify it some time later pretending I said it the first day.