Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if a sentence is a question with spacy?

Tags:

python

nlp

spacy

I am using spacy library to build a chat bot. How do I check if a document is a question with a certain confidence? I know how to do relevance, but not sure how to filter statements from questions.

I am looking for something like below:

spacy.load('en_core_web_lg')('Is this a question?').is_question
like image 377
Iliiazbek Akhmedov Avatar asked Oct 15 '22 10:10

Iliiazbek Akhmedov


1 Answers

My first response is to suggest looking for question marks at the end of the sentence.

Otherwise, most questions start with {is, does, do, what, when, where, who, why, what, how}.

There is a more complex answer involving the inclusion of auxiliary verbs and their placement relative to the verb, but if your data is well-formed, this may be sufficient (and fast).

like image 152
Eric McLachlan Avatar answered Oct 21 '22 11:10

Eric McLachlan