Archive for the ‘code’ Category

Machine learning “Top Trumps”

Saturday, October 1st, 2016

A simple demonstration of machine learning to let a child train a computer to play Top Trumps

I’ve been talking for a while now about how we introduce the idea behind machine learning to school kids. I’ve given several talks about it but I’ve also tried out a couple of approaches to it.

Now I’m trying out another: training a machine learning bot how to play Top Trumps.

I’ve put a demo at


What is this?

It’s basically Top Trumps: that card game I used to play as a kid where you choose one of the attributes on a card, and if it beats the other player you get their card. Except it’s online, and you’re playing against a computer.

But the computer hasn’t been given any strategies on how to play, and has to learn from the player.

Initially, it makes random choices, but it learns from playing against the player. The more turns it plays, the more training it gets, which it uses to make predictions of which choice would give it the best chance of winning. (more…)

Normalised Discounted Cumulative Gain

Friday, July 15th, 2016

A ramble about accuracy compared with NDCG scores for evaluating effectiveness of information retrieval. It’s an introduction, so if you already know what they are, you can skip this.

A couple of weeks ago, we released a new tool for training the IBM Watson Retrieve and Rank service (a search service that uses machine learning to train it how to sort search results into the best order).

This afternoon, I deployed a collection of small updates to the tool and thought I’d make a few notes about what’s changed.

Most of them are a bunch of incremental updates and minor bug fixes.

For example, support for a wider range of Bluemix environments, support for larger document cluster sizes, displaying the amount of disk space left in a cluster, and so on.

One update in particular I thought was more interesting, and worth explaining.


Watson Rock, Paper, Scissors

Sunday, June 26th, 2016

A simple hands-on activity to let kids train a machine learning classifier to be able to play Rock, Paper, Scissors.

Screen Shot 2016-06-26 at 13.59.20

I’ve written and spoken before that I think we should do more to introduce children to the idea of machine learning. And I’ve tried introducing my two kids to it, such as by making a Code Club-style game with them: we built a system to play Guess Who, that they trained both to understand what you say and to recognise the characteristics of faces from photos.

This weekend, we tried out another idea – Rock, Paper, Scissors from a web app, using the web cam to see your moves, and training a system to recognise your hand signs.



An introduction to machine learning with Guess Who

Thursday, February 18th, 2016

I tried introducing my two kids to machine learning by helping them make a game this week.

In this post, I’ll try and explain why, how we did it, and how it went. And if you make it all the way to an end, I’ve got some videos and a link to a demo to show you what we made.


I think we need to introduce the basic concept of machine learning to children.

I think the current approach to introducing coding using things like Scratch aren’t enough. This isn’t to say Scratch isn’t great (I’ve been running a Code Club every week for the last couple of years, delivered almost entirely using Scratch, so I’d be the last person to say it isn’t a fantastic tool). It lets you snap together blocks representing actions to teach the programming mindset of getting a computer to do something by you breaking the task down into a series of steps.

I think we need to add to this with something that introduces the model of machine learning – getting a computer to do something by training it with examples of doing that task.

I’ve been saying this for a while – I gave a talk about it at an education conference last year, I’ve written about it here before, and it was the theme of a lecture I gave at a science society in London last month.

This week is half-term and I have the week off work, so I thought I’d finally spend a bit of time trying it out by experimenting on my own two daughters (Faith and Grace, who are aged 7 and 11).

In Code Club, I mostly try to introduce programming concepts by helping the kids to create games. Sticking with what seems to work, I’ve helped them to make a game by training an ML system how to play it.


Don’t be like blonde Gwyneth 

Wednesday, December 2nd, 2015

Or a helpful pointer for developers contributing fixes and changes to an existing code base.

Do you remember that old Gwyneth Paltrow movie Sliding Doors? Imagine that she’d been a software developer who had been asked to fix a problem with an existing software project.

Next thing you know she’s running for the train, some kid gets in her way and she misses the train but also gets the train, one of her gets a dramatically convenient hair cut, and we’re left with two Gwyneths and two insights into how things could play out.


Connecting to MQ Light from a web app via WebSockets

Monday, May 25th, 2015

How to subscribe to MQ Light notifications from a web app, via a WebSockets bridge

I’ve been working on a microservices app hosted on Bluemix. It’s one logical app, but it’s implemented and deployed as a bunch of separate Bluemix applications, each with it’s own separate responsibility.

I’m using MQ Light as asynchronous messaging between the apps. Each Bluemix app publishes notifications about changes to resources, and the status of long-running tasks.

mqlight on Bluemix

I won’t labour why or how we do this here, as it’s well covered in many other posts on microservices. For example:

…publish everything, however boring and insignificant it may seem to the rest of the system. Publishing is very lightweight and the publisher does not need to know whether 0 or 1000 other services are interested in that particular event, just fire and forget. This is extremely powerful and is what enables microservices to be built and deployed extremely quickly…

This is working well, but I also want a web app to be able to get some of these notifications.

If the web app has a resource open for editing, I want it to get a push notification if there are any changes to the resource.

If the web app started a long-running task, I want it to get push notifications of status changes.

I’ve done this by writing a small proxy, allowing a web app to subscribe to MQ Light topics and get the message via WebSockets.

Essentially, it’s an mqlight-WebSockets bridge.

mqlight with WebSockets on Bluemix


Recycling: a Scratch game for Code Club

Sunday, April 19th, 2015

Grace and Faith have been helping me work on a new project for Code Club. It’s not quite finished yet (Excuse: Thanks to the holidays, it’s still over a week till my next Code Club class!), but it’s close enough that I thought it’s worth sharing the work-in-progress.

The basic idea (more than a little inspired by an old Mega Drive game we’ve played) is that you have to catch falling bits of rubbish and put them in the correct recycling bin.

A playable version is embedded here if you’re using a Flash-friendly browser. Press the green flag to start, use the arrow keys to run left and right, and press the space bar to throw what you’re carrying. (If the embed isn’t working, you can also get to it on the Scratch website.)

I’ve started writing up how we made it, using Code Club’s lesson format tool. (A tool that reads Markdown with a few Code Club-specific extras).

The write-up is still a little rough around the edges, but the source for what we’ve got so far is on github.

And I’ve used lesson_format to create HTML and PDF versions in the Code Club style.

How to use the IBM Watson Relationship Extraction service on Bluemix

Sunday, January 25th, 2015

Before Christmas, I wrote about how I used the Watson Relationship Extraction service on Bluemix to pick out the things mentioned in news stories, as part of a mobile app we built on a hackday. I’d still like to do something more with that app, but in the meantime I should at least share how I did the Relationship Extraction bit.

From the official doc for the service:

From unstructured text, Relationship Extraction can extract entities (such as people, locations, organizations, events), and the relationships between these entities (such as person employed-by organization, person resides-in location).

This is provided as a hosted service on IBM Bluemix where any developer can sign up and give it a try.

It’s available as a documented REST API, but as part of using it in the hackday, I needed to write a bit of code around that, just to prepare the request and parse the response. I think it’ll save me time to reuse this the next time I want to build something with the API, so I’m sharing it as a standalone package.

In this post, I’ll walk though how you can use it, with a small app that grabs the contents of a BBC News story and picks out the names of people mentioned in the story.