Message Boards Message Boards

A basic NLP application with Classify

Posted 8 years ago

There is an enormous interest in developing NLP models into today's applications. I have decided to take a stab at what making a very general application to track:

  • What people are talking about
  • How they feel about what they are talking about

The first thing I need to do is capture a statement you want to analyze. I can build a simple front end utility to do this conveniently using InputField[]. This will take in a string input and dynamically update an object called "statement" in the kernel to what ever it is you type. I went ahead and styled it a bit. I even rigged it up to take in my voice via an external transcription an application and fill in the text box for me as I am talking. Check out the video at the end of this blog to see me demonstrate that.

inputField = InputField[Dynamic[statement], String, FieldSize -> {20, 7}, Background -> GrayLevel[0.85]]

enter image description here

The next thing Iwill want to do is determine different properties of interest about our statement. To this end we can employ two separate prebuilt classification functions "FacebookTopic" (What people are talking about ) and "Sentiment" ( How they feel about what they are talking about).

In this first function I will take in an string object statement and it will deduce the topic of the statement and return various information about the different statistical probabilities of the results.

 topic = Classify["FacebookTopic", {ToString[statement]}];

In the second function we will deduce the overall sentiment of the statement.

sentiment = Classify["Sentiment", {ToString[statement]}];

I need to wrap all this stuff together into a nice GUI that allows me to give the kernel statements - and get back the desired information at the click of a button. The button creates the topic and sentiment objects from the statement and stores them in a new object - response - which is a string combination to make it nice in the front end.

NLPButton =
 Button["Analyze Statement",
  topic = Classify["FacebookTopic", {ToString[statement]}];
  sentiment = Classify["Sentiment", {ToString[statement]}];
  response = "You made a " <> sentiment <>;
  ]

enter image description here

Now I can test it with the statement bellow with a new object which contains the precursor functionality wrapped in a front-end friendly environment.

ToolKit = Column[{
   inputField,
   NLPButton,
   Spacer[1],
   Dynamic[response]
   }, Alignment -> Center]

enter image description here

There are lots of creative ways to apply these types of quantitative descriptions of our results but I will leave this here as a simple exposition of the idea. I am working on a chat-bot like project and if you have any other cool ideas let me know.

Sentiment and Topical Analysis using Mathematica 10

enter image description here

POSTED BY: William Duhe
3 Replies

Nice! Did I understand correctly that in the video you had a feed between Mathematica and Dragon Speech Recognition Software? If yes, how did you do that?

POSTED BY: Sam Carrettie
Posted 8 years ago

There are some options in the settings of the Nuance software that allow you to set unsupported external applications as the program to accept the "Dictation Box" of Dragon. Check this piece of documentation:

http://www.nuance.com/products/help/dragon/dragon-for-pc/enx/professionalgroup/main/Content/Dictation/using_the_dictation_box.htm

Basically - I just hacked it to work with a dynamic front end text box that dynamically accepts what I say as I talk - checks for a minimum number of letters and then makes the analysis using a RunScheduledTask[] like bellow:.

RunScheduledTask[
 statementLength = StringLength@statement;
 If[statementLength > 15,
  resultsProbabilities = 
   Classify["Sentiment", {ToString[stuff]}, "Probabilities"];
  topic = Classify["FacebookTopic", {ToStringstatement]}];
  sentiment= Classify["Sentiment", {ToString[statement]}];
  lastStatement = statement;
  stuff = "";
  ]
 , 2]
POSTED BY: William Duhe

enter image description here - another post of yours has been selected for the Staff Picks group, congratulations !

We are happy to see you at the tops of the "Featured Contributor" board. Thank you for your wonderful contributions, and please keep them coming!

POSTED BY: Moderation Team
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract