Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -4,14 +4,14 @@ import json
|
|
4 |
import torch
|
5 |
|
6 |
# Define hyperparameters
|
7 |
-
learning_rate =
|
8 |
-
batch_size =
|
9 |
-
epochs =
|
10 |
-
max_seq_length =
|
11 |
-
warmup_steps =
|
12 |
-
weight_decay = 0.01
|
13 |
-
dropout_prob = 0.
|
14 |
-
gradient_clip_value = 1.0
|
15 |
|
16 |
context_val = ''
|
17 |
|
@@ -23,8 +23,7 @@ context = gr.Textbox(label="Add the Context (Paragraph or texts) for which you w
|
|
23 |
|
24 |
def q_n_a_fn(context, text):
|
25 |
QA_input = {'question': text, 'context': context}
|
26 |
-
|
27 |
-
|
28 |
# Set the device (CPU or GPU)
|
29 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
30 |
q_n_a_model.to(device)
|
@@ -34,7 +33,7 @@ def q_n_a_fn(context, text):
|
|
34 |
|
35 |
# Get predictions
|
36 |
with torch.no_grad():
|
37 |
-
outputs = q_n_a_model(**inputs)
|
38 |
|
39 |
# Get the predicted answer span indices
|
40 |
start_idx, end_idx = torch.argmax(outputs.start_logits), torch.argmax(outputs.end_logits)
|
@@ -47,7 +46,7 @@ def q_n_a_fn(context, text):
|
|
47 |
answer_tokens = inputs["input_ids"][0][start_idx : end_idx + 1]
|
48 |
|
49 |
# Decode the answer tokens into a human-readable answer
|
50 |
-
answer = tokenizer.decode(
|
51 |
|
52 |
return answer
|
53 |
|
@@ -85,4 +84,4 @@ with gr.Blocks(theme='gradio/soft') as demo:
|
|
85 |
gr.Interface(fn=classification_fn, inputs=[context], outputs="text")
|
86 |
|
87 |
if __name__ == "__main__":
|
88 |
-
demo.launch()
|
|
|
4 |
import torch
|
5 |
|
6 |
# Define hyperparameters
|
7 |
+
learning_rate = 3e-5
|
8 |
+
batch_size = 16
|
9 |
+
epochs = 3
|
10 |
+
max_seq_length = 512
|
11 |
+
warmup_steps = 100
|
12 |
+
weight_decay = 0.01
|
13 |
+
dropout_prob = 0.1
|
14 |
+
gradient_clip_value = 1.0
|
15 |
|
16 |
context_val = ''
|
17 |
|
|
|
23 |
|
24 |
def q_n_a_fn(context, text):
|
25 |
QA_input = {'question': text, 'context': context}
|
26 |
+
|
|
|
27 |
# Set the device (CPU or GPU)
|
28 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
29 |
q_n_a_model.to(device)
|
|
|
33 |
|
34 |
# Get predictions
|
35 |
with torch.no_grad():
|
36 |
+
outputs = q_n_a_model(**inputs) # Use q_n_a_model to get model predictions
|
37 |
|
38 |
# Get the predicted answer span indices
|
39 |
start_idx, end_idx = torch.argmax(outputs.start_logits), torch.argmax(outputs.end_logits)
|
|
|
46 |
answer_tokens = inputs["input_ids"][0][start_idx : end_idx + 1]
|
47 |
|
48 |
# Decode the answer tokens into a human-readable answer
|
49 |
+
answer = tokenizer.decode(inputs["input_ids"][0][start_idx:end_idx+1], skip_special_tokens=True)
|
50 |
|
51 |
return answer
|
52 |
|
|
|
84 |
gr.Interface(fn=classification_fn, inputs=[context], outputs="text")
|
85 |
|
86 |
if __name__ == "__main__":
|
87 |
+
demo.launch()
|