I found an interesting paper on Part-Of-Speech (POS) tagging with word embedding. Through my current work at Xing and my previous work on hidden Markov Models, I find this new model very interesting for several reasons. As mentioned in previous posts, word embeddings such as word2vec map all words in a dictionary into a d-dimensional, real valued vector space. In this new space, the similarity of two words decreases with distance of their respective word vectors. The idea is now to
see a document as a d- dimensional time series and use a hidden Markov model with Gaussian observations to model this real valued sequence. Now each state of the hidden Markov model
can be regarded as a POS category. Now this model can be trained using the Baum Welch algorithm and decoding can be performed using the Viterbi path. In my opinion this model is superior to classic hidden Markov models with multinomial observations and word embeddings alone in several ways.
First, the model's observation space has way fewer dimensions. While the multinomial observation for text can have thousands of parameters to estimate (one dimension / word), the word embeddings
only need several hundred dimensions and the semantic representation of each state can be captured more efficiently. Second, a recent article on kaggle suggested summing up all word vectors in a document as a representation. However, the average word vector might not be a sufficient representation, since a lot of the fine differences in a document are lost. In the hidden Markov model,
we still have to average vectors but the average is taken per state. In this way, the model introduces structure. In the POS paper, the temporal model with word embeddings outperformed the other multinomial approach by a large margin. It would be interesting to see such a model used in different NLP tasks.
Thursday, March 24, 2016
Sunday, February 28, 2016
Speed Bake-Off Tensorflow / (Numpy | SciPy | Matplotlib) / OpenCV
I recently got interested into scaling some of the algorithms from my PhD thesis. Especially the feature learning part. I used a K-Means to learn a convolutional codebook over audio spectrogram.
Why you can use K-Means to learn something like a convolutional neural net is described in: Coates, Lee and NG as well as my thesis. Anyways in my thesis experiments the bottle neck was the feature learning. So I need a fast clustering implementation as well as a fast convolution in order to resolve the speed issues. The three main implementations I look at are:
The convolution test is based on the three functions:
The results in seconds:
Why you can use K-Means to learn something like a convolutional neural net is described in: Coates, Lee and NG as well as my thesis. Anyways in my thesis experiments the bottle neck was the feature learning. So I need a fast clustering implementation as well as a fast convolution in order to resolve the speed issues. The three main implementations I look at are:
- Google Tensor Flow
- SciKit Learn
- OpenCV
All three provide a python interface but use a low level, speedy C or Fortran implementation under the hood. My goal is to evaluate these three libraries for their performance (speed) under the following conditions:
The library is fastest when testing on a single Macbook. It can use the available parallel devices such as a GPU and multi threading. Furthermore, the library should be fastest on medium sized problems.
I choose these conditions since I plan to design programs that animal communication researchers can use in the field. Meaning, if you are to analyse dolphin communication on a boat in the Bahamas or
you observe Birds in the rainforest, the only thing you might have is your laptop with no internet connection.Convolution
The convolution test is based on the three functions:
- Tensorflow: tensorflow.nn.conv2d
- SciPy: scipy.signal.convolve2d
- OpenCV: cv2.filter2d
My test is to compute the edge image using a sobel filter in x-direction and on in y-direction:
I am using the following image and expect the following edge image:
The results in seconds:
- Tensorflow: 0.125 [s]
- SKLearn: 0.049 [s]
- OpenCV: 0.019 [s]
Here it looks like the OpenCV implementation is the fastest. So openCV it is. For the clustering there are a lot of libraries and even the sklearn implementation is very fast.
Update:
After Himanshu's comment I chose to check Tensorflow not including the variable assignment
and then it took 0.021 seconds. However, the image copying into the variable and the session setup
matter in my use case, too. And it is still lower than Open CV. It is also interesting that for these problems, the speed between the libraries is not that different. However, I belief that for larger problems, the tensor flow version that can run on a cluster will show way better performance. Also I don't know right now if the current tensor flow version works with opencl.
After Himanshu's comment I chose to check Tensorflow not including the variable assignment
and then it took 0.021 seconds. However, the image copying into the variable and the session setup
matter in my use case, too. And it is still lower than Open CV. It is also interesting that for these problems, the speed between the libraries is not that different. However, I belief that for larger problems, the tensor flow version that can run on a cluster will show way better performance. Also I don't know right now if the current tensor flow version works with opencl.
Wednesday, February 17, 2016
Word Embeddings
Since my grad school interest was focused on machine learning for perception, I did not notice a class of methods called word embeddings. However, recently I got interested more into text mining so I started to read up on these method and implement some.
A word embedding maps words into a multi dimensional euclidean space in which semantically similar words are close. In other words, each word in your dictionary is represented by a multi dimensional vector.
A word embedding can capture many semantics. For example, on the word2vec webpage,
an embedding from google, it is noticed that:
In other words, the representation is capturing concepts such as gender and captial city.
The two most prominent methods so far seem to be word2vec (by google), glove (by stanford's nlp group). Furthermore, there is a very recent combination of the two called swivel (again by google).
All the methods are based on the idea that the usage of a word gives insight into the words meaning or that similar words are used in a similar context. Here context can be defined as a small neighbourhood. For example, a context definition could be defined as the words to the left of the target word and the three words to the right.
Google's Word2Vec obtains the vectors by using a simple neural net that predicts the target word from it's context (Continuous Bag Of Words) or vice versa (Skip Gram). As usual the neural net can be trained using stochastic gradient descent (back propagation). The neural net can be seen as learning a representation for words (word vectors) and a representation for contexts (context vectors).
Glove sloves a similar problem. However, instead of predicting the actual context around a word, glove learns vectors predictive of the a global coocurance matrix, extracted from the complete corups. Glove is trained using adagrad. In general we solve an optimisation problem of the form:
A word embedding maps words into a multi dimensional euclidean space in which semantically similar words are close. In other words, each word in your dictionary is represented by a multi dimensional vector.
A word embedding can capture many semantics. For example, on the word2vec webpage,
an embedding from google, it is noticed that:
- "vector('king') - vector('man') + vector('woman') is close to vector('queen')"
- "vector('Paris') - vector('France') + vector('Italy') [...] is very close to vector('Rome')"
In other words, the representation is capturing concepts such as gender and captial city.
The two most prominent methods so far seem to be word2vec (by google), glove (by stanford's nlp group). Furthermore, there is a very recent combination of the two called swivel (again by google).
All the methods are based on the idea that the usage of a word gives insight into the words meaning or that similar words are used in a similar context. Here context can be defined as a small neighbourhood. For example, a context definition could be defined as the words to the left of the target word and the three words to the right.
Google's Word2Vec obtains the vectors by using a simple neural net that predicts the target word from it's context (Continuous Bag Of Words) or vice versa (Skip Gram). As usual the neural net can be trained using stochastic gradient descent (back propagation). The neural net can be seen as learning a representation for words (word vectors) and a representation for contexts (context vectors).
Glove sloves a similar problem. However, instead of predicting the actual context around a word, glove learns vectors predictive of the a global coocurance matrix, extracted from the complete corups. Glove is trained using adagrad. In general we solve an optimisation problem of the form:
Basically the two methods differ in the way f(.) and C are defined. C is the target function and we aim to minimise the difference between the prediction and the target, scaled by a function of the co-occurrence count f(.). For word2vec the target function is the pointwise mutual information between two words and for glove it is the log co-occurrence count.
Both method come with several implementations already. Semantic similarity can be used for several
NLP tasks. For example, sentiment analysis or query expansion.
Labels:
machine learning,
neural network
Location:
Barcelona, Barcelona, Spain
Wednesday, September 23, 2015
Thesis Published: DATA MINING IN LARGE AUDIO COLLECTIONS OF DOLPHIN SIGNALS
The study of dolphin cognition involves intensive research of animal vocalisations recorded in the field. In this dissertation I address the automated analysis of audible dolphin communication. I propose a system called the signal imager that automatically discovers patterns in dolphin signals. These patterns are invariant to frequency shifts and time warping transformations. The discovery algorithm is based on feature learning and unsupervised time series segmentation using hidden Markov models. Researchers can inspect the patterns visually and interactively run comparative statistics between the distribution of dolphin signals in different behavioral contexts. The required statistics for the comparison describe dolphin communication as a combination of the following models: a bag-of-words model, an n-gram model and an algorithm to learn a set of regular expressions. Furthermore, the system can use the patterns to automatically tag dolphin signals with behavior annotations. My results indicate that the signal imager provides meaningful patterns to the marine biologist and that the comparative statistics are aligned with the biologists’ domain knowledge. |
[PDF]
Labels:
machine learning,
research
Location:
Hamburg, Germany
Sunday, August 30, 2015
Random Intersection Trees
Found an interesting paper with a new idea on how to build interpretable decision rules. The paper
describes an algorithm to find a set of binary features that are together indicative of a class. For example, a set of binary features might be:
describes an algorithm to find a set of binary features that are together indicative of a class. For example, a set of binary features might be:
- Humidity = high: true / false
- Temperature > 10 C: true / false
- Sunny = true / false
- Rain = true false
A feature is said to be active whenever the result evaluates to true. For two classes C1 and C2, the goal is to find a subset of active features S such that P(S|C1) > O2 and P(S|C2) < O1 for two thresholds 0 < O1 < O2 < 1.
For example, let the class be good weather and bad weather. Furthermore, I specified the thresholds
as O1 = 0.5 and O2 = 0.25. A good result might then be
- P(S = {temperature > 10, sunny} | good weather) > .5
- P(S = {temperature > 10, sunny} | bad weather) < .25
Such a result would be indeed interpretable and we could agree with the results that a higher temperature and sun would result in higher probabilities for good weather.
The algorithm works in two steps:
- Candidate generation for subsets S.
- Check subsets for constraint: P(S|C1) > O2 and P(S|C2) < O1
The main algorithm in the paper is an efficient candidate generation algorithm.
The main idea is to organise the subset search into a random tree of fixed depth and breadth.
At every node in the tree we pick a random example from the dataset with a positive label and then
compute the intersection of that example with the active feature set of the parent node.
By intersecting with positive examples only, the set of features gets more and more refined at each level. All remaining sets at the specified depth are candidates. Afterwards, we only have to check gif the subset holds to the constraints.
A very interesting method to find rules in a dataset which is an interesting alternative to decision tree learning and apriori rule discovery.
Labels:
discovery,
machine learning
Location:
Osterholz-Scharmbeck, Germany
Monday, July 13, 2015
Social Network Sampling
I will start working for a social network in August. My new job is data scientist at the business network Xing. I decided to play with their open API a little. The Xing API gives access to users in the network as well as their contact list. So an external app can analyze the social graph. Well actually there are restrictions on the number of queries so it is possible toanalyze the graph partly. My goal is to extract an unbiased sample from the complete graph by performing a random walk from a start node. That means at every node the algorithm expands all
the node's successors and then picks a random one. The chosen successor is the next node. With
a probability of 0.15 the algorithm returns to the start node. This will ensure that we explore the graph around the start node. The going back is ensuring a trade off between breadth of the exploration and the depth of the exploration. I use the ruby version of the API.
A code snippet for a random walk step in the Xing API
is shown below:
##
# Random walk step:
# 1) With probability 0.15 go back to start
# 2) Randomly choose a node from the successors
def random_walk_step(user_id, start)
reset = false
if Random.rand < 0.15
user_id = start
reset = true
end
num_contacts = 5 # control branching
contacts = XingApi::Contact.list(user_id, limit: num_contacts)[:contacts][:users]
next_user = Random.rand(num_contacts)
contacts.map! {|x| x[:id]}
if reset
return random_walk_step(contacts[next_user], start)
end
return [contacts[next_user], contacts, user_id]
end
The random step function takes a user id as the current node and a node we
started the random walk at. First we decide if we restart the search at the start
node, then it samples a neighbor. Repeating the process and updating the user
id with the sampled neighbor results in a graph. The function below,
explores the graph for 25 nodes and returns the graph as a dot file:
##
# Print graph as graphviz file
def dot(path)
expended = []
File.open(path, 'w') do |file|
file.write "digraph my_neighbors {\n"
start_id = XingApi::User.me[:users].first[:id]
ids = random_walk_step(start_id, start_id)
45.times do
id = ids[2]
username = XingApi::User.find(id)[:users].first[:display_name]
username.gsub! /\W/, ""
if not expended.include? username
expended = expended + [username]
ids[1].each do |neighbor|
neighborname = XingApi::User.find(neighbor)[:users].first[:display_name]
neighborname.gsub! /\W/, ""
file.write "#{username} -> #{neighborname};\n"
end
end
ids = random_walk_step(ids[0], start_id)
end
file.write "}"
end
end
A dot file is a graph description that can be converted into graph images.
A sample graph of my network is shown below.
Wednesday, May 13, 2015
Integrating Weka's UI into your own code
Weka is a machine learning toolkit written in Java. Despite it's capability to run as a stand alone
user interface, you can also use Weka in your own Java code. That means, all algorithms you can find in the user interface are also trainable and usable in your Java application. The cool thing is, you can also integrate part of Weka's user interface into your own. So my goal was to integrate the option to choose a Weka classifier and configure it using Weka's native components.
![]() |
| Choosing and configuring a Weka classifier, here a Support Vector Machine. |
After browsing a little through the Weka UI code I found two classes that can be used to
open the editor to choose a classifier and to configure it. Once the window closes, the classifier
with it's configuration is ready to be used by other functions. The first UI component is the GenericObjectEditor, which is responsible for choosing a classifier. The second is the PropertyDialog which is configuring the current classifier. Blow I showed some code that displays the dialog and prints out the classifier. I found the example in the Weka GenericObjectEditor class at the bottom. For the code to work you have to make sure the weka.jar is in your CLASSPATH.
package wekaui;
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.beans.PropertyEditor;
import weka.classifiers.Classifier;
import weka.classifiers.rules.ZeroR;
import weka.gui.GenericObjectEditor;
import weka.gui.PropertyDialog;
/**
* Choose a classifier and configure it in your own java code.
*
* @author Daniel Kohlsdorf
*/
public class WekaUI {
public static void main(String[] args) {
Object initial = new ZeroR();
GenericObjectEditor.registerEditors();
GenericObjectEditor editor = new GenericObjectEditor(true);
ce.setClassType(weka.classifiers.Classifier.class);
ce.setValue(initial);
// Setup the property view
PropertyDialog propertyDialog = new PropertyDialog((Frame) null, editor, 100, 100);
// Get the classifier when the window is closed
pd.addWindowListener(new WindowAdapter() {
@Override
public void windowDeactivated(WindowEvent e) {
PropertyEditor propertyEditor = ((PropertyDialog) e.getSource()).getEditor();
if (propertyEditor.getValue() != null) {
Classifier classifier = (Classifier) propertyEditor.getValue();
System.out.println("CLASSIFIER: " + classifier);
}
}
});
propertyDialog.setVisible(true);
}
}
Labels:
coding,
java,
machine learning,
research
Location:
Atlanta, GA, USA
Subscribe to:
Posts (Atom)







