# Intent Classification in Question Answering

I am trying to write a question answer intent classification program.

My task is given a set of unlabelled question and answers, I have to write a program where I may group all the similar questions and identify their answers.

Once the answers for a group of similar questions are done, I have to identify the intent or focus of answers.

For example, if I have a set of questions like:

a) Q: where is Texas? A : It is in USA.
b) Q: where is California? A: It is in USA.
c) Q: where is NASA? A: It is in USA.
d) Q: who is Queen Elizabeth II? A: Queen of England.
e) Q: who is Donald Trump? A : President of USA.


Thus, I am trying to group questions a, b & c as Location oriented question, and d & e as Official/Person oriented question.

To solve this problem,

I am trying to use a standard classifier, and as it identifies 'It is in USA' as the class, I am trying to tag it tag it as "It/NA is/NA in/NA USA/LOC" to identify intent/focus of answer as Location.

I am using a standard classifier like Naive Bayes and a standard Hidden Markov Model based tagger.

The result is more or less fine. I am using two training set one for classifier and the other for tagging.

If any one of the esteemed scientists may kindly suggest how I am trying to solve the problem?

Here, Q means question, A means answer.

Apology for cross-posting

I don't know about the granularity of the intents. If they are just Person/Loc/Official, why not use question words(where,who,what etc.) to identify the intent? For example, "where" corresponds to "Loc", "Who" corresponds to "Person" etc. You can also use this as a feature in you classifier. Hope it helps!!

you can use named entity recognition from python nltk. for identifying whether you question has - person or organisation or place.

from nltk import word_tokenize, pos_tag, ne_chunk

Q1 = "where is Texas ?"
A1 = "It is in USA."
Q2 = "where is California?"
A2 = "It is in USA"
Q3 = "where is NASA?"
A3 = "It is in USA."
Q4 = "who is Queen Elizabeth II?"
A4 = "Queen of England"
Q5 = "who is Donald Trump?"
A5 = "President of USA."

print(ne_chunk(pos_tag(word_tokenize(Q1))))
print(ne_chunk(pos_tag(word_tokenize(Q2))))
print(ne_chunk(pos_tag(word_tokenize(Q3))))
print(ne_chunk(pos_tag(word_tokenize(Q4))))
print(ne_chunk(pos_tag(word_tokenize(Q5))))


code output below

(S where/WRB is/VBZ (PERSON Texas/NNP) ?/.)
(S where/WRB is/VBZ (GPE California/NNP) ?/.)
(S where/WRB is/VBZ (ORGANIZATION NASA/NNP) ?/.)
(S who/WP is/VBZ (PERSON Queen/NNP Elizabeth/NNP II/NNP) ?/.)
(S who/WP is/VBZ (PERSON Donald/NNP Trump/NNP) ?/.)

you can group output based on person or organisation or location. Also note Texas is shown as person here, so all answers will not be correct. But should be a good start.

You can use Spacy's named entity recognition. Since I feels it is good in accuracy as well as multi-processing approach is also possible.

https://spacy.io/usage/linguistic-features#named-entities

import spacy
from statistics import mode

Q1 = "where is Texas ?"
Q2 = "where is California?"
Q3 = "where is NASA?"
Q4 = "who is Queen Elizabeth II?"
Q5 = "who is Donald Trump?"

for i in range(1,6):
doc= nlp(eval("Q"+str(i)))
print("Class :",mode([ent.label_ for ent in doc.ents]))


OutPut:

Class : GPE
Class : GPE
Class : ORG
Class : PERSON
Class : PERSON


Hope it will help to start !