Giter Club home page Giter Club logo

little_questions's Introduction

Little Questions

Classify and Parse questions

A decent question answering system needs to know what users are talking about

Install

pip install little_questions

Usage

So what is a question? A question is a sentence, but a sentence might not be a question

To understand if a sentence is a question we want to:

  • classify it as question, command or statement
  • extract the entities the sentence is about
  • decompose it in individual actions
  • classify the question according to answer type
  • classify the question according to action type

Questions

Questions can have two patterns. Some can have ‘yes’ or ‘no’ as an answer.

Do you like Paris?,
Can you speak Russian?
Will you marry me?

Alternatively, they have a pattern that asks an ‘open’ question which can have any number of answers

What did you have for breakfast?
Which newspaper do you read?
Who is your favourite actor?

In addition to the sub-steps and tagged entities, if we do indeed have a question we want to classify it, a classifier will let us know what the answer is about

from little_questions import Question, Sentence

text = "who made you"
question = Sentence(text)

assert question.is_question
assert isinstance(question, Question)
assert question.pretty_label == "individual (Human)"
assert question.main_label == "HUM"
assert question.secondary_label == "ind"

text = "when will the world end"
question = Question(text)
assert question.pretty_label == "date (Numeric)"

text = "how fast can an elephant run"
question = Question(text)
assert question.pretty_label == "speed (Numeric)"

text = "why are fire trucks red"
question = Question(text)
assert question.pretty_label == "reason (Description)"

Sentences

Sentences might not be questions, in this case we probably want to send them to an intent parsing step in our pipeline and take an action

from little_questions import Sentence

text = "I want you to buy bitcoin"

sentence = Sentence(text)

assert not sentence.is_question

Statements

Sentences might also be statements that don't expect any action and only convey information

A statement is defined as having a structure in which there is typically a Subject, followed by a verb and then a further unit such as a Direct Object.

Jimmy loves his dog,
The government will make an announcement at noon,
She reads two newspapers every day
from little_questions import Sentence, Statement

text = "I like Mycroft"

sentence = Sentence(text)

assert not sentence.is_question
assert not sentence.is_command
assert sentence.is_statement
assert isinstance(sentence, Statement)

Exclamations

Exclamations grammatically have a structure that involves the words what a or how,

What a nice person you are!
What a beautiful painting!,
How clever you are!,
How wonderful that is!

Notice that the Subject goes before the verb in How clever you are! If this were a question we would have How clever are you?

from little_questions import Sentence, Exclamation

text = "How clever you are!"
sentence = Sentence(text)

assert not sentence.is_question
assert not sentence.is_command
assert not sentence.is_statement
assert not sentence.is_request
assert sentence.is_exclamation
assert isinstance(sentence, Exclamation)

Commands

Most likely you only care about questions vs commands classification

Commands also have a special structure in that they typically lack a Subject.

Eat your dinner
Be quiet
Open the pod bay doors

Not all imperative sentences are orders or commands. They can be social expressions.

Have a nice day.
Get well soon.
Help yourselves to coffee.
from little_questions import Sentence, Command

text = "Do your homework"
sentence = Sentence(text)

assert not sentence.is_question
assert sentence.is_command
assert not sentence.is_statement
assert not sentence.is_request
assert not sentence.is_exclamation
assert isinstance(sentence, Command)

Requests

We can make a request, which is a type of command, sound more polite by using the interrogative.

Would you feed the dog, please.
Would you mind shutting the door.
Could I have that now, thank you.
from little_questions import Sentence, Command, Request

text = "Could you pass me the salt please?"
sentence = Sentence(text)

assert isinstance(sentence, Command)
assert isinstance(sentence, Request)
assert not sentence.is_question
assert sentence.is_command
assert not sentence.is_statement
assert sentence.is_request
assert not sentence.is_exclamation

little_questions's People

Contributors

jarbasal avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

little_questions's Issues

installation issues

Hello.

I was trying to install your package (which looks very interesting!) but I run into problems with swig2.0 installation both on ubuntu and macos.

On macosx, this is the error

>> pip install little_questions

[...]
Building wheels for collected packages: fann2
  Building wheel for fann2 (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: /usr/local/Caskroom/miniconda/base/envs/py37/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/t4/f39wd1sd25x8ry2hq74xhz1r0000gn/T/pip-install-uhkh9goa/fann2/setup.py'"'"'; __file__='"'"'/private/var/folders/t4/f39wd1sd25x8ry2hq74xhz1r0000gn/T/pip-install-uhkh9goa/fann2/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /private/var/folders/t4/f39wd1sd25x8ry2hq74xhz1r0000gn/T/pip-wheel-92m343vm --python-tag cp37
       cwd: /private/var/folders/t4/f39wd1sd25x8ry2hq74xhz1r0000gn/T/pip-install-uhkh9goa/fann2/
  Complete output (30 lines):
  running swig
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.macosx-10.7-x86_64-3.7
  creating build/lib.macosx-10.7-x86_64-3.7/fann2
  copying fann2/__init__.py -> build/lib.macosx-10.7-x86_64-3.7/fann2
  copying fann2/libfann.py -> build/lib.macosx-10.7-x86_64-3.7/fann2
  running egg_info
  writing fann2.egg-info/PKG-INFO
  writing dependency_links to fann2.egg-info/dependency_links.txt
  writing top-level names to fann2.egg-info/top_level.txt
  reading manifest file 'fann2.egg-info/SOURCES.txt'
  reading manifest template 'MANIFEST.in'
  writing manifest file 'fann2.egg-info/SOURCES.txt'
  copying fann2/fann2.i -> build/lib.macosx-10.7-x86_64-3.7/fann2
  copying fann2/fann2_wrap.cxx -> build/lib.macosx-10.7-x86_64-3.7/fann2
  copying fann2/fann_cpp_subclass.h -> build/lib.macosx-10.7-x86_64-3.7/fann2
  running build_ext
  building 'fann2._libfann' extension
  creating build/temp.macosx-10.7-x86_64-3.7
  creating build/temp.macosx-10.7-x86_64-3.7/fann2
  gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/usr/local/Caskroom/miniconda/base/envs/py37/include -arch x86_64 -I/usr/local/Caskroom/miniconda/base/envs/py37/include -arch x86_64 -DSWIG_COMPILE -I./include -I../include -Iinclude -I/usr/local/Caskroom/miniconda/base/envs/py37/include/python3.7m -c fann2/fann2_wrap.cxx -o build/temp.macosx-10.7-x86_64-3.7/fann2/fann2_wrap.o
  warning: include path for stdlibc++ headers not found; pass '-stdlib=libc++' on the command line to use the libc++ standard library instead [-Wstdlibcxx-not-found]
  fann2/fann2_wrap.cxx:2715:10: fatal error: 'stdexcept' file not found
  #include <stdexcept>
           ^~~~~~~~~~~
  1 warning and 1 error generated.
  error: command 'gcc' failed with exit status 1
  ----------------------------------------
  ERROR: Failed building wheel for fann2
  Running setup.py clean for fann2
Failed to build fann2
ERROR: rasa 1.7.2 has requirement python-dateutil~=2.8, but you'll have python-dateutil 2.6.0 which is incompatible.
ERROR: pandas 0.25.1 has requirement python-dateutil>=2.6.1, but you'll have python-dateutil 2.6.0 which is incompatible.
ERROR: gobbli 0.0.7 has requirement scikit-learn>=0.21.0, but you'll have scikit-learn 0.20.4 which is incompatible.
Installing collected packages: fann2, xxhash, padatious, python-dateutil, lingua-franca, inflect, num2words, quantulum3, pyspotlight, simple-NER, text-classifikation, little-questions
    Running setup.py install for fann2 ... error
    ERROR: Command errored out with exit status 1:
     command: /usr/local/Caskroom/miniconda/base/envs/py37/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/t4/f39wd1sd25x8ry2hq74xhz1r0000gn/T/pip-install-uhkh9goa/fann2/setup.py'"'"'; __file__='"'"'/private/var/folders/t4/f39wd1sd25x8ry2hq74xhz1r0000gn/T/pip-install-uhkh9goa/fann2/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/t4/f39wd1sd25x8ry2hq74xhz1r0000gn/T/pip-record-5j9n1fr7/install-record.txt --single-version-externally-managed --compile
         cwd: /private/var/folders/t4/f39wd1sd25x8ry2hq74xhz1r0000gn/T/pip-install-uhkh9goa/fann2/
    Complete output (30 lines):
    running swig
    running install
    running build
    running build_py
    creating build
    creating build/lib.macosx-10.7-x86_64-3.7
    creating build/lib.macosx-10.7-x86_64-3.7/fann2
    copying fann2/__init__.py -> build/lib.macosx-10.7-x86_64-3.7/fann2
    copying fann2/libfann.py -> build/lib.macosx-10.7-x86_64-3.7/fann2
    running egg_info
    writing fann2.egg-info/PKG-INFO
    writing dependency_links to fann2.egg-info/dependency_links.txt
    writing top-level names to fann2.egg-info/top_level.txt
    reading manifest file 'fann2.egg-info/SOURCES.txt'
    reading manifest template 'MANIFEST.in'
    writing manifest file 'fann2.egg-info/SOURCES.txt'
    copying fann2/fann2.i -> build/lib.macosx-10.7-x86_64-3.7/fann2
    copying fann2/fann2_wrap.cxx -> build/lib.macosx-10.7-x86_64-3.7/fann2
    copying fann2/fann_cpp_subclass.h -> build/lib.macosx-10.7-x86_64-3.7/fann2
    running build_ext
    building 'fann2._libfann' extension
    creating build/temp.macosx-10.7-x86_64-3.7
    creating build/temp.macosx-10.7-x86_64-3.7/fann2
    gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/usr/local/Caskroom/miniconda/base/envs/py37/include -arch x86_64 -I/usr/local/Caskroom/miniconda/base/envs/py37/include -arch x86_64 -DSWIG_COMPILE -I./include -I../include -Iinclude -I/usr/local/Caskroom/miniconda/base/envs/py37/include/python3.7m -c fann2/fann2_wrap.cxx -o build/temp.macosx-10.7-x86_64-3.7/fann2/fann2_wrap.o
    warning: include path for stdlibc++ headers not found; pass '-stdlib=libc++' on the command line to use the libc++ standard library instead [-Wstdlibcxx-not-found]
    fann2/fann2_wrap.cxx:2715:10: fatal error: 'stdexcept' file not found
    #include <stdexcept>
             ^~~~~~~~~~~
    1 warning and 1 error generated.
    error: command 'gcc' failed with exit status 1
    ----------------------------------------
ERROR: Command errored out with exit status 1: /usr/local/Caskroom/miniconda/base/envs/py37/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/t4/f39wd1sd25x8ry2hq74xhz1r0000gn/T/pip-install-uhkh9goa/fann2/setup.py'"'"'; __file__='"'"'/private/var/folders/t4/f39wd1sd25x8ry2hq74xhz1r0000gn/T/pip-install-uhkh9goa/fann2/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/t4/f39wd1sd25x8ry2hq74xhz1r0000gn/T/pip-record-5j9n1fr7/install-record.txt --single-version-externally-managed --compile Check the logs for full command output.

It looks like on macosx I have swig4.0.1

(py37) Jeeg:my_codes acortis$ brew install swig
Warning: swig 4.0.1 is already installed and up-to-date
To reinstall 4.0.1, run `brew reinstall swig`

Any suggestions?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.