Exemplo n.º 1
0
def load_weights():
    pretrained_path = 'BioBertFolder/biobert_v1.0_pubmed_pmc/'
    # ffn_weight_file = None
    bert_ffn_weight_file = 'newFolder/models/bertffn_crossentropy/bertffn'
    embedding_file = 'Float16EmbeddingsExpanded5-27-19.pkl'

    doc = RetreiveQADoc(pretrained_path=pretrained_path,
                        ffn_weight_file=None,
                        bert_ffn_weight_file=bert_ffn_weight_file,
                        embedding_file=embedding_file)

    var = 'yes'
    while (var == 'yes'):
        inp = input("How are you feeling today?: ")

        print(doc.predict(inp, search_by='answer', topk=1, answer_only=True))
        var = input("Do you want more assistance?")
Exemplo n.º 2
0
def get_prediction(query):
    '''
    Will return the analysed things after predicting from the query
    '''
    PRETRAINED_PATH = os.path.join(os.path.expanduser("~"), "data", "BioBert", "biobert_v1.0_pubmed_pmc")
    BERT_FFN_WEIGHT_FILE = os.path.join(os.path.expanduser("~"), "data", "newFolder", "models", "bertffn_crossentropy", "bertffn")
    EMBEDDING_FILE = os.path.join(os.path.expanduser("~"), "data", "Float16EmbeddingsExpanded5-27-19.pkl")

    DOCTOR = RetreiveQADoc(
        pretrained_path=PRETRAINED_PATH,
        ffn_weight_file=None,
        bert_ffn_weight_file=BERT_FFN_WEIGHT_FILE,
        embedding_file=EMBEDDING_FILE
    )


    return DOCTOR.predict(
        query,
        search_by="answer",
        topk=1,
        answer_only=True)
Exemplo n.º 3
0
class QAModel:
    def __init__(self, biobert_path: str, bert_fnn_weights: str,
                 embedding_file: str):
        self._qa_model = RetreiveQADoc(pretrained_path=biobert_path,
                                       ffn_weight_file=None,
                                       bert_ffn_weight_file=bert_fnn_weights,
                                       embedding_file=embedding_file)

    def predict(self,
                question_text,
                search_by: str = 'answer',
                results_num: int = 1,
                answer_only: bool = True):
        results = self._qa_model.predict(question_text,
                                         search_by=search_by,
                                         topk=results_num,
                                         answer_only=answer_only)
        return results
Exemplo n.º 4
0
import zipfile
zip_ref = zipfile.ZipFile('DataAndCheckpoint.zip', 'r')
zip_ref.extractall('newFolder')
zip_ref.close()

#@title Load model weights and Q&A data. Double click to see code

from docproduct.predictor import RetreiveQADoc

pretrained_path = 'BioBertFolder/biobert_v1.0_pubmed_pmc/'
# ffn_weight_file = None
bert_ffn_weight_file = 'newFolder/models/bertffn_crossentropy/bertffn'
embedding_file = 'Float16EmbeddingsExpanded5-27-19.pkl'

doc = RetreiveQADoc(pretrained_path=pretrained_path,
ffn_weight_file=None,
bert_ffn_weight_file=bert_ffn_weight_file,
embedding_file=embedding_file)

''' predict on a single sentence just for the testing purpose. '''
test_sen1 = [0,0]
test_sen1[0] = "This is one of the best creation of Nolan. I can say, it's his magnum opus. Loved the soundtrack and especially those creative dialogues."
test_sen1[1] = "I have fever for past few days."

for t in test_sen1:
  test_sen1 = TEXT.preprocess(t)
  test_sen1 = [[TEXT.vocab.stoi[x] for x in test_sen1]]


  test_sen = np.asarray(test_sen1)
  test_sen = torch.LongTensor(test_sen)
  test_tensor = Variable(test_sen, volatile=True)
Exemplo n.º 5
0
 def __init__(self, biobert_path: str, bert_fnn_weights: str,
              embedding_file: str):
     self._qa_model = RetreiveQADoc(pretrained_path=biobert_path,
                                    ffn_weight_file=None,
                                    bert_ffn_weight_file=bert_fnn_weights,
                                    embedding_file=embedding_file)
Exemplo n.º 6
0
from docproduct.predictor import RetreiveQADoc

pretrained_path = 'BioBertFolder/biobert_v1.0_pubmed_pmc/'
# ffn_weight_file = None
bert_ffn_weight_file = 'newFolder/models/bertffn_crossentropy/bertffn'
embedding_file = 'Float16EmbeddingsExpanded5-27-19.pkl'

