Giter Site home page Giter Site logo

quizzzy-backend's Introduction

Welcome to quizzzy-backend ๐Ÿ‘‹

License: MIT

This is backend for Quizzzy, Python application which automatically generate MCQ (specially factoid) questions and answers from given context, uses FastAPI to build APIs.

Automatically generating question from context is a trival task till today. This approach uses transformers and other algorithms to generate both question and answers from given context. We can divide the problem (Automatic question & answer generation) into many subproblems.

NOTE: This is applicable only to MCQ question generation.

Workflow is,

  1. Answer generation
  2. Question generation
  3. False answers generation aka Distractors
  • Answer generation

Answer will always lies in given context. So, we just need to extract the answers from the context. To extract answers aka keyword from context, keyBERT is used, which is a powerful and easy-to-use keyword extraction technique. These extracted keywords are the answers for the questions which is going to be generated.

  • Question generation

T5 transformers are used to generate questions when answer and context are given. These transformer were finetuned on SQuAD (reading comprehension QA) and SciQ (Science exam QA) datasets. Training details are in this repo. Those transformers will generate reading comprehensive questions and logical questions.

  • False answers generation

False answers needs to be in same context as correct answer and needs to distract user. sense2vec library and other custom algorithms are used to tackle this problem. But, still, word sense disambiguation is a challenging task, sometimes output won't be desireable. So, Human-In-The-Loop method is used here. Which is, users can modify false answers if generated one is not desireable. This is implemented in frontend.

Prerequisite

  • Docker
  • Firebase Firestore

Usage

Build Docker image by cloning the repo.

$ git clone https://github.com/Karthick47v2/quizzzy-backend.git
$ docker build -t quizzzy/latest .

Run container from image.

$ docker run --name mcq-gen -d -p 8080:8080 quizzzy/latest

Now it will be accessible on http://localhost:8080

Now you can generate questions and answers by sending POST request to http://localhost:8080/get-questions/

Body of POST req should be,

{
    context: <context needed to generate questions and answers>
    uid: <firebase user unique id >
    name: <title for questionnaire>
}
# app designed in a way to automatically send generated ans and question to requested flutter app user's auth id

Run tests

pytest app/tests/

You can also view the code coverage report here

Author

๐Ÿ‘ค Karthick T. Sharma

๐Ÿค Contributing

Contributions, issues and feature requests are welcome!
Feel free to check issues page.

Show your support

Give a โญ๏ธ if this project helped you!

quizzzy-backend's People

Contributors

karthick47v2 avatar snyk-bot avatar trellixvulnteam avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

quizzzy-backend's Issues

tarfile.ReadError: unexpected end of data

Firstly, thank you so much for your repository ๐Ÿ‘

I tried to start docker but got this error. Could you suggest me a solution?

Checking for script in /app/prestart.sh
Running script /app/prestart.sh
Running inside /app/prestart.sh, you could add migrations to this file, e.g.:

#! /usr/bin/env bash

# Let the DB start
sleep 10;
# Run migrations
alembic upgrade head

{"loglevel": "info", "workers": 1, "bind": "0.0.0.0:80", "graceful_timeout": 120, "timeout": 120, "keepalive": 5, "errorlog": "-", "accesslog": "-", "workers_per_core": 1.0, "use_max_workers": 1, "host": "0.0.0.0", "port": "80"}
{"loglevel": "info", "workers": 1, "bind": "0.0.0.0:80", "graceful_timeout": 120, "timeout": 120, "keepalive": 5, "errorlog": "-", "accesslog": "-", "workers_per_core": 1.0, "use_max_workers": 1, "host": "0.0.0.0", "port": "80"}
[2023-11-25 02:05:24 +0000] [1] [INFO] Starting gunicorn 20.1.0
[2023-11-25 02:05:24 +0000] [1] [INFO] Listening at: http://0.0.0.0:80 (1)
[2023-11-25 02:05:24 +0000] [1] [INFO] Using worker: uvicorn.workers.UvicornWorker
[2023-11-25 02:05:24 +0000] [8] [INFO] Booting worker with pid: 8
[nltk_data] Downloading package punkt to /root/nltk_data...
[nltk_data]   Unzipping tokenizers/punkt.zip.
Downloading: 100%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ| 1.18k/1.18k [00:00<00:00, 6.45MB/s]
Downloading: 100%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ| 190/190 [00:00<00:00, 1.46MB/s]
Downloading: 100%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ| 10.6k/10.6k [00:00<00:00, 42.4MB/s]
Downloading: 100%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ| 573/573 [00:00<00:00, 1.94MB/s]
Downloading: 100%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ| 116/116 [00:00<00:00, 930kB/s][2023-11-25 02:07:24 +0000] [1] [CRITICAL] WORKER TIMEOUT (pid:8)
[2023-11-25 02:07:24 +0000] [1] [WARNING] Worker with pid 8 was terminated due to signal 6
[2023-11-25 02:07:24 +0000] [62] [INFO] Booting worker with pid: 62
[nltk_data] Downloading package punkt to /root/nltk_data...
[nltk_data]   Package punkt is already up-to-date!
Downloading: 100%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ| 39.3k/39.3k [00:00<00:00, 164kB/s]
Downloading: 100%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ| 349/349 [00:00<00:00, 2.96MB/s]
Downloading: 100%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ| 134M/134M [00:11<00:00, 11.7MB/s] 
Downloading: 100%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ| 53.0/53.0 [00:00<00:00, 409kB/s]
Downloading: 100%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ| 112/112 [00:00<00:00, 642kB/s]
Downloading: 100%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ| 466k/466k [00:00<00:00, 1.82MB/s]
Downloading: 100%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ| 352/352 [00:00<00:00, 1.96MB/s]
Downloading: 100%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ| 13.2k/13.2k [00:00<00:00, 25.3MB/s]
Downloading: 100%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ| 232k/232k [00:00<00:00, 300kB/s] 
[2023-11-25 02:08:15 +0000] [62] [ERROR] Exception in worker process
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/gunicorn/arbiter.py", line 589, in spawn_worker
    worker.init_process()
  File "/usr/local/lib/python3.8/site-packages/uvicorn/workers.py", line 66, in init_process
    super(UvicornWorker, self).init_process()
  File "/usr/local/lib/python3.8/site-packages/gunicorn/workers/base.py", line 134, in init_process
    self.load_wsgi()
  File "/usr/local/lib/python3.8/site-packages/gunicorn/workers/base.py", line 146, in load_wsgi
    self.wsgi = self.app.wsgi()
  File "/usr/local/lib/python3.8/site-packages/gunicorn/app/base.py", line 67, in wsgi
    self.callable = self.load()
  File "/usr/local/lib/python3.8/site-packages/gunicorn/app/wsgiapp.py", line 58, in load
    return self.load_wsgiapp()
  File "/usr/local/lib/python3.8/site-packages/gunicorn/app/wsgiapp.py", line 48, in load_wsgiapp
    return util.import_app(self.app_uri)
  File "/usr/local/lib/python3.8/site-packages/gunicorn/util.py", line 359, in import_app
    mod = importlib.import_module(module)
  File "/usr/local/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 843, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/app/main.py", line 26, in <module>
    false_ans_gen = FalseAnswerGenerator()
  File "/app/src/ansgenerator/false_answer_generator.py", line 26, in __init__
    self.__init_sense2vec()
  File "/app/src/ansgenerator/false_answer_generator.py", line 65, in __init_sense2vec
    safe_extract(file)
  File "/app/src/ansgenerator/false_answer_generator.py", line 57, in safe_extract
    for member in tar.getmembers():
  File "/usr/local/lib/python3.8/tarfile.py", line 1971, in getmembers
    self._load()        # all members, we first have to
{"loglevel": "info", "workers": 1, "bind": "0.0.0.0:80", "graceful_timeout": 120, "timeout": 120, "keepalive": 5, "errorlog": "-", "accesslog": "-", "workers_per_core": 1.0, "use_max_workers": 1, "host": "0.0.0.0", "port": "80"}
  File "/usr/local/lib/python3.8/tarfile.py", line 2656, in _load
    tarinfo = self.next()
  File "/usr/local/lib/python3.8/tarfile.py", line 2572, in next
    raise ReadError("unexpected end of data")
tarfile.ReadError: unexpected end of data
[2023-11-25 02:08:15 +0000] [62] [INFO] Worker exiting (pid: 62)
[2023-11-25 02:08:15 +0000] [1] [INFO] Shutting down: Master
[2023-11-25 02:08:15 +0000] [1] [INFO] Reason: Worker failed to boot.

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.