Is the machine learning?

Do you remember the moment you knew that something fundamental had happened? The moment when a door opened to your future and there was no way you were ever going back.
computing history
Author

Allen Kamp

Published

October 25, 2021

Do you remember the moment you knew that something fundamental had happened? The moment when a door opened to your future and there was no way you were ever going back?

That moment for me was in the computer room at my high school in around 1980. At the time computers were not cool, and certainly those of us in the computer club were not cool, pocket protectors were cool though right? Then I saw a program on a ‘personal computer’ that blew my mind, the computer learned by asking questions!

The lead up.

In the early ‘80s most of our ’computer’ lessons were in Math classes, after having learnt a few rudimentaries of branching and looping, we would write out our program in our notebooks. Then painstakingly transcribe these onto optical-mark cards before the end of the lesson, trying very hard to avoid mistakes.

optical-card.jpg

These punchcards were bundled up and sent to the local university to be run. The following week (if we were lucky) we would get our program output back, printed on multi-fold paper. It was a long time to wait, just to find you’d made a simple syntax error or the program was halted to prevent an infinite loop. The long ‘debug’ cycle taught us to be very, very careful.

Many students gave up at this point.

There was no encouragement in that long ‘debug’ cycle to do anything interesting, nothing beyond replication of calculators. User interaction wasn’t a thing in such a process. A later staple of introductory programming classes, guessing .”higher or lower” would have taken months of round trips. It is why I chuckle to myself when someone complains that the internet is slow.

The changes.

It was around this time, with the help of the Math department that we began raising money for a computer for the school. And luckily it was also around this time that the government injected funds into the school curriculum specifically to help schools purchase computers. The computer club became a hive of activity, and before I left high school we had many computers. 5 to be exact. From memory, there was an Apple IIe, Ohio Scientific Challenger 1P 4K-Ram, two Ohio Challenger 4p 8K-Ram and a Commodore Vic 20 (it had colours-wow!!). To me the Ohio’s were beautiful wooden sided, metal cased machines - we learnt to program from the BASIC-IN-ROM 16 page manual. (You can play with an Emulator here).

2009-04-26-challenger fixed.jpg

Without these computers the moment may never have happened.

I feel like Grandpa Simpson when I talk about these things, and I am grateful at technical meetups for the few younger people who are genuinely interested.

The moment.

The day that opened up my lifelong fascination with computers, programming and machine learning was when one of my classmates implemented a program version of the guessing game. “What animal am I thinking of?”.

A game where you try to guess what animal the person is thinking of, by asking a series of questions that can be answered “yes” or “no”, until you feel you have enough information to guess. It usually it follows a sequence such as.

- Does it have a 4 legs?
    - No
- Does it have feathers?
    - Yes
- Does it swim?
    - Yes
- Is it a duck? 
    - Yes. You guessed correctly!

I’d seen guessing games before, usually in the form of number guessing “higher / lower”, or just guessing from a predifined list.

But what set this particular program apart from anything else I had seen upto that point was that by seemingly magic, is that could learn!. If it could not guess the answer correctly it would ask the user for information to help it answer correctly in the future. My tiny teen mind was blown. I had no idea at the time how it worked, but I took it as challenge to find out.

In context you have to remember, there was no hard-drive, floppy disk, no network, and barely enough memory to hold the program.

We had simple 20 questions type programs where we had pre-programmed all of the options and knew the outcome expected at any point. This was the first time I had seen a program know more than the original programmer had told it. This was the turning point, the big moment where I knew programming and computers was for me. It didn’t matter that I wasn’t allowed to go to university to study computing because I had studied humanities instead of physics or that the Australian Computer Society at the time wanted to prevent anyone without a computer degree from getting a role with computers. Nothing would stop me.

Thankfully society has moved on, the internet and open source communities have broken down those wall, there are many free resources and opportunities today.

What animal am I thinking of now?

Recently whilst working through the book Conceptual Programming with Python, one of the examples was a version of the program. And here it is in Python using classes, largely as per that book. Thank you to the authors Thorsten Altenkirch & Isaac Triguero for bringing back some happy memories.

(I had thought about re-writing the code to work in the emulator, I may do that in future. If you take up that challenge, please let me know.)

#slow
# from Conceptual Programming with Python, with minor modification.
class Knowledge:
        pass

class Answer(Knowledge): 
    def __init__(self,text):
        self.text = text

    def play(self):
        if ask("Were you thinking of a {}?".format(self.text)):
            print("I knew it!")
        else:
            newanimal = input("What animal were you thinking of?")
            newquestion = input("What is a question to distinguish between {} and {}?".format(self.text,newanimal))
            if ask("for {}, what should the answer be (y/n)?".format(newanimal)): 
                return Question(newquestion, Answer(newanimal),self)
            else:
                 return Question(newquestion, self, Answer(newanimal))

class Question(Knowledge):
    def __init__(self, text, ifyes, ifno):
        self.text, self.ifyes, self.ifno = text, ifyes, ifno
    
    def play(self):
        if ask(self.text):
            self.ifyes = self.ifyes.play()
        else:
            self.ifno = self.ifno.play()
        return self

def ask(q):
    while True:
        ans = input(q+" ")
        if ans=="y":
            return True
        elif ans=="n":
            return False
        else:
            print("Please answer y or n!")    

#------------------------

import pickle
try : 
    file = open("animal.kb","rb")
    kb = pickle.load(file)
    file.close()
except FileNotFoundError:
    # seed with a few defaults
    kb = Question(
    "Does it have 4 legs?",
    Question("Does it bark?", 
             Answer("dog"), Answer("cat")),Answer("bird"))             

while True:
    print("I can guess what animal you are thinking of." )
    if not ask("Do you want to play?"):
        break
    kb = kb.play()    

    if not ask("Do you want to save changes?"):
        break
    file = open("animal.kb","wb")
    pickle.dump(kb, file)
    file.close
   
I can guess what animal you are thinking of.
Do you want to play?  y
Does it have 4 legs?  y
Does it bark?  n
Were you thinking of a cat!  n
What animal were you thinking of? rabbit
What is a question to distinguish between cat and rabbit? Does it eat carrots?
for rabbit, what should the answer be (y/n)?  y
Do you want to save changes?  y

## And on the next round, it knows what a rabbit is..

I can guess what animal you are thinking of.
Do you want to play?  y
Does it have 4 legs?  y
Does it bark?  n
Does it eat carrots?  y
Were you thinking of a rabbit?  y
I knew it!

The Verdict

Yes, by modern standards it is pretty lame. But it was fun and inspiring then. I’m sure the modern ML achievements we have to today will seem as equally laughable to someone 40 years from now.

Was the machine learning? It certainly would not pass a Turing test, but it did behave as science fiction books lead me to expect. So teenage me will say “Yes!, the machine was learning”.

The door to the future had opened, there was no turning back. I’ve been hooked on programming and machine learning ever since.