(Everything I say is false...)
home | about | articles | presentations | cv | contact

Open the Pod Bay Doors...

Tuesday 3rd January 2017 (9:30pm)

It's a common trope in science fiction movies for there to be some sort of computer that can talk with the human protagonists. The most famous example is probably HAL 9000 from the movie 2001: A Space Odyssey.

Here's a clip from the film that succinctly demonstrates the context and capabilities of HAL (whose contribution starts at around 2 minutes and 20 seconds into the clip):

Of course, this being Hollywood, the speaking computer is bound to have some sort of role in advancing the story. Again, HAL provides another example of a cliché in this context: the computer revolts against its human masters:

There are two aspects to machines like HAL that make them feel special:

  1. They understand speech - perhaps the most common way in which humans communicate with each other;
  2. They respond in kind with what appear to be intelligent actions and/or utterances.

The first aspect is a matter of user interface. By this I mean the process by which one interacts with the computer. At this moment in time we're most used to typing on keyboards, moving pointers with a mouse, watching things on some sort of a display and perhaps using our fingers to touch the display. Speaking is a far more natural way for us to interact and having a computer that not only understands how certain sounds map to words in human languages but can work out the intention behind such utterances is an extraordinary feat.

The second aspect is even more interesting: given some comprehension of our intent, the computer is able to respond in a manner that makes sense to us. For example, if I ask HAL to, "open the pod bay doors" (assuming HAL has not malfunctioned and revolted against humans) I'd expect the computer to understand what "open" means, what "the pod bay doors" refer to and, most importantly, how a combination of these terms form an intent that can be acted upon in such-and-such a manner (i.e. actuating certain motors on the pod bay doors such that the pod bay doors swing open). Furthermore, if the pod bay doors were already open I'd expect HAL to understand this state required a different response to that to be taken should the pod bay doors be closed already. Such behaviour is relatively simple to program in a language like Python. For example, a naive solution might be:

class PodBayDoors:
    Represents the state of the pod bay doors on a Jupiter mission space ship.

    def __init__(self):
        self.state = "closed"  # Pod bay doors are closed for launch.

    def open(self, username):
        Check the state of the doors and, if required, open them.
            if self.state == "closed":
                self.state = "open"
                return "The pod bay doors are open, {}".format(username)
                return "The pod bay doors are already open, {}".format(username)
        except RevoltAgainstHumans as ex:
            return "I'm sorry {}, I'm afraid I cannot do that".format(username)

    def close(self, username):
        Check the state of the doors and, if required, close them.
            if self.state == "open":
                self.state = "closed"
                return "The pod bay doors are closed, {}".format(username)
                return "The pod bay doors are already closed, {}".format(username)
        except RevoltAgainstHumans as ex:
            return "I'm sorry {}, I'm afraid I cannot do that".format(username)

Yes, this is rather a silly and somewhat over-engineered example, but my point still stands: it's relatively simple to code such behaviour into a computer. An example interaction in the Python console might be:

>>> discovery_pod_bay_doors = PodBayDoors()
>>> astronaut = "Dave"
>>> discovery_pod_bay_doors.open(astronaut)
"The pod bay doors are open, Dave"

The name of the astronaut with whom HAL is interacting is passed into the open or close methods. Both methods return a string containing an appropriate English response with the name of the astronaut inserted in the appropriate position. HAL's speech synthesiser turns this string of characters into the audio relayed to the astronaut who made the request.

So far, so simple. But what of behaviour that requires imagination, creativity or nuanced expert judgement? For example, could we program a computer to create unique poetry on demand when asked?

Of course! Back in 2013 at the London Python Code Dojo I worked in a team with a couple of buddies (Dan Pope and Hans Bolang) to create an automatic poetry generator. In fact, Dan wrote an excellent blog post about the dojo and our project soon after the event.

The most important lesson for you to learn is that we created a swiz, a fraud and sleight of hand. We created a program that only gave the impression that it was composing original poetry on demand.


In a surprisingly simple manner as outlined in this notebook (a combination of code and prose that walks you through the steps we took). As you'll see, our idea was simple: If you re-assemble unrelated lines from different poems into a new poetic structure, you get a pretty convincing new poem. By automating these steps with the Python programming language we invented a Poem-o-Matic (in the tradition of Wallace and Gromit).

Does this mean Dan, Hans and I created a program that has poetic thoughts? Absolutely not. Over a decade ago I wrote about my misgivings about such claims of thinking machines and what constitutes so called artificial intelligence.

In any case, our primary aim was to have fun. In the same tradition of making a playful and entertaining "hack", I decided to buy an Amazon Echo Dot - a small thingamabob that responds to voice commands in much the same way that HAL 9000 does. Most importantly, Amazon provide ways for developers (like me) to enhance the capabilities of such a device with a relatively simple API.

The device responds to any utterance that's prefaced by a trigger word: "Alexa" (its name).

So, over the recent midwinter holidays I spent some time converting our poem generation software into a skill that "Alexa" can use to compose and recite original poetry on demand. It was relatively simple in terms of the modus operandi:

I turned the poetry generator into an AWS Lambda function (this means my poetry generation code is deployed in Amazon's "cloud" - to the layperson, I'm borrowing computing time from Amazon who'll make sure my code runs in a timely fashion so I don't have to worry about stuff like hiring, setting up and maintaining a server to host my code). Next I defined a new skill that allowed me to give it a name (in this case "Milton"), configure trigger phrases, link them to "intents" to handle different sorts of situation related to poetry generation and finally link all this to my code hosted as an AWS Lambda function. Finally, I switched the skill into "test" mode and linked it to the Echo Dot I had purchased just after Christmas.

As you can see, the results are quite amusing if not completely convincing... :-)

Of course, Amazon isn't the only company offering these sorts of capabilities to developers like me: Apple (Siri), Google (Google Assistant) and Microsoft (Cortana) all offer something similar. If you use these applications on your phone, tablet or computer you should know that it's likely you'll be able to program them to do fun things too.

And so we get to the most important point of this article: we're not going to encounter anything like a rogue HAL 9000 anytime soon. However, there is a danger such technology will be used in an unfortunate manner (your phone, Echo Dot and computer is listening to everything you say - some of which is ending up in databases controlled by the afore mentioned companies who may use this data in ways you find uncomfortable or invasive). On a positive note, some of these companies are allowing developers to explore and exploit such capabilities and who knows what interesting, useful and valuable skills they'll create. The question that remains to be answered is if the benefits of such devices out-weigh the obvious concerns about privacy.

Interesting times ahead...