class MachineComprehend:
    def __init__(self):
        self.model = Demo()

    def answer_question(self, paragraph, question):
        pq_prepro = prepro(paragraph, question)
        answer = self.model.run(pq_prepro)
        if len(answer) == 0:
            return None
        return answer
Exemple #2
0
class BidafBot:
    def __init__(self):
        self.paragraph = None
        self.question = None
        self.demo = Demo()

    def getAnswer(self, paragraph, question):

        pq_prepro = prepro(paragraph, question)
        if len(pq_prepro['x']) > 1000:
            return "[Error] Sorry, the number of words in paragraph cannot be more than 1000."
        if len(pq_prepro['q']) > 100:
            return "[Error] Sorry, the number of words in question cannot be more than 100."
        return self.demo.run(pq_prepro)

    def respond(self, query):
        if query.startswith("@context"):
            self.paragraph = query.split("@context")[1]
            answer = "Context received. Shoot your questions"
        else:
            self.question = query
            answer = self.getAnswer(self.paragraph, self.question)
        return answer
Exemple #3
0
from flask import Flask, render_template, redirect, request, jsonify
from squad.demo_prepro import prepro
from basic.demo_cli import Demo
import json

app = Flask(__name__)
shared = json.load(open("data/squad/shared_test.json", "r"))
contextss = [""]
context_questions = [""]
for i in range(len(shared['contextss'])):
    j = 1 if i==0 else 0
    contextss.append(shared["contextss"][i][j])
    context_questions.append(shared['context_questions'][i][j])
titles = ["Write own paragraph"]+shared["titles"]

demo = Demo()

def getTitle(ai):
    return titles[ai]

def getPara(rxi):
    return contextss[rxi[0]][rxi[1]]

def getAnswer(paragraph, question):
    pq_prepro = prepro(paragraph, question)
    if len(pq_prepro['x'])>1000:
        return "[Error] Sorry, the number of words in paragraph cannot be more than 1000." 
    if len(pq_prepro['q'])>100:
        return "[Error] Sorry, the number of words in question cannot be more than 100."
    return demo.run(pq_prepro)
 def __init__(self):
     self.model = Demo()
Exemple #5
0
 def __init__(self):
     self.paragraph = None
     self.question = None
     self.demo = Demo()