Thursday 24 March 2016

ChatBot 4 - Sioni on the Web

Leat House
After a long break from ChatScript I now have enough to make Sioni vaguely interesting - to me at least.

Here he is: sioni.online

Status Update

I started out trying to find a way to build a conversational agent that would capture the life and times of someone like my grandmother. That way people could sit down and have a chat with a distant relative and find out about their lives in a much more engaging way than reading some facts about where they were born and seeing some photographs about where they lived.

How are things going so far? Here's a sanity check:

  • Is it engaging enough?
    Yes, it's not bad. It could be much more engaging if I put more time into the script. However, ChatScript is a great tool for bots, there's no doubt.
  • Is it possible to simply feed a bunch of stories and facts into a repository and have the bot use that for its memory of events for conversions?
    No, that's not what ChatScript does in it's current form. Although the recent extension of ChatScript to call out to other sources of truth using REST APIs is worth pursuing. Commercial bots obviously do this to some extent based on knowledge bases.
    Next blog post maybe. 
  • Is the experience rich enough?
    It's ok but it would be useful if the bot was able to use URL's in the script to display additional content or play audio files.  Another blog post.

What did I learn?

Events not Facts

I started with a mind-map of Sioni's world. Being as ChatScript is driven by topics, structuring the mind-map by topics is a good idea. I started with topics for friends, family and places etc. My initial approach was to have a whole bunch of facts as rules. This probably reflects my Prolog programming thought process. However, this approach doesn't result in particularly entertaining conversations! It is much better (as the ChatScript docs suggest) to have your bot drive the conversation. So I ended up with topics for specific life events driven by the bot. If you're building a bot based on your life events (as Sioni is) this is a much more natural way to remember your past and structure your bot. When we catch up with family and friends and talk about the past, we almost always talk about particular events - the memorable ones are often the most emotional too: funny or sad or significant in other ways. Once I figured out that was my best approach, the flood gates opened and the memories of particular events came in thick and fast: The day the onion seller came to the village, that time when I rode my bike into Annie May, the times we went to the big swing past the sand-banks and threw coins into the wishing pond, my first day at school, picking pees in the garden for dinner etc. etc.
If you have a chat to Sioni, you'll see these events come through along with some of my fact-based style weaved in. I haven't gone back and cleaned up the scripts - this is an experiment in bot creation and not a fully complete and consistent bot.

AWS Server

sioni.online is hosted in Amazon (AWS). If you're a bit technical, setting up the Linux server in AWS is straight forward. In fact, it's a lot easier than setting it up on the Mac. Look at "ChatScript Amazon Server.pdf" in the documentation directory.
I used the BETTER PHP files and modified them to call Sioni.

Topics and Behaviour

Because ChatScript remembers where you left off, its behaviour can be confusing when you're trying to develop more script. You need to rebuild and reset to get a clear idea of what it's doing. Initially, I was confused about why a certain topic was being executed and why. In simple terms, ChatScript stays in its current topic as long as there are things left to say and what you've typed matches a rule. If you type something that can't be matched, it will find a typic which will match and then find a rule within that topic. It's pretty obvious really but the behaviour when you're developing can be confusing.

Sublime Text Editor

There are now themes for ChatScript. Syntax highlighting makes writing ChatScript much easier!

ChatScript files

While ChatScript ships with example bots, creating a new bot by copying an existing one can lead to some confusion. I ended up copying quibble.topintroductions.topchildhood.top, keywordless.top, simplecontrol.top and the entire quibble Eliza file set. Update introductions for your bot, add a bunch of things to keywordless.top that makes sense for your bot, and update the simplecontrol.top to make sure it has the right topics are called in the control loop. Most of the text for Sioni is obviously in childhood.top.






Sunday 24 January 2016

Science and the Grand Confusion




I have many issues with the way science is taught and portrayed in the media. 

I've been meaning to write an informed, pseudo-academic post on this topic for a long time, filled with examples and references, all framed in an epistemological context with enough philosophical jargon to scare the most enthusiastic reader.