doc = RetreiveQADoc(pretrained_path=pretrained_path,
                    ffn_weight_file=None,
                    bert_ffn_weight_file=bert_ffn_weight_file,
                    embedding_file=embedding_file)


question_text = "i am 18 and having frequent and painful urination, with a mild fever since 2-3 days"

search_similarity_by = 'answer'

number_results_toReturn = 10

answer_only = True

returned_results = doc.predict(question_text,
                               search_by=search_similarity_by, topk=number_results_toReturn, answer_only=answer_only)

print('')
for jk in range(len(returned_results)):
    print("Result ", jk+1)
    print(returned_results[jk])
    print('')
from docproduct.predictor import RetreiveQADoc

pretrained_path = 'pubmed_pmc_470k/'
ffn_weight_file = None
bert_ffn_weight_file = 'models/bertffn_crossentropy/bertffn'
embedding_file = 'qa_embeddings/bertffn_crossentropy.pkl'

doc = RetreiveQADoc(pretrained_path=pretrained_path,
                    ffn_weight_file=None,
                    bert_ffn_weight_file=bert_ffn_weight_file,
                    embedding_file=embedding_file)

print(
    doc.predict('my eyes hurts and i have a headache.',
                search_by='answer',
                topk=5,
                answer_only=True))
print(
    doc.predict('my eyes hurts and i have a headache.',
                search_by='question',
                topk=5,
                answer_only=True))
Exemplo n.º 8
0
from flask import Flask, jsonify, make_response, request

app = Flask(__name__)

MODEL_LOADED = False
REPO_LOCATION = os.path.join("code", "Hackshetra", "py_backend")
PRETRAINED_PATH = os.path.join(os.path.expanduser("~"), REPO_LOCATION, "data",
                               "BioBert", "biobert_v1.0_pubmed_pmc")
BERT_FFN_WEIGHT_FILE = os.path.join(os.path.expanduser("~"), REPO_LOCATION,
                                    "data", "newFolder", "models",
                                    "bertffn_crossentropy", "bertffn")
EMBEDDING_FILE = os.path.join(os.path.expanduser("~"), REPO_LOCATION, "data",
                              "Float16EmbeddingsExpanded5-27-19.pkl")

DOCTOR = RetreiveQADoc(pretrained_path=PRETRAINED_PATH,
                       ffn_weight_file=None,
                       bert_ffn_weight_file=BERT_FFN_WEIGHT_FILE,
                       embedding_file=EMBEDDING_FILE)

MODEL_LOADED = True
print("\n\n MODEL LOADED YAY 😀")


@app.route('/wiki', methods=['POST'])
def table():
    '''
    Will return the data from side table from WikiPedia
    '''
    try:
        query = request.json['query']
        return jsonify(wiki.wiki_get_table(query))
Exemplo n.º 9
0
    tar.extractall(path='BioBertFolder/')
    tar.close()

    file_id = '1uCXv6mQkFfpw5txGnVCsl93Db7t5Z2mp'

    download_file_from_google_drive(file_id,
                                    'Float16EmbeddingsExpanded5-27-19.pkl')

    file_id = 'https://onedrive.live.com/download?cid=9DEDF3C1E2D7E77F&resid=9DEDF3C1E2D7E77F%2132792&authkey=AEQ8GtkcDbe3K98'

    urllib.request.urlretrieve(file_id, 'DataAndCheckpoint.zip')

    if not os.path.exists('newFolder'):
        os.makedirs('newFolder')

    zip_ref = zipfile.ZipFile('DataAndCheckpoint.zip', 'r')
    zip_ref.extractall('newFolder')
    zip_ref.close()


from docproduct.predictor import RetreiveQADoc

pretrained_path = 'BioBertFolder/biobert_v1.0_pubmed_pmc/'
# ffn_weight_file = None
bert_ffn_weight_file = 'newFolder/models/bertffn_crossentropy/bertffn'
embedding_file = 'Float16EmbeddingsExpanded5-27-19.pkl'

doc = RetreiveQADoc(pretrained_path=pretrained_path,
                    ffn_weight_file=None,
                    bert_ffn_weight_file=bert_ffn_weight_file,
                    embedding_file=embedding_file)
Exemplo n.º 10
0
def load_model():
    global doc
    doc = RetreiveQADoc(pretrained_path=pretrained_path,
                        ffn_weight_file=None,
                        bert_ffn_weight_file=bert_ffn_weight_file,
                        embedding_file=embedding_file)