ibm sorting hat You're a wizard, Julia! Ryan Anderson

Computer science can literally be magical.

Ryan Anderson, a solutions architect for IBM Watson, took his work home with him when he decided to make a functional 'Harry Potter' sorting hat for his two daughters: Lucy, 8, and Julia, 6.

"I was thinking of fun projects and, coincidentally, I have a couple daughters and they are mad keen on 'Harry Potter' — they've read the books like 5 times," he told Tech Insider.

The hat works simply enough. You place it on your head (that part is actually for fun, you could just talk to it) and tell the sorting hat a few things about yourself so it can sort you appropriately. Easy!

The sorting hat runs on Watson's Natural Language Classifier, which interprets the intent behind a set of text. So since Anderson coded that 'honesty' is a characteristic of Hufflepuff, the hat will dub you a badger if you describe yourself as honest or use similar words to do so.

Deciding what words associate with a specific house is called "setting a ground truth." You simply put adjectives in one column and the corresponding house in the other. It's so easy to get the hang of that Anderson's daughter Lucy did most of them by herself.

"I started with five or six rows and Lucy looked over my shoulder and said she wanted to try and she created 150 lines," Anderson said.

IBM sorting hatRyan Anderson

But running on the Natural Language Classifier language alone would have forced users to describe themselves over written text. And we all know that's not how the real sorting hat works! So Anderson also used Watson's Speech to Text feature so you can speak to the hat.

The sorting hat also uses deep learning, a branch of AI when machines learn to complete tasks on their own, to expand the number of ground truths. It essentially gets the gist of what qualities fit a house like Hufflepuff and will add more characteristics on its own to Lucy's list of 150 ground truths.

Anderson said the hat learns overtime from scanning the web, and that he (or even Lucy!) can go in and correct a ground truth if the hat gets it wrong.

Once Anderson and his daughters had the software down for the hat, they decided to have some more fun with its actual design. Anderson attended a Hackathon where his team helped add animatronics to the hat. Now if you're dubbed a Slytherin, its eyebrows will furrow. For Gryffindor, the hat's eyes turn green (though I personally think that makes more sense for Slytherin, but they were going for green is good.)

As for what's next for the sorting hat?

"I may, time permitting, for next Halloween give it more personality and make it more dynamic," Anderson said. 

Here's Anderson's GitHub if you want to try making your own! Watch the hat sort: