Category: Cognitive Science

Fun With Text – Hacking Text Analytics

hacking_text_analytics

I’ve always wondered if there was a way to teach people to cobble together quick and dirty solutions to problems involving natural language, from duct tape, as it were.

Having worked in the field now for a donkey’s years as of 2015, and having taught a number of text analytics courses along the way, I’ve seen students of text analysis stumble mostly on one of two hurdles:

1.  Inability to Reduce Text Analytics Problems to Machine Learning Problems

I’ve seen students, after hours of training, still revert to rule-based thinking when asked to solve new problems involving text.

You can spend hours teaching people about classification and feature sets, but when you ask them to apply their learning to a new task, say segmenting a resume, you’ll hear them very quickly falling back to thinking in terms of programming steps.

Umm, you could write a script to look for a horizontal line, followed by capitalized text in bold, big font, with the words “Education” or “Experience” in it !!!

2.  Inability to Solve the Machine Learning (ML) Problems

Another task that I have seen teams getting hung up on has been solving ML problems and comparing different solutions.

My manager wants me to identify the ‘introduction’ sections.  So, I labelled 5 sentences as introductions.  Then, I trained a maximum entropy classifier with them.  Why isn’t it working?

One Machine Learning Algorithm to Rule Them All

One day, when I was about to give a lecture at Barcamp Bangalore, I had an idea.

Wouldn’t it be fun to try to use just one machine learning algorithm, show people how to code up that algorithm themselves, and then show them how a really large number of text analytics problem (almost every single problem related to the semantic web) could be solved using it.

So, I quickly wrote up a set of problems in order of increasing complexity, and went about trying to reduce them all to one ML problem, and surprised myself!  It could be done!

Just about every text analytics problem related to the semantic web (which is, by far, the most important commercial category) could be reduced to a classification problem.

Moreover, you could tackle just about any problem using just two steps:

a) Modeling the problem as a machine learning problem

Spot the appropriate machine learning problem underlying the text analytics problem, and if it is a classification problem, the relevant categories, and you’ve reduced the text analytics problem to a machine learning problem.

b) Solving the problem using feature engineering

To solve the machine learning problem, you need to coming up with a set of features that allows the machine learning algorithm to separate the desired categories.

That’s it!

Check it out for yourself!

Here’s a set of slides.

It’s called “Fun with Text – Hacking Text Analytics”.

Mental Models and Art Aesthetics

The Mind of a Dance
An Exploration of the Mental Model that a Spectator might Form when Watching a Dance.

This is a post about a painting that I completed only last week.  But it was a painting that I’d been trying to figure out how to paint for all of 7 years.  It all started with a motorbike ride.

One day in 2006, I was riding down a mountainous road in North Carolina,
when I saw a hill of striking beauty (I believe it was somewhere near a town called
Marion).

It was evening and the colours were beginning to fade, but I could clearly
make out on one side of the hill striking trees that were reddish-orange in hue and I
found them beautiful against the light green that surrounded them and the blue skies
above.

I continued to ride down the road.  I rounded the hill and came to the other
side. I saw again, waves of green and yellow and touches of red and I was overcome
with a sense of being in the presence of the highest beauty that the eye could
behold.

So, I stopped and removed the camera from the knapsack behind me. From
various points along the road, I tried to photograph the hill.

However, I could not frame a shot that could evoke the beauty of
the hill that stood before my eyes.

That evening, I was troubled by a sense of failure, of bafflement at having failed to record the soul of the scenery that I had left behind. The hills around Marion were all extremely beautiful, but nothing else on the road had the perfection of the hill that I had not been able to photograph.

So, that evening, I sat and pondered a very interesting question that had to do with
aesthetics. The question was this: Does the mind experience beauty according to
images that it has seen, or does the mind experience beauty by a mental model it
has built of an object and the associations it has made between that model and
models of other objects?

Let me clarify what I mean by a mental model with an example. When we approach a
person whom we have never met before, we don’t immediately see all of that person.
We perhaps at first only see the front of the person, at a distance. Later we see more
of the person, their face, their profile, and how they look from behind. As we see
more and more of a person, we fill in more and more of the missing information about
how the person looks.

However, from the very beginning, we know that we are
looking at a person, even though we haven’t seen the person’s teeth or sides or
back. So we must have decided that the frontal image that we saw fit best into a
mental model of a person.  The mental representation may not just be a 3
dimensional representation. It may be a set of associations and memories over time, all woven together in complex ways.

So, the question that came to my mind was:  Is a human mind’s evaluation of
the aesthetics of an object based on a) any of the individual images of the object
that we have seen or on b) the entire mental model that we have constructed in our
minds of the object.

The more I thought about it, the more I began to feel that my experience with the hill
would be best explained by the conclusion that our aesthetic experience of an
object is determined by the mental model we have formed of it, and not by any image
of it, and here were the reasons for my leaning towards the latter conjecture:

a) If it is just a single view or image of an object that drives us to experience it as
beautiful or attractive, then our feelings about its attractiveness should change all
the time, based on small things like the angle at which we are viewing it. That does
not seem to be how we experience things in real life.

b) The experience of the hill led me to think that the latter explanation was the more
likely because if it was one of the views of the hill that made me think it beautiful, I
should have been able to capture the view with my camera. Since I couldn’t,
perhaps it was something I saw on the other side of the hill, combined with the
fading light and the landscape along the way (perhaps combined with the beauty of
some of the trees I saw upon the hill) that came together to contribute to the sense
of beauty that I experienced when looking at the hill.

That evening, I thought of a new kind of painting technique that would be possible if
the above conjecture proved true. It seemed that it might be worthwhile to paint a
picture from the point of view of the mental model a viewer might form if they saw the actual subject of the painting in context, possibly from different angles, or at different distances, and over an extended period of time.

But it was only last week, a good 7 years after I passed through Marion, NC, that I
tried to create a painting of the sort. Since I have recently watched many Indian
classical dance performances and some contemporary dance performances, I
attempted to paint all the things that might be associated with a dance performance
in the mind of a spectator. I constructed the painting like a fractal, starting with a
dancer and then representing the dancer at different levels of granularity and detail.

One of the things on the mind of the spectator would be the dancer’s body
(the whole form, from head to toe). Emoting is a key aspect of dancing in Indian classical dance.  So, in order to appreciate the emotion, a spectator would have to pay close attention to (and so form a model of) the dancer’s face, and of his or her eyes. So, I wove an
image of a forehead, and of an eye, into the painting. Another part of the body that
Indian classical dancers use a lot is the hands and the fingers. They use them to
denote various objects, characters and actions. I associated the movements of the
arms and fingers with flowing water, and plants with branches. So, I painted in some
flowing washes and let some negative white spaces take the form of trees in the
painting. Indian dance costumes are colourful, so I made everything in the painting
as bright as a classical dance costume.

The process of painting was a lot of fun. It was very different from the process of
scientific experimentation of course. There was none of the same rigour and I
wasn’t really looking to prove anything.

I liked the painting that came about and I have inserted a photograph of the same into this blog entry (it’s at the top).

But we don’t know yet whether mental models lie at the root of aesthetic
experiences. And you know what? As an AI researcher, I am just dying to find out! It
seems possible to design an experiment to determine the validity of the conjecture.

We could take an object whose facade is beautiful but whose side view is not. The
subjects of the experiment would be shown the front and side views of the building
and asked to rate the appearance of the front of the building. The control group
would be shown just the front of the building and asked to rate its appearance.

A significant difference in ratings (poorer ratings by subjects shown the front and
side view) would support the conjecture that a mental model lay at the root of the
aesthetic experience.

I hope that one fine day, we might be able to conduct the experiment, and if we do, I
shall share the results here with you!

As a footnote, I’d like to share this blog post http://aimeeknight.com/2012/04/10/the-new-aestheticperhaps/ by a blogger from (it appears to be – hmm, what a coincidence) North Carolina.  The article is about art that attempts to portray the world from the point of view of a machine – using a machine’s aesthetic – the phrase they’ve used is ‘New Aesthetic’.  I had not heard of the concept before, and it isn’t the same thing that I am working on, but since we’re discussing aesthetics and perception, it appeared relevant and interesting.

As a second footnote, I’d like to put in a word of explanation about why a firm of computer scientists and AI researchers should be interesting in painting.  Well, to many early AI researchers, AI was as much a quest to understand the human mind as it was a quest to solve difficult problems.  There were many attempts to comprehend the human mind by constructing logical and mathematical models of various cognitive processes (things the mind did) and seeing if the models could mimic the real thing.  So, AI research had a lot of common ground with Psychology.  And there is still a cross-disciplinary research area known as Cognitive Science that blends Psychology and AI research.  So, I just want to defend myself by saying that talking about aesthetics is not off-topic for this blog.

Frameworks for evaluating values

I recently came across a very interesting 2001 paper by Daphne Koller that dealt with influence diagrams and how they could be applied to game theory.  I came across the paper while doing some background reading on a talk on decision making in accordance with our core values by a friend of mine, Somik Raha.

Influence diagrams are a formalism (very similar to probabilistic graphical models) that are used for making decisions.

What Somik Raha has attempted to do is come up with a framework for making decisions while also taking one’s values into account (either as constraints or as inputs into the decision model).  To do that he proposes extensions to influence diagrams.

What I found interesting when I thought about Daphne Koller’s work and Somik’s together, is that they could possibly give you a framework to evaluate your values.

Koller’s formalism reduces to a game theoretic model, which can be evaluated to determine the outcome of the decisions made by a group of people.

Plug in a formalism based on Somik’s ideas and you just might be able to create a way to quantity the benefits of values.

The Importance of Values?

I have been thinking a bit about values these days because there has been a horrific gang rape in Delhi, and there have recently been numerous incidents of bad driving where friends of mine have been injured in Bangalore.  Then there is corruption.  Our society seems to be quite happy with inequality and vast differences in the distribution of wealth.  It make me wonder if our values are to blame.

I have often wondered whether some of our problems originate in our value systems and whether the value systems that we consider sacrosanct in India are really very good ones.

Let me take just a couple of values that most Indians would consider to be very good values

  1. Non-violence
  2. Obedience

and let’s discuss them in more detail.

  1.  Non-violence

This value appeals not just to people in India.  You see variants of the value of non-violence appear in Tolstoy’s writings and in Semitic religions, as you can see from the Bible (“turn the other cheek”) and the Quran (“give alms to one who begs from you, even if he comes on the back of a horse”).

The issue with this sort of value is that it makes a person (and those around him/her) extremely vulnerable to injustice.

In India, we restrict the liberty of women – in their choice of clothing, company and lifestyle – for fear that they could be in danger if they violated societal norms.  This shows that none of us want to fight society or cross swords with someone who might make disparaging comments about personal choices.

Moreover, possibly as a result of the value of non-violence, very few Indians if any are taught fighting skills in school.  So, even if a person really wanted to act, say to protect a friend, he or she might not really have the skills to take down an aggressor.

So, instead of protecting and standing up for people who might be vulnerable, we become their tormentors and make their lives more miserable, just so we don’t have to get our hands dirty, or because we don’t have the skills and strength to do squat.

I’ve written about how bribes are openly collected by traffic policemen.  It should be very easy to put a stop to such behavior if you’re willing to fight.

If non-violence is not a core value, then how do we protect people from tearing each other to bits?

We could start with a question like:  non-violence for what purpose?  (turning it into an extrinsic value)

If the answer is something like, “so that the weak feel protected”, why not make protecting the weak our core value?

I’d prefer teaching kids values like “Don’t ever turn your back on a bully” rather than values like “Don’t fight anybody, and just come home safe, child!”

2.  Obedience

Indian parents love to boast that their child is “such an obedient child!”

Is that a good thing?

Obedience is different from politeness or respect.  The latter are mutual but the former is one way.

So, the politics of obedience creates a hierarchy of subservience.

In India, Parents expect complete obedience from Children.

The Police expect complete obedience from People.

The Politicians expect complete obedience from Police.

Teachers expect complete obedience from Students.

Managers expect complete obedience from Employees.

The creation of the hierarchy (through expectations of obedience) can be very dangerous in many ways.

1.  It can stifle creativity and problem-solving ability.  There is a bias against ideas flowing up a hierarchy because those higher up the hierarchy claim their place above those required to be obedient to them on the premise that they are somehow superior to those below them.  A good example is how parliament will not accept that people have a right to demand a bill against corruption (members of the Indian parliament claim that parliament is supreme in a parliamentary democracy – not the citizens that the parliamentarians represent).

2.  It can leave young people ill-equipped to defend their personal spaces.  I read in a paper on rape that many rapists approach victims by testing their boundaries.  They make comments and otherwise violate the intended victim’s personal boundaries.  If these are not strongly resisted, the probability of an assault becomes greater.  Another strategy used by rapists is to move their intended victim to a new location where they are more vulnerable. It is very important for people to be conditioned so that they do not obey an order by an attacker to relocate under any circumstances.

3.  The hierarchies perpetuate the power of stronger (bigger, older or richer) parties by providing social sanction to their dominant position, and so hinder social mobility.

4.  The obedience hierarchy could allow a few people at the top to amass too much power. It might have, for example, prevented cops from disobeying those in power during the Gujarat riots.

5.  Obedience means valuing rules above truth.  Obedience implies not challenging the rules or the status quo.  So there is little scope for discovering if the rules really are good ones for everybody.  People often defend something they assert with a “because I said so.” – that is, you are expected to believe them because of their authority, and not because they can substantiate their assertion.

Obedience as an absolute value is not entirely harmless.  It could be dangerous to us as a society because corrupt politicians can use the pliability and obedience of people around them to get away with evil (remember the activist who was hacked to death on the orders of a corporator from Bangalore, the journalist who was burnt to death in Uttar Pradesh, or the shutdown that the former Chief Minister of Karnataka State ordered when he was about to be investigated for corrupt dealings?).

I’d love to replace “obedience” with something else, perhaps “honesty” and “trustworthiness” and “pride”.

Summary

I understand that we as Indians are very proud of our values but I’ve tried to argue that our values need to be re-examined.

Personally, I’d love to see the day when we replace all our values with just the value of trustworthiness.

Trustworthiness as a value would mean we’d fight for each other.  It would mean we’d protect the weak.  It would mean we’d be on time.  It would mean we’d be honest.  It would mean we’d be capable and skilled and strong.  It would mean we’d be proud of each other.  It might mean we’d never lose another war.

Reading Koller’s and Somik’s work you get the feeling that one day you might be able to evaluate the comparative benefits of two sets of values, and pick the better one, using plain math.

And hopefully, by showing them mathematical proofs, you can convince people to change their values and pick better ones for themselves.