But, it's never going to happen and I need to get my thoughts down on paper in whatever form comes to mind!



So here it is...

Firstly, there is a confusion between what science does and what science is that starts at school.

Kids are taught science as a series of simple experiments about the world but rapidly realise that the science that matters is unbelievably complicated and largely inaccessible. If a teacher told you that playing chopsticks on the piano would give you a good grounding in the comprehension of symphonic masterpieces would you believe them? Would you bother?

Not only do people not understand much of what science has discovered, but they often don't have any confidence in scientists' proclamations about how things are. "We live in a multiverse where spooky action at a distance is true". Yep, really.

The scientific community are not doing a great job of convincing people that they know what they're talking about.  Unfortunately their approach is often arrogant and condescending. Strangely many scientists don't understand scientific topics that are only slightly to the left of their area of expertise. You can't expect people to believe in science by insisting they either a) be smart and do science or b) accept you are dumb but trust that someone else is smart enough to know what they're talking about. It doesn't work and it's not helping science.

I have a view of how science should be understood (and taught) that helps me through the quagmire of gibberish. And, fortunately for me, it's not such an odd view - as you'll see below....

I admit that this post takes a very simplistic view of the topic - but I'd rather take an approach that's accessible rather than fail to get my point across. The topic can be refined later.

Firstly, a definition:

Science is about building and testing models of the world around us. Models must fit what we know, and predict things we don't. Models that fit the best and predict the most top the leaderboard until a better model comes along.
Scientists are in the business of building models that compete in an open arena. 

That's it. No more, no less.

On face value, the concept is simple. It omits some of the loftier and more esoteric views of what it means to do science, but I believe the advantages of taking such a simple view are significant and could help humanity as a whole - a simple and worthwhile goal :)

But, is it reasonable to describe science this way?
Here's some views on the subject:
  • The Grand Design: Stephen Hawking and Leonard Mlodinow take the modelling idea to the point of suggesting that it is meaningless to talk about true reality - the only meaningful thing is to talk about the usefulness of the model. In many ways this isn't a new idea.
  • Nancy Nersessian highlights the central position of model building in scientific pursuit. Nancy makes the point that this is how science really gets done which goes against the traditional view that science is: dream up hypothesis, test etc. More on Nancy's work here.
  • David Hestenes' paper on reforming mathematical notation and the role of models in scientific knowledge acquisition provides another good example - he says: "Modeling Theory is about the structure and acquisition of scientific knowledge. Its central tenet is that scientific knowledge is created, first, by constructing and validating models to represent structure in real objects and processes, and second, by organizing models into theories structured by scientific laws. In other words, Modeling Theory is a particular brand of scientific epistemology that posits models as basic units of scientific knowledge and modeling (the process of creating and validating models) as the basic means of knowledge acquisition."
  • Models-Based Science Teaching: Understanding and Using Mental Models - Steven Gilbert.
Many have taken the view that models are central to the way in which we do science. In some cases they insist that science is nothing other than the pursuit of ever better models with an insistence that the models are our reality - talking about reality beyond the model is meaningless.

So this idea is not new - which is a relief.

What are the implications of this view?

Science and Religion

I'll talk about this topic first as it's probably the most common cause of confusion.
There is a constant dialog between "the religious" and "the scientific" community that resembles a conversation between a chicken and a duck.
The internet is awash with science vs religion discussions that get very heated very quickly.
What if we take the view that science is about building models? What part has God to play in such a scheme?
Firstly, if scientists are in the business of building predictive models, introducing God into the equation doesn't help. It doesn't introduce any predictive power into the model. It's not necessarily right or wrong, it's simply not of any use to a scientific model builder.
With this approach, you could believe in a God and do science. You would just have to accept the fact that God has so far been of no benefit to science. If you were to take the scientific model as reality, then God appears to play no objective role in our physical reality. However, we're talking about models here and not reality - more on that later.
So... you don't need to be an atheist to believe in science. You just have to accept that introducing God into a model doesn't improve the model's ability to predict objective outcomes.
Taking this approach helps dissect most of the religion vs science babble on the internet but comes at a cost for scientists. It means that scientists have to admit that while in a strong position, when it comes to predicting outcomes in the physical world, what they have is only a collection of models. Nothing more and nothing less.

Science and Facts

There is a whole body of philosophy dedicated to this topic which I won't cover here. But essentially, facts are simply things that we agree on (for now) that are true about things. There are also facts that are labels of convention: "that's a horse, my cat is black etc."
Facts are parts of our modelling frameworks that we hold true. Facts are often updated through model building. Come up with a better model that breaks some assumptions (facts) but predicts so much more and you have some new facts. There are no facts in the traditional sense.
Scientists have a habit of proclaiming things are facts when they know that the concept is quite fluid. They are simply terrified to admit that facts do change over time and they do not know all the answers. This is terrifying because, as soon as this ground is given up, there is a fear that the lunatic fringe will proclaim that "science has admitted it knows nothing", and so their opinion is as valid as any other! Scientists simply need to stick to the theme of explaining that while they may be proven wrong about something in the future, there's a good chance that the model they are using today is a pretty good bet compared to less scientific models. They should be prepared to simply state that they'd be happy to go head-to-head with alternative models and see who wins.

Rules of the Game

Which brings us to the rules of the game. If you want to play this game you have to agree on the rules. The rules are simple, as stated above, the better the predictive power of the model, the more points you get. Elegance and universality can be used to decide between models with similar predictive powers. If you don't want to stick to those rules then you can't participate in the science arena.
The rules have been selected through natural selection. They are the set of principles that when applied to the array of possible models have resulted in a working set of models that have helped humans survive in a difficult landscape. Our success as a species is clearly in part due to science which is a result of natural selection at many levels!
Obviously Science isn't the only thing that's helped us survive.

We all do so Science

Our brains do science all the time. We build and adapt models in our heads that allow us to catch balls, drive cars, understand language etc. How these things are modelled in our brains is up for debate, but whether or not we have a Bayesian machine or simply a large neural network the modelling is clearly going on. I'd go as far as to say that the reason science has emerged as a discipline is because it's simply a way for humans to collectively do what they do in their own heads all the time. Science wasn't invented, we've just taken it out of our heads and put it on the table - so to speak.

What about Reality

What about it? We only have models. Our entire experience of reality is through models. What we perceive as reality is simply the activation of models in our head. Whether or not there is an objective reality beyond our models is not something that science can answer. The limits of our models are not necessarily the limits of reality. We're moving away from science now an into the land of philosophy and religion.

Questions for another time:
  • What constitutes a good modelling framework? Mathematics? Computers? bits of stick and string? Why?
  • Is it always possible for models to overlap cleanly with other models? what makes models commensurate?
  • What can and can't be modelled?

Education

I'd like to see this view taken and used through all science education. I would prefer to see this view (philosophy of science) taught in schools instead of having kids conduct experiments. It would be much better for people to understand how science works than to do a few lame science experiments that teach kids very little. Very few people go on to do hard science. Ironically, teaching science by doing science may not be the best way for people to understand what science is, why it works and why you should trust it. Unlike cooking, geography or english, very little of what you teach kids in science has any use in day to day life. The same could be true for maths - more on that later.

There's hope: making models is accessible - "doing science" is less so.

Crowdsourcing approaches to scientific problems are now being framed as modelling problems: data sets are provided for analysis with the best solution winning a prize.
Defining science as the creation and selection of models may also help provide a more objective way to assess scientific progress. Who knows... what is the science of models themselves? Meta Science? or simply: Mathematics?

For my part, treating science as model building helps me to enter a new field of exploration armed only with a fertile imagination and the insistence that I check the validity of my models. It doesn't really matter that I'm not an expert before I start. I can still create models, review established literature and have fun [repeat]. 
The alternative is: Review established literature for many years, become bored, demoralised and despondent; fail to have an original idea and give up. 

Understanding the world should be fun - engage your creativity first and rigour second.

My hope is that this approach will not only help the status of science in society but also help many others enter science by simply unleashing their curiosity to build models.

Enough for now - more later.