The Journey is the Thing

...or, a brief introduction to machine omletting.

Thinking back on when I started programming as a kid, I could pretty well sum up the playing around that I did then (and to be honest most of the work I do now) as writing a recipe. The "deliverable" was a set of instructions for getting a desired outcome. To be a little silly, I could say this is like teaching you to make an omelette by telling you what to buy at the store, steps one through whatever for cracking the eggs, slicing the veggies, heating the pan, et cetera.

For a little while I've been trying to think of a metaphor along these lines for machine learning, and I think the best example would be putting a couple of eggs, some whole mushrooms and bell peppers in front of you. Then I show you plate on which is a fully prepared omelette. Then I ask you to tell me how to get from the input (the "bare" ingredients) to the output (the prepared omelette). Maybe it wouldn't be clear to you at first, let's say for example you are from a non omelette-speaking country. So I keep showing you examples of inputs and outputs for omelettes and other omelette-like foods (say a frittata). Hopefully, given enough examples and enough practice, you become trained and proficient in the art of egg-based breakfasts.

In a sense, this is what we are doing when we are training in the machine-learning sense. We are less interested in providing a "recipe" (algorithm) to the computer to get from input A to output B. Instead we feed the computer a ton of inputs and outputs of enough similarity that the computer learns the algorithm on its own, such that it can be relied on in the future to produce a sensible output given only an input.

I thought it would be fun to put together a little demo of this concept, so I wrote a small program call "tiny-learner" that derives a function capable of producing reliable output given a set of inputs and outputs, in the spirit of much more complex use cases. In this demo, we provide tiny-learner with an input that we expect to be operated on via one of four possible mathematical operators: addition, subtraction, multiplication, or division. If I did a halfway decent job, tiny-learner should (when given enough examples) then be able to deduce an appropriate function for producing a reliable outcome given only an input.

Here's an example session with tiny-learner:

$ node index

Let's start learning. What is the input? 1
What is the output? 6

Let's keep learning. What is the input? 5
What is the output? 30

Function learned:

function anonymous(input) {
  const result = input * 6;
  console.log(input + ' * ' + 6 + ' = ' + result);
  return result;
}

Let's exercise the learned function.
What is the input? 7

7 * 6 = 42

It's a silly toy, for sure, but I hope it's fun to play with and somewhat instructive. It's available to clone from the following repo: https://github.com/jeromecovington/tiny-learner

That's it from me for now, I'm hungry for breakfast. Maybe something with eggs, I'm thinking.