Wit.ai and React Native

Introduction

Data is the new oil. We all have heard it from a lot of people, but it is vital to classify and extract useful data from unstructured data. Data Scientists all around the world are working on developing algorithms to do the same thing as it will help a lot of people to solve many real-world problems. In this tutorial, we will discuss one such service provided by Facebook, and that is wit.ai. Before learning more about wit.ai, it is essential to know the term NLP in computer programming.

Understanding NLP

Natural Language Processing (NLP) or Natural Language Understanding (NLU) is a set of AI techniques that deal with the interactions of humans and machines. NLP is useful to extract useful data out of raw input like Text or Speech.

For instance, consider a sentence-

'Book a table at a restaurant for two people next Tuesday at around 5:00 pm'.

As humans, we understand the meaning of the above sentence, but machines cannot. They need very structural information to process the above sentence. Like -

  1. what is the Intent- make a reservation.
  2. How many people- 2
  3. when- DateTime.

It is where NLP comes into the picture. It acts as a mediator between machines and humans. Because of NLP, computers appear to talk to people without actually doing it

What is wit.ai?

Wit.ai is an NLP (natural language processing) interface for applications capable of turning sentences into structured data. And most importantly, it is free!

If you would ask me, then I would say that it is the easiest way to include AI (NLP) in the app. It is so simple that developers don't even require to write a piece of code. It's just about clicking a few buttons on the website, and they can get an API endpoint.

Few Technical terms to know

Utterances

It accepts input to train in the text format. It is what your users can say or type. For instance,

'Provide me a code snippet for the Button.'

Intent

It tells wit.ai the aim of the utterance. It is what you want to do with the text. Wit.ai already provides a lot of built-in intents for developers to use like Location, Date, etc. Apart from the built-in Intents, developers can create their own as well.

Entity

It extracts a meaningful piece of information from the utterance. Wit.ai provides a lot of Recipes that can be used by developers as per their use case. Here, I am using a keyword extraction Entity Recipe.

Tutorial To Create Wit.ai App

In this tutorial, we will create an NLP based HTTP API endpoint using Wit.ai. We will then use this API endpoint in ReactNative tutor to make a code snippet feature.\n\nFollow the steps to create Wit.ai Endpoint -

  • Go to the wit.ai official website and sign in with your Facebook account.

Alt text

  • Click the New App button on the Welcome to Wit.ai page.

Alt text

  • Put ReactNativeTutor as the name of the wit.ai app.

Alt text

  • Click on the Understanding section on the left to provide utterances for your app. It is where we will put what our users will type in our app. In our case, we will put "Give me the code snippet for the Button".

Alt text

  • Now, we will add a custom intent name into the app.

Wit.ai provides a lot of built-in intents for developers to use, but as per our use case, we will create a custom intent "type"

Alt text

After creating the type Intent, highlight the word Button in the utterances. Next, click the button Train and validate to train the app.

  • Now, click the entities section on the left nav. Create a new Entity by clicking the blue entity button. In the entity dropdown, type "snippet_type" in the input. Select the "keywords" option in the lookup strategy section and create the new entity.

Alt text

  • Add keywords navigation, scrollview, image, animation, textview.

Alt text

  • Click on the understanding section from the left nav, and type the sentence containing one of the keywords. It will extract from the sentence.

Alt text

  • Congrats, now you have created a Wit.ai app that extracts keywords from the text.

  • Click on the Settings section on the left nav, and get the URL and Server Access Token to access the Wit.ai app in ReactNativeTutor.