Semantic Experiences

Semantic Reactor

Experiment with machine learning language models

Install Add-on

Introducing the Semantic Reactor

Natural Language Understanding (NLU) makes it possible to communicate with our digital devices with everyday words, phrases and sentences. It can be used to make customer service bots, digital virtual assistants, search engines, games, game characters, and lots of things we haven’t thought of yet.

However, there is a perception that building an application with NLU is costly, complex, and time-consuming. It doesn’t have to be!

To show how easy it can be to use NLU, we’ve created a tool called the Semantic Reactor that uses pre-trained language models, offers different ranking methods, and has a few advanced features.

It’s a Google Sheets Add-on and easy to install and use. You can grab it from the G Suite Marketplace.

Semantic Reactor in Google Sheets

How to use the Semantic Reactor

The Semantic Reactor lets you sort lines of text in a Google Sheet using a variety of machine-learning models. The models offer ranking methods that determine how the list will be sorted.

With the semantic similarity method, the lines more similar to the input will be ranked higher.

With the input-response method, the lines that are the most appropriate conversational responses are ranked higher.

To use, open a new sheet and write the lines you would like the model to sort in Column A. Row 1 is assumed to be a header and will be ignored by the tool.

The optional Column B can be used to carry metadata (like responses to questions) alongside the lines you are sorting. This metadata has no influence on the result of the sort.

Remember to press the “Reload” button anytime you’d like changes in your sheet to be considered by the Semantic Reactor.

Experiment with different combinations of models and ranking methods to see which work best for your use case!

Why use the Semantic Reactor?

There are a lot of interesting things you can do with the Semantic Reactor, but let’s look at two:

  1. Writing dialogue for a game character, using semantic similarity.
  2. Searching within a big hunk of text, like from a message board. For that, we will use input-response.

Writing Dialogue for a Game Character Using Semantic Similarity

So, just as an example, let’s say you are writing dialogue for a guard standing in front of the castle gate in a fantasy RPG. He doesn’t have much to say as he isn’t a major character. However, it would be good if he could answer player questions about the town, some of the key characters, and maybe drop some clues to a developing plot.

Because you know your game, you can likely guess some of the questions a player might have for that guard. However, you won’t be able to guess all the different ways players will ask those questions. For instance, “Where is the king?” might be expressed as “Is the king home?” or “Is the king in residence?” or “King here?”

What the Semantic ML will do is examine what the player asked and then look at your list of anticipated questions, then rank those questions by what it thinks is the most similar to what the player asked.

If a player asks “Is the king home?” then the model will semantically match to “Where is the king?” and deliver the correct answers to the player. (It turns out, the king is not at home.)

Let’s give it a try...

Here is a sample with five Q-A pairs to get you started. Open that doc and do these steps (You’ll need to have the Semantic Ranker Sheets Add-on installed to do these exercises):

  1. Make a copy of that sheet, so you have a version you can edit and add to.
  2. In your new sheet, open the Semantic Reactor Add-On from the Add-Ons menu.
    addon opening
  3. Within Rank Method, select Semantic Similarity.
    addon opening
  4. Ask it: “Is the King home?” Notice that it returns the closest semantic match, which is “Where is the king?” Players can ask that question with a variety of different wordings and will often get the correctly anticipated response.
    Where is the king?

Try this query: “Where is the bar?” It returns: ”Where is the tavern?” with the answer concerning directions to the tavern, which is what you want the player to have. Also try: “Where can a king get a drink around here?” and “Does this town have a tavern?” They all semantically match the response you want to give.

It is true that players could ask a question in such a way that the model won’t return the answer you want it to. When that happens, you could add a new question-answer pair to match the wording the player used, or you might be satisfied with the guard giving imperfect answers.

Now add in your own question-answer pairs to your NPC sheet. Fill up your guard’s head with the answers to questions you think players might ask. Then, through the Semantic Reactor, ask those questions with different phrasings that have the same meaning.

Note: be sure to hit the “Reload” button after you add new responses to have them considered in the sort.

If you are a coder and want to see how this technique works within a game, check out Mystery of the Three Bots on GitHub. It’s an open sourced bit of sample code that shows how you can use a small semantic ML model to drive conversations with game characters.

You can experiment with the corpora of two of the characters, the Maid and the Butler, contained within this Sheet.

Mystery of the Three Bots

Searching Through Text Using Input-Response

Sometimes you can’t anticipate what users are going to ask, and sometimes you might be dealing with a lot of potential responses, maybe thousands. In cases like that, you should use the input-response ranking method. That means the model will examine the list of potential responses and then rank each one according to what it thinks is the most likely response.

Here is a sheet containing a list of simple conversational responses. Do the following:

  1. Make a copy of that sheet, so you have a version you can edit and add to.
  2. In your new sheet, open the Semantic Reactor Add-On from the Add-Ons menu.
    addon opening
  3. Within Rank Method, select Input / Response.
    input / response
  4. Say to it: “Hello.” Notice that it has guessed that the most appropriate response is “Nice to meet you.” (If you select the Semantic Similarity rank method, notice that you get a very different response.)
    Nice to meet you
  5. Try a few conversational inputs. You could try: “Let’s go to the movies” or “Want to go to dinner?”

Now try your own! Add potential responses. See what inputs result in your new responses being ranked at the top.

Other Experiments To Try

Open a fresh sheet then try these experiments with the Semantic Reactor:

The Rule Reranker

The Rule Reranker is an advanced feature of the Semantic Reactor that allows you to tweak the default behavior of the models by applying a set of rules. Learn more about this advanced feature in the Rule Reranker Instructions.

Game Making

If you’re interested in making games that take advantage of Semantic ML, you should take a look at Semantris, which uses the same technology to detect word associations. You can experiment with the words it uses in the Semantic Reactor.

You might also be interested in the open sourced code for Mystery of the Three Bots, a simple game where a player solves a mystery by asking questions of the three AI-powered bots (see above).

If you are a game developer, and want more access to ML-powered tech, along with one of the most powerful gaming platforms ever created, you should visit Stadia.dev.

Where To Get The Models Used Within The Semantic Reactor

All of the models used in the Semantic Reactor are published and available online.

Final Thoughts

These language models are far from perfect. They use their training to give a best estimate on what to return based on the list of responses you gave it. Machine learning is about calculation, prediction and training. Models can be improved over time with more data and tuning, and, in turn, can be made more accurate.

Also, because conversational models are trained on dialogue between people, and because people are biased, the models will display biases that exist in the data that they were trained on, sometimes in ways you can’t predict. For more on model bias, and more detail about how these models were trained, see the Semantic Experiences for Developers page.

We hope you have fun experimenting with the Semantic Reactor! If you’re interested in machine learning and AI, keep your eye on the Google AI Blog, which is updated frequently with fascinating new developments.

If you have any questions about the Semantic Reactor or the models used within it, please feel free to email us with any of your questions.