Kikai I: An Unusual Story

http://i1367.photobucket.com/albums/r796/skyarmor/banner11_zpsf84u526u.png

Kikai - a 3D dark-themed mystery game with focus on story and AI

Prologue

During his gradual recovery from a chronic disease, a musician and luthier had traveled to a beautiful foreign land. Just to get away, relax in scenic beauty, and maybe find some musical inspiration. He left the crowded, distracting cities to travel all the way to a border town so he could enjoy the best sceneries there were.

Then the war broke out.

Everyone lost their minds and chaos ruled. In the midst of all this, he found a boy with a broken leg, crawling against the stream of people running away from the fighting.
He couldn’t just leave the poor boy. He tried to pull him away from danger, but the kid showed him a picture of a girl and pointed deeper into town. With haste, he helped the boy get to where he wanted to go: a large laboratory. There was screaming coming from the inside.

They followed the sounds deeper into the building until they encountered a small girl stabbing a female scientist to death.

The girl passed out and the boy crawled to her immediately. There were three corpses at the scene, two in white lab coats. A picture on the wall showed the dead people and the two kids, all happy and smiling.

The musician was still shell-shocked, but with the war outside, dangers were already on the doorstep again. He took it upon himself to protect the kids from the war. The boy’s name was Kai and the girl’s was Kira. They showed him the few underground lab rooms that they had access to, and the three of them made it their home while the war raged on outside. Introduction

The game will have action and stealth mechanics as well as puzzle and visual novel elements. We want to focus on the story, the AI and the immersive atmosphere of the game. Playing as the foreign musician, you will explore the mysterious labs, the war-ravaged town and the scenic landscape surrounding it, looking for supplies and answers, while trying to take care of the children and teaching them right from wrong. With our robust AI learning system, the children will respond to your actions and gradually change. Our goal is to deliver the truest, deepest and most emotional experiences.

The kids’ AI will be developed with Machine Learning, which means they can learn through experiences. For example, if you always kill enemies upon met without mercy, the kids will grow to be violent. If you help other people frequently, they will learn to do the same, etc.

Art & Screenshots

https://dl.dropboxusercontent.com/s/pgziru5m7yxkolq/labBb.png

https://dl.dropboxusercontent.com/s/mx2tl87yrmjery6/controlroomb.png

https://dl.dropboxusercontent.com/s/j84ob05cygtqppr/reclimation1b.png

https://dl.dropboxusercontent.com/s/kgciyruwdt1agnu/reclimation2b.png

https://dl.dropboxusercontent.com/s/rq793tdqjafzx7a/machinesroom2d.png

https://dl.dropboxusercontent.com/s/3dh62drh8tvyqdv/machinesroom.png

https://dl.dropboxusercontent.com/s/ko3hx32kn5duk65/Kai (1).gif

The Light Novel

http://i1367.photobucket.com/albums/r796/skyarmor/18d55071-fca5-4300-b728-621c3c9e5384_zpsc4tjxrb6.png

We’re going to demonstrate the game world and tell some stories through a light novel written specifically for the game. A chapter will be published every month or two. We’re not going to spoil much and might even insert some lies and misleading clues. The point is to make sure everyone can feel the game better and imagine what kind of mysteries there are. You will have to play the game to truly understand the characters and mysteries.
I () am the writer, Jaco is our editor and Trieu is the illustrator.
You can read all chapters here!

The Team

  • ** ** (writer, programmer)
  • **Trieu ** (concept artist)
  • Jaco (English proofreader, editor)
  • **** (3D artist)
  • Josh (composer)
  • Ian (animator)

You can read all chapters in better format here, first time loading the site might be a bit slow though!

[FONT=Comic Sans MS]Prologue
During his gradual recovery from a chronic disease, a musician and luthier had traveled to a beautiful foreign land. Just to get away, relax in scenic beauty, and maybe find some musical inspiration. He left the crowded, distracting cities to travel all the way to a border town so he could enjoy the best sceneries there were.

Then the war broke out.

Everyone lost their minds and chaos ruled. In the midst of all this, he found a boy with a broken leg, crawling against the stream of people running away from the fighting.
He couldn’t just leave the poor boy. He tried to pull him away from danger, but the kid showed him a picture of a girl and pointed deeper into town. With haste, he helped the boy get to where he wanted to go: a large laboratory. There was screaming coming from the inside.

They followed the sounds deeper into the building until they encountered a small girl stabbing a female scientist to death.

The girl passed out and the boy crawled to her immediately. There were three corpses at the scene, two in white lab coats. A picture on the wall showed the dead people and the two kids, all happy and smiling.

The musician was still shell-shocked, but with the war outside, dangers were already on the doorstep again. He took it upon himself to protect the kids from the war. The boy’s name was Kai and the girl’s was Kira. They showed him the few underground lab rooms that they had access to, and the three of them made it their home while the war raged on outside.

[FONT=Comic Sans MS]#1: Ink

Yet another day on this horrible battlefield.

With those same eyes, with that same face, Kira has killed again. We were just out on a quick supply run when some young men jumped us. I couldn’t stop her in time.
Kai didn’t react much; he must be used to it by now.
I know that I’ve got to do something to fix this, but the whole situation is just too overwhelming for me to handle. The stabs of pain still haunt me every day, even though the disease has stopped getting worse.

Before I got sick, I once had to babysit my brother’s kid, so he and his wife could enjoy a holiday somewhere on the coast. The boy was well behaved. He always listened to adults and was perfectly polite.
Yet just taking care of him for one day was more exhausting than a 16 hour shift at the factory.
Now I’ve got two strange kids to take care of. They don’t even speak my language. And the days just seem to go on forever.

Kai and Kira have already entered the basement, but I’m still here playing my violin in the light of this melancholy sunset. There was a big battle in the east earlier this morning, so it’s been quiet for a while now. I just don’t want to miss the chance to play some music out here, in nature. I don’t think I’ll ever get another opportunity. I choose a peaceful Baroque song I’ve just learned to play.

I chastise myself for the horrible tempo. Even though I know that the soul and character of a song comes from imperfection, I still want my performances to be perfect. I can always move along with the music if I want more emotion. But this sloppy tempo is just too painful to listen to. What a horrible day this is.
I sigh, carefully putting the violin back inside its case. I plod up the handful of steps to get inside the house.

Ink?

On the way in, I find a multitude of dark splotches that look like blood, but smell strongly of ink. They’re scattered all over the floor, but they seem to lead somewhere. I carefully follow the marks. They lead to the bodies of the two scientists who had been living with the children.

I try to hold back my lunch as I look at the gaping holes where the chests of the two scientists have been torn open. Empty cavities stare back where their lungs and hearts should have been.

Around the wounds are sharp and decisive bite marks, as if a huge beast had ripped the scientists open and eaten their innards.
There are no blood stains around the corpses. Only ink marks. Hundreds of them, scattered violently all around the room, like some kind of macabre modern art painting.
None of the dark purple-black marks are spatters of blood. Did the beast lick up every last drop?

Suddenly the danger of the situation sinks in, and I immediately run to Kai and Kira.

Thankfully, they’re still safe, but there’s no time to waste. I quickly lock all the doors, then recheck every corner of the rooms.
After having checked and rechecked everything to make sure the rooms are safe, I catch my breath and finally feel a sliver of relief.

We have dinner in silence. I make sure the kids have brushed their teeth and then go lie flat on my back.
I soon fall asleep.

I wake up after a dreamless night, feeling tired and empty.
Kai is still fast asleep. Kira, on the other hand, confirms that I’ve awakened, staring at me with her blank eyes, and then stares into space impassively, holding her favorite doll in her arms, as always.

I brush my teeth, wash my face, then go to the kitchen to prepare breakfast. I think of my old house, back in the homeland. It was just a small box of a house but it had a nice warm bath.
I really wish I could take a bath.
Once breakfast is ready, I go to wake Kai up. As always, he opens his eyes lightly and then closes them again. He’s awake, he just needs a little more time and effort to get out of bed.
Funny how a single blanket could turn a leopard into such a harmless sloth.
After leaving a hot water bowl and Kai’s face towel next to his mattress, I head back to the kitchen.

To my surprise, the old wooden dining table has already been set. Kira sits in her place, still holding her doll impassively. Her eyes are as blank as always, but I know she’s gradually changing.
With such a simple action, she has blown away all of my worries and exhaustion.
Even though my body is tired, my smile has finally come back. I pick up my violin, gently rub Kira’s head, and then start playing a few of my favourite pieces. Kai, having finally left his bed, ambles closer to listen to my music. His face is unwashed, as expected, and Kira is still not reacting much.

But I don’t mind. I continue to play with a smile on my face.

During the entire meal, Kai talks to Kira in excited tones. I guess he had some really good dreams last night. Kira doesn’t reply often, and when she does, her voice is so quiet that I doubt even Kai could hear it.
But I could see her subtle smile every now and then. The whole atmosphere is really warm. It reminds me of Sunday dinners when I was a kid.
We don’t have to go out today. After cleaning up, I just stand in the corner of the room, watching the kids play.
I haven’t been in such a good mood for a long time, so I decide to seriously clean up and reorder the rooms. I haven’t really cleaned at all since we started living here a few days ago, and I want the kids to live in a clean environment anyway.

I start with the books that Kira piled up in the corner after finishing them. I wish I could understand the language, just to know what she’s been reading. There are some books with silly covers, but most of them are too generic to guess.

With all the books in my arms, I head to the library room.

This one… goes here.
Title starts with L… there, that last row.
This last ro…

Ink!?

=============
You can read all chapters in better format here.


Kai’s bravery

Summary
Kai learns how to react to enemies from the way the player reacts. He could either be brave, always confronts the enemies without fear or could simply be a coward, just runs away all the time. This bravery of his depends on how the player plays the game.

Prototype
At the beginning, Kai is coward in general. His coward level is randomly generated though. For some players, he just runs away all the time. For others, he might actually choose to confront the enemies when in real danger.


(a rather brave newborn Kai)


(a not so brave newborn Kai)

The bravery level B varies from 0 to 1. Kai is bolder when B is closer to 1 and tends to run away when B is closer to 0.
The cool thing is that this bravery level B differs with situations. Kai won’t just either run away or confront the enemies all the time, he might run in one situation (the enemy is still very far) and confront in another (the enemy has already come close).

Now let’s see how Kai grows!

  • With an aggressive player, Kai’s bravery might change like this:


>>

  • With a rather shy player, Kai’s bravery might change like this:


>>

-vCA

A more balanced player will help Kai grow the bravery level B to around 0.5 for different situations.

We could also easily expand Kai’s observations to base his decision on, not only how far the enemy is or has it detected Kai or not, but also what kind of weapon the enemy’s holding, how threatening it is, is there a closet nearby… The number of decisions could also be easily expanded, adding the options to hide in a nearby closet, setting up traps, etc.

Note that this model is only for Kai’s bravery, not Kai’s aggressiveness, since Kai can either knock the enemy off, put it to sleep or kill it when confronted. Kai’s willingness to kill is then another model, influenced by the player and different situations. These models can link with each other and by designing different models like these, we could develop really deep and realistic AIs.

These models also have a learning rate and a *momentum *used to define how fast the AI learns. So we can control how fast Kai grows or is influenced. For example, killing the first person will make killing a second one easier, while sparing a life or two won’t really make one less likely to kill. A few runaways also won’t immediately turn someone into a coward.

Programming
Use a simple Neural Network with Stochastic Gradient Descent.
Implemented using classic OOP classes without matrix multiplication, since importing libraries into UE could be heavy, buggy and anti cross-platform. Also, implementing my own Neural Network helps boost my understanding of it, which is still quite low.
To do: Optimize the Neural Network code, make sure SGD works well with data gathered real time in game. Learn more Neural Network, Gradient Descent & Machine Learning techniques.

I have updated the Kai’s bravery prototype post so if you’re interested in AI, check the previous post in this thread!
We’re going to introduce our first 3D Artist soon too while the first chapter of the Light Novel’s also doing well.
Cheers guys!

We’re very happy to announce that has joined us as a 3D Artist.
We’re still searching for some more 3D artists so if you’re interested, contact us at

We’re very happy to announce that Josh has joined us as a composer.
He’s going to work on a special track for the game soon.
The story behind the track and more details will be revealed once we have a demo to show :smiley:

We’re also very close to finish the first chapter of the light novel and still looking ceaselessly for more 3D Artists.
Hope everyone’s doing fine as always.

Looks great Skyarmor, can’t wait to see what your team comes up with soon :slight_smile:

;656650]
Looks great Skyarmor, can’t wait to see what your team comes up with soon :slight_smile:
[/QUOTE]

Thank you so much for your kind comment :smiley:
We’re going to post more stuffs soon, stay tuned!

Will do! Thanks :slight_smile:

I love that log on the top. real nice; good luck!

;656935]
Will do! Thanks :slight_smile:
[/QUOTE]

Thank you! :wink:

Thank you so much, more stories coming soon!

Anyway, we have finished and finally published the first chapter of the light novel, you can check it out here.
We have also launched our Facebook and Patreon. Please share the game with your friends if you like it ;)!
More news coming soon!

Will he ever get that tempo right?!

Gripping for a first chapter! I’d love to hear more :smiley:

;657435]
Will he ever get that tempo right?!

Gripping for a first chapter! I’d love to hear more :smiley:
[/QUOTE]

What a horrible practice skipper! Or maybe he was just having a bad day, I need to write more to understand him better :smiley:
We’re working to finish the second chapter too, but it won’t be released until we reach our goal on Patreon :frowning:
But Enmanuel, another 3D Artist has just joined us (welcome!), more in-game updates should be up soon, stay tuned!

What a horrible practice skipper! Or maybe he was just having a bad day, I need to write more to understand him better :smiley:
We’re working to finish the second chapter too, but it won’t be released until we reach our goal on Patreon :frowning:
But Enmanuel, another 3D Artist has just joined us (welcome!), more in-game updates should be up soon, stay tuned!
[/QUOTE]

If you ever need help with UI stuff by any chance, I’m your guy!

;657474]
If you ever need help with UI stuff by any chance, I’m your guy!
[/QUOTE]

Thank you so much for the constant support!
We’re still focusing on the core of the game right now so there won’t be UI tasks until March.
We will remember to contact you once we reach that stage though :D!

I like the idea for the AI. It’s a pity more games don’t make use of neural nets and other machine learning approaches, though I can certainly understand the reasons. It just feels though like for many years now, all the focus has been on bigger worlds and better graphics, and AI gets so little attention.

I’ll be interested to see how you go with this side of things.

Thank you for the support man!

And yes, many developers nowadays (especially the bigger ones) should be able to implement sophisticated AI without problems.
I believe they choose not to simply because complex AI can confuse players, which can lead to a less “fun” game and less sales.
Focusing on graphics and other appealing factors are easily better choices.
There are also a lot of young fellows who have been doing great things with Machine Learning and Deep Learning too.
So although I still need to learn a lot more, I believe that Kikai’s AI is technically realistic and doable.

Let’s see how far we can get!


Teach the kids English (Part 1)

Introduction
I have been trying to develop a system where the player can teach English to Kai and Kira. And after skimming through some research papers about natural language processing, chatbots,… I was truly intimidated and depressed. I was afraid that it would take me years of study just to understand how to make a “state-of-the-art” natural language processing system.

I soon came to a conclusion that I was too systematic, instead of being creative. Why search the whole net for academic articles when my goal was not to create an AI that can discuss philosophy? Making games is so much different from solving real life problems. We can define our own rules, most sloppy logic are plausible. I was coward for being afraid of creating “not good enough” systems.
We have to be creative. Game systems are fine as long as they work.

So while I would not stop exploring Machine Learning and other intermediate AI techniques, I’m going to start humble and naive here with my own language processing system. Enjoy!

Background & Goals
We want the kids to learn English so they can communicate better with the player.
The player talks to them by typing sentences into a textbox, instead of choosing from scripted options. The kid will reply if they can grasp what the player said. Below are some of the conversations we want to achieve:

1. Simple Q&A

  • The player: What’s your name?
  • Kira: Kira
  • The player: Do you like my dishes?
  • Kai: No

Since the kids are new learners, we can allow them to ignore grammar. By training them with neural networks, they will interpret sentences by patterns rather than by grammar rules and structures. So the following conversation is still plausible:

  • The player: What you name are?
  • Kira: Kira

Both native speakers and new learners should be able to interpret “What you name are”. Native speakers, young people “deliberately” use wrong, ignore grammar all the time.
That said, we still need to keep patterns under control, “You what are name” should be interpreted as nonsense. This can be done by creating training data by hand.

2. Q&A with more context

  • Who are the dead people?
  • Why did you kill the female scientist?
  • Where is that doll from?

These are the questions that help the player gather valuable information to unfold the mysteries in the game. The player is free to come up with all kind of questions. The kids will answer the ones that they can understand.
Tell the kids to study English everyday if you’ve come up with some critical questions that they have not yet understand.

3. Instant Enquiries, Ask for help & Planning

  • Are you hungry?
  • Where is Kai?
  • What kind of stories do you want to hear next?
  • We’re running out of water, do you want to go get more tomorrow?
  • Do you want me to play some music for you now?
  • Can you help me find some batteries in the other rooms?
  • Put the clothes on the floor back into the closet
  • It’s still early, go read some books

The kids will answer, act differently, depending on their states and other conditions.

4. Behaviours, habit and manner related

  • Please don’t go out alone next time
  • Don’t talk to strangers
  • Put the book back to its shelve after reading it.

5. Casual conversations

  • The player: What is your favorite band?
  • Kira: Pantera.
  • The player: Ah okay. They’re great and all, but have you listened to Iron Maiden?
  • Kira: No. Tell me more about them. Are they metal?

6. Conversations which the kids start

  • You look tired, are you alright?
  • Have you taken your pills today?
  • What will we have for dinner?
  • Do you even have a name?

7. Complete nonsense

  • The player: Kai, how much wood would a woodchuck chuck if a woodchuck could chuck wood?
  • Kai:

  • The player: Hah!
  • The player: Kira, how much wood would…
  • Kira: Shut

Finally, our main goal building this system is to help the main characters communicate and interact better. So instead of a system that relies heavily on complicated patterns and grammar rules, we will focus on the kids’ personalities and their understanding of the world around them. How the kids “feel” and interpret a word is more important than that word’s formal definition in a dictionary. As long as talking to the kids is fun and informative, we’re solid.

So we will have to come up with creative and effective ways to represent words, objects, events, relationships, etc for the kids to understand as well as getting better at understanding. Since we don’t want the kids to know everything right off the bat.

Problems to solve

  1. How can the kids learn patterns to interpret what the player says?

  2. How can they build up their own expressions, answers?

  3. How can they remember the context of the current conversation to maintain a consistent one? For example:

  • The player: What is your favorite band?
  • Kira: Pantera.
  • The player: Any others?
    Kira is expected to know what do *others *refer to so a simple sentence by sentence algorithm is not good enough.
  1. How can they maintain consistent memories? To avoid:
  • Kai: Carl, let’s go!
  • The player: I’m not even Carl.
  • Kai: Paul, let’s go!
  • The player: I’m not Paul, and we just agreed to stay home 2 minutes ago.
  • Kai: Nevermind then, Carl!
    Again, a simple sentence by sentence algorithm won’t work.
  1. How would the conversations affect the kids? If they do, how? Will the kids learn new things from the conversations too?

I will tackle these problems and update their status with each development log. More problems, suggestions and directions are well appreciated!

How the kids learn
They will mostly learn the language through books themselves. The player can help them study or tell them to, but they will mostly study on their own.

The books the kids learn from have different chapters. Each chapter brings more knowledge, which help improve their English and other skills. This gradual learning works well because it does not require huge data right off the bat.

They both start with English starter books for kids. When they reach a certain level, the player can show them more kinds of text. It can be some moral short stories, simple cooking recipes, etc. The kids will grow differently if they are given different texts, in different orders. Their levels differ too, Kira will likely to spend more time studying so she will get better faster than Kai.

The player will first teach the kids the alphabet and numbers by clicking a button and everything is done. A mini game for this might be okay but is unnecessary for now.

Programming, Demo
Will be demonstrated clearly from the next part.

References, inspirations

  1. Natural Language Understanding: Foundations and State-of-the-Art
  2. Making a chatbot that drives a narrative in sci-fi exploration game Event[0]
  3. Deep Learning for Chatbots, Part 1 - Introduction

P/s: Please forgive me for making dumb English mistakes while trying to teach the language itself to AIs :eek:

On a side note, our 3D artists have been working hard, pumping out new models everyday! We will start showing stuffs once ready.
Our composer has also recorded some really cool demos, the light novel is doing well and more concept art will be published next week, stay tuned :smiley:

Teach the kids English (Part 2)

Introduction
I have come up with a “plausible” language system design and have been working on it. I start with recognizing sentence types (normal sentence, question and order) using a Neural Network with Batch Gradient Descent.

System Design
This system’s goal is to simulate smart chatbots. It takes a sentence as input and is expected to produce a reply as output. For example:

  • Input: What band do you like?
  • Output: I like Pantera
  • Input: Any others?
  • Output: I’ve been listening to Iron Maiden too, they’re solid.

The player will produce input by typing into a textbox and the kids will reply.

Since we want the kids to remember the context of the current conversation, their relationship with the speakers, as well as inserting their own opinions, feelings and thoughts into their interactions, a simple sentence by sentence matching system won’t work.
Instead, I will run the input sentence through a few different neural networks and functions to extract a bunch of useful details. These details will then be combined with the context object, the kids’ personality and state objects to construct a reply.


A small taste of MS Paint

We will want to extract the following details;

  • Sentence type (Normal sentence, question, order, etc)
  • Question type (Ask for reason, fact, mean/way, etc)
  • Main subject
  • Main object
  • Main verb
  • Main adjective

For example:
1. What is your name?

  • Sentence type: question
  • Question type: fact
  • Main subject: listener
  • Main verb: be
  • Main object: name

2. He loves cake

  • Sentence type: normal sentence/inform
  • Main subject: he
  • Main verb: love
  • Main object: cake

Recognize sentence type with Neural Network
I will demonstrate my steps building a neural network which can recognize the sentence type of the input in this section.
Since many things are still unclear to me, any suggestions, corrections and clarifications are well appreciated.
I also believe this article is a good start. If you’re familiar with Neural Networks and interested in smart chatbots in games. Feel free to go along!

Step 1: Define the Neural Network
I split the input sentence into words, instead of characters or chunks of data so I could control the vocabulary of the kids. The “?” and “!” mark are each counted as a single word… The maximum number of words an input can hold is 15. That should be enough to cover most “meaningful” sentences in our game context. So we will set the size of the input layer to 15.
Observation: If our date set is large enough, reducing the size of the input layer to around 10 won’t improve our algorithm performance much!

The output layer will have 3 neurons, used to classify Normal sentence, Question and Order. I use Sigmoid function and 6 hidden neurons in a single hidden layer.


The Neural Net model without bias neurons

Step 2: Generate and process Data
We can easily build a list of common nouns, verbs, adjectives then write a program to generate normal sentences, questions and orders from these words. My current data set has 500 sentences, which I mostly generate by hand and copy-pasting patterns. It’s easier to manage for now.

[table]
normal.txtquestions.txtorder.txt

Because I am tired
Clean food is good
Dinner is ready
Food need to be clean
Goodbye
He is bored

Are you alright?
Are you fine?
Are you happy now?
Are you hiding something?
Are you hungry?
Are you okay?

Admit it
Answer me
Be careful
Be quiet
Be yourself
Beat it!

You can get the full data set here.

I then read the sentences from the files, extract words from them then fetch into a std::map like this:


std::map<std::string, int> words;
...
if (words.find(newWord) == words.end()) {
    words.insert(std::make_pair(newWord, words.size());
}

So now each word is labeled with a different number. We can then transform the input sentence into a std::vector of these numbers to fetch our Neural Net. I thought of 2 different ways to order the words:
Either place the words right at the head: what, is, your, name, -1, -1, -1, … ]
or in the middle: -1, -1, -1, -1, what, is, your, name, -1, -1, … ]
I quickly tested both version and their performances are pretty close if our data is large enough. Placing the words in the middle seems quite interesting but the first way feels more stable to me.

I then perform a simple feature scaling. I don’t know what is the best way and why not doing this hurts the algorithm a bunch. For now, I’m simply dividing each number in the vector by the number of known words:


res* /= words.size();

With that, we have been able to set up the training data. A training case should look like this:

  • input: { 0.317073, 0.198171, 0.131098, 0.344512, 0.0121951, 0.0152439, 0 0 0 0 0 0 0 0 0 } // What is your name?
  • output: { 0, 1, 0 } // Question

We can also write a simple function to auto-correct unknown words, like “wat” -> “what”, and transform plural nouns to singular, singular verbs to plural (“dogs” -> “dog”, “eats” -> “eat”), etc. More on this on upcoming articles.

Step 3: Training
With the data ready, I train the Neural Net with Batch Gradient Descent. Since I have very poor data, only 500 sentences for 328 different words, I have to run Gradient Descent with a small learning rate (0,025) for 600 iterations! The result is below, which can be said to suffer from both underfitting and overfitting (What???). I couldn’t even reach 80% accuracy on the training set, need better data!


Excuse me if you could see “Neuron Network”, I was not really bright

I’ve also recorded a video inspecting the trained neural net. Check it out :smiley:

So I’ve been able to create a neural net that works, but not well. It can’t fit the training well enough, reaching only 77%~79% accuracy on different runs. I will start working on the data first, then tackling more minor problems that I’m still unsure of. Like trying different hidden layer numbers and sizes, tweaking the learning rate, etc.
Again, I will be very happy if we can form a group working on smart chatbot, not specifically for Kikai, but for games in general. Any comments, corrections, suggestions and questions are well appreciated.

Anyway, of the 5 problems that I’ve mentioned in the first article, this article only touches a small part of the first one, many more discussions are coming soon, stay tuned!

References
Online courses for Machine learning:

  1. Machine Learning, taught by Andrew Ng
  2. Neural Networks for Machine Learning, taught by Geoffrey Hinton

Implementing Neural Networks in C++

  1. Tutorial Video
  2. Detailed Article with Source code

Teach the kids English (Part 3)

Introduction
I have created a “word with labels” system which allows the kids to learn every single word, instead of learning only patterns. The kids have also been able to respond!

Overfitting models
In the last article, my neural network model seemed to underfit the training data set, with an accuracy of only 77%-79%. It turned out that the model was alright. To improve the algorithm’s performance, all I need was to change Visual Studio’s solution configuration from Debugx86 to Releasex64 then run 20000 iterations of Gradient Descent. Last time, it took the program almost 100 seconds to run 600 iterations, now it takes roughly 10 seconds to run 20000 iterations with over 90% of accuracy.


Sometimes, all you have to do is running more and faster!

Passing 90% is always good thing, but not necessarily good enough. It could be very annoying for the player if the AIs “accidentally” fail to recognize simple patterns like “Good morning” or “Are you hungry?”. So I want to get as close to 100% accuracy as possible. I will largely increase the number of known words / number of training cases ratio and hopefully the algorithms will overfit according to known words. Then all we need is to feed more words and training data. The approach is not that hard to implement as for a single word, we can automatically create many different type of sentences which contain that word. And it works for the fact that we should not expect the kids to understand sentences which contain too many unknown words to them, while they are expected to understand sentences that they have learned before. In short, we’re heading for overfitting models with a lot of data for our neural networks. Also for this reason, I’ve added another hidden layer then changed the neural network’s size from 15-10-6 to 15-12-12-6 to help fit our training set better.

A “Word with Labels” System
To help the kids interpret words and sentences better, I’ve built a system which marks a word with one or more labels.
For example, the word “you” is labeled “listener”, “good” is labeled “adj”, “fish” is labeled “animal” and “food/drink”, etc.
This already helps the kids find the subject and object of simple questions like “What is your name?” and seems to be very helpful in the future.

Wait? If we label words, then shouldn’t a parsing system work too? Many games have succeeded using this approach, right?
We will have to stick to Neural Networks and other Machine Learning techniques to simulate the learning process of the kids. These techniques also allow the kids to learn many different kind of complex sentences and expressions. At the end of the day, both approaches should work if done correctly but I still prefer Machine Learning because it’s simply fun and interesting as hell.

For now, we have 14 labels, which can cover many words already.



enum EnumWordLabel {

	// Can be adjective (good, beautiful,...)
	word_label_adj = 0,
 
	// Can be verb (help, take,...)
	word_label_verb = 1,
 
	// Can be noun (name, age, color,...)
	word_label_noun = 2,
 
	// Can be place (room, house, mountainside,...)
	word_label_place = 3,
 
	// Can be time (morning, afternoon, o'clock,...)
	word_label_time = 4,
 
	// Can be tool (pen, gun, sword,...)
	word_label_tool = 5,
 
	// Can be object (table, machine,...)
	word_label_object = 6,
 
	// Can be human (miner, worker,...)
	word_label_human = 7,
 
	// Can be animal (cat, dog,...)
	word_label_animal = 8,
 
	// Can be plant (tree, flower,...)
	word_label_plant = 9,
 
	// Can be food or drink (cookies, water,...)
	word_label_food_drink = 10,
 
	// Can refer to the listener
	word_label_listener = 11,
 
	// Can refer to the speaker
	word_label_speaker = 12,
 
	// Can be other (what, who,...)
	word_label_other = 13,
};


Since the kids don’t know English at the beginning and only gradually learn it, we still have plenty of time to gather words and label them. And since we split the game into smaller games and chapters, we can still work on the word database after releasing the first few ones.

More Sentence Types
We have added two more types of sentences: greetings and partings.
With “Hello”, “Hey there”, “Good morning”, etc marked as greetings and “Bye bye”, “See you later”, “Goodbye”, etc marked as partings.
The neural net has been working well so far:


Do not worry when you see the ratio of known words over training cases is too high, most known words are not yet used in the training cases. You can also see here that I now use the F1 score to judge the performance of the algorithm, instead of using only recall in the past.

Coming up with Responses
The kids have been able to respond, but only to simple sentences that they can easily interpret. They are not yet aware of the context of the conversation too. I will cover this topic more in-depth in later articles, once the system is highly improved.

Autocorrect the Input Sentence
I’m using Dynamic Programming (Minimum Edit Distance) to autocorrect words from the input sentence the player types in.
I’m currently running through all of the known words and try to match the input words with the ones similar to it in size and characters. For example it will try to match “wat” with “what” or “liek” with “like” but not “watttttttttttttttt” with “what” or “tone” with “come”. The algorithm is very beautiful and have great performance after adding a few if else here and there. It is potentially slow once the number of known words becomes very big though. Any suggestions here are well appreciated!

References

  1. Minimum Edit Distance Dynamic Programming
  2. Dynamic Programming Edit Distance

We’re also very close to finish the second chapter of the Light Novel now. it will be temporarily distributed personally through messages and emails so if you’re interested, please drop a message below!