• Stars
    star
    396
  • Rank 108,135 (Top 3 %)
  • Language
    Python
  • License
    GNU Affero Genera...
  • Created about 5 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

SQuAD Question Answering Using BERT, PyTorch

BERT-SQuAD

Use google BERT to do SQuAD !

What is SQuAD?

Stanford Question Answering Dataset (SQuAD) is a reading comprehension dataset, consisting of questions posed by crowdworkers on a set of Wikipedia articles, where the answer to every question is a segment of text, or span, from the corresponding reading passage, or the question might be unanswerable.

Requirements

  • python3
  • pip3 install -r requirements.txt

Result

model : bert-large-uncased-whole-word-masking

{"exact_match": 86.91579943235573, "f1": 93.1532499015869}

Pretrained model download from here

unzip and move files to model directory

Inference

from bert import QA

model = QA('model')

doc = "Victoria has a written constitution enacted in 1975, but based on the 1855 colonial constitution, passed by the United Kingdom Parliament as the Victoria Constitution Act 1855, which establishes the Parliament as the state's law-making body for matters coming under state responsibility. The Victorian Constitution can be amended by the Parliament of Victoria, except for certain 'entrenched' provisions that require either an absolute majority in both houses, a three-fifths majority in both houses, or the approval of the Victorian people in a referendum, depending on the provision."

q = 'When did Victoria enact its constitution?'

answer = model.predict(doc,q)

print(answer['answer'])
# 1975
print(answer.keys())
# dict_keys(['answer', 'start', 'end', 'confidence', 'document']))

model.predict(doc,q) return dict

{
"answer" : "answer text",
"start" : "start index",
"end" : "end index",
"confiednce" : "confidence of answer",
"document" : "tokenzied document , list"
}

Deploy REST-API

BERT QA model deployed as rest api

python api.py

API will be live at 0.0.0.0:8000 endpoint predict

cURL request

curl -X POST http://0.0.0.0:8000/predict -H 'Content-Type: application/json' -d '{ "document": "Victoria has a written constitution enacted in 1975, but based on the 1855 colonial constitution, passed by the United Kingdom Parliament as the Victoria Constitution Act 1855, which establishes the Parliament as the states law-making body for matters coming under state responsibility. The Victorian Constitution can be amended by the Parliament of Victoria, except for certain 'entrenched' provisions that require either an absolute majority in both houses, a three-fifths majority in both houses, or the approval of the Victorian people in a referendum, depending on the provision.","question":"When did Victoria enact its constitution?" }'

Output

{
    "result": {
        "answer": "1975",
        "confidence": 0.940746070672879,
        "document": [
            "Victoria",
            "has",
            "a",
            "written",
            "constitution",
            "enacted",
            "in",
            "1975,",
            "but",
            "based",
            "on",
            "the",
            "1855",
            "colonial",
            "constitution,",
            "passed",
            "by",
            "the",
            "United",
            "Kingdom",
            "Parliament",
            "as",
            "the",
            "Victoria",
            "Constitution",
            "Act",
            "1855,",
            "which",
            "establishes",
            "the",
            "Parliament",
            "as",
            "the",
            "states",
            "law-making",
            "body",
            "for",
            "matters",
            "coming",
            "under",
            "state",
            "responsibility.",
            "The",
            "Victorian",
            "Constitution",
            "can",
            "be",
            "amended",
            "by",
            "the",
            "Parliament",
            "of",
            "Victoria,",
            "except",
            "for",
            "certain",
            "entrenched",
            "provisions",
            "that",
            "require",
            "either",
            "an",
            "absolute",
            "majority",
            "in",
            "both",
            "houses,",
            "a",
            "three-fifths",
            "majority",
            "in",
            "both",
            "houses,",
            "or",
            "the",
            "approval",
            "of",
            "the",
            "Victorian",
            "people",
            "in",
            "a",
            "referendum,",
            "depending",
            "on",
            "the",
            "provision."
        ],
        "end": 7,
        "start": 7
    }
}

Postman

postman output image

More Repositories

1

BERT-NER

Pytorch-Named-Entity-Recognition-with-BERT
Python
1,199
star
2

Named-Entity-Recognition-with-Bidirectional-LSTM-CNNs

Named-Entity-Recognition-with-Bidirectional-LSTM-CNNs
Python
357
star
3

BERT-NER-TF

Named Entity Recognition with BERT using TensorFlow 2.0
Python
213
star
4

ALBERT-TF2.0

ALBERT model Pretraining and Fine Tuning using TF2.0
Python
199
star
5

stable-diffusion-tritonserver

Deploy stable diffusion model with onnx/tenorrt + tritonserver
Jupyter Notebook
119
star
6

Vision-Transformer

Vision Transformer using TensorFlow 2.0
Python
95
star
7

DATA-SCIENCE-BOWL-2018

DATA-SCIENCE-BOWL-2018 Find the nuclei in divergent images to advance medical discovery
Jupyter Notebook
90
star
8

e5-mistral-7b-instruct

Finetune mistral-7b-instruct for sentence embeddings
Python
65
star
9

minGPT-TF

A minimal TF2 re-implementation of the OpenAI GPT training
Jupyter Notebook
55
star
10

BioELECTRA

BioELECTRA
51
star
11

Swin-Transformer-Serve

Deploy Swin Transformer using TorchServe
Python
26
star
12

TAPAS-TF2

End-to-end neural table-text understanding models.
Python
8
star
13

Malayalam-News-Classifier

Python
7
star
14

BioGPT-HF

Jupyter Notebook
5
star
15

Tapas-Tutorial

Jupyter Notebook
3
star
16

Summarizer

Python
2
star
17

pytorch-tutorial

Jupyter Notebook
2
star
18

Redis-Stack-Bitnami-Helm-Chart

Redis Stack Server Helm Chart
Mustache
1
star
19

librispeech_100_jax

Python
1
star
20

Tensorflow-Paper-Implementation

Python
1
star
21

BioNLP-Corpus

Python
1
star
22

dlrm-jax

Python
1
star
23

S4-Standalone

Python
1
star
24

Multilingual-Complex-Named-Entity-Recognition

Python
1
star
25

git-actions-python

Python
1
star
26

NLI4CT

Jupyter Notebook
1
star
27

BioSimCSE

1
star