Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,8 +5,19 @@ import pdfplumber
|
|
| 5 |
import os
|
| 6 |
from transformers import AutoModelForQuestionAnswering, AutoTokenizer, pipeline
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
def AImodel(text,questionText):
|
| 9 |
model_name = "deepset/tinyroberta-squad2"
|
|
|
|
| 10 |
|
| 11 |
# a) Get predictions
|
| 12 |
nlp = pipeline('question-answering', model=model_name, tokenizer=model_name)
|
|
@@ -21,6 +32,17 @@ def AImodel(text,questionText):
|
|
| 21 |
# b) Load model & tokenizer
|
| 22 |
model = AutoModelForQuestionAnswering.from_pretrained(model_name)
|
| 23 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
return(res)
|
| 25 |
|
| 26 |
|
|
|
|
| 5 |
import os
|
| 6 |
from transformers import AutoModelForQuestionAnswering, AutoTokenizer, pipeline
|
| 7 |
|
| 8 |
+
batch_size = 96
|
| 9 |
+
n_epochs = 2
|
| 10 |
+
base_LM_model = "roberta-base"
|
| 11 |
+
max_seq_len = 386
|
| 12 |
+
learning_rate = 3e-5
|
| 13 |
+
warmup_proportion = 0.2
|
| 14 |
+
doc_stride = 128
|
| 15 |
+
max_query_length = 64
|
| 16 |
+
|
| 17 |
+
|
| 18 |
def AImodel(text,questionText):
|
| 19 |
model_name = "deepset/tinyroberta-squad2"
|
| 20 |
+
|
| 21 |
|
| 22 |
# a) Get predictions
|
| 23 |
nlp = pipeline('question-answering', model=model_name, tokenizer=model_name)
|
|
|
|
| 32 |
# b) Load model & tokenizer
|
| 33 |
model = AutoModelForQuestionAnswering.from_pretrained(model_name)
|
| 34 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 35 |
+
inputs = tokenizer(
|
| 36 |
+
questionText, text,
|
| 37 |
+
add_special_tokens=True,
|
| 38 |
+
max_length=max_seq_len,
|
| 39 |
+
truncation=True,
|
| 40 |
+
return_tensors="pt",
|
| 41 |
+
padding="max_length",
|
| 42 |
+
stride=doc_stride,
|
| 43 |
+
return_overflowing_tokens=True,
|
| 44 |
+
return_offsets_mapping=True
|
| 45 |
+
)
|
| 46 |
return(res)
|
| 47 |
|
| 48 |
|