Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -22,8 +22,11 @@ retriever = SentenceTransformer('all-MiniLM-L6-v2')
|
|
| 22 |
|
| 23 |
# Load ONNX model for QA using optimum.onnxruntime
|
| 24 |
# Model: Xenova/distilbert-base-uncased-distilled-squad (~260MB)
|
| 25 |
-
#
|
| 26 |
-
model = ORTModelForQuestionAnswering.from_pretrained(
|
|
|
|
|
|
|
|
|
|
| 27 |
tokenizer = AutoTokenizer.from_pretrained("Xenova/distilbert-base-uncased-distilled-squad")
|
| 28 |
qa_model = pipeline("question-answering", model=model, tokenizer=tokenizer, framework="ort")
|
| 29 |
|
|
@@ -89,7 +92,7 @@ def answer_question(question):
|
|
| 89 |
|
| 90 |
# Compute cosine similarity with stored embeddings
|
| 91 |
cos_scores = util.cos_sim(question_embedding, embeddings)[0]
|
| 92 |
-
top_k = min(2, len(corpus)) # Get top
|
| 93 |
top_indices = np.argsort(-cos_scores)[:top_k]
|
| 94 |
|
| 95 |
# Retrieve context (top 3 paragraphs)
|
|
|
|
| 22 |
|
| 23 |
# Load ONNX model for QA using optimum.onnxruntime
|
| 24 |
# Model: Xenova/distilbert-base-uncased-distilled-squad (~260MB)
|
| 25 |
+
# Specify file_name="model.onnx" to select the correct ONNX file
|
| 26 |
+
model = ORTModelForQuestionAnswering.from_pretrained(
|
| 27 |
+
"Xenova/distilbert-base-uncased-distilled-squad",
|
| 28 |
+
file_name="model.onnx"
|
| 29 |
+
)
|
| 30 |
tokenizer = AutoTokenizer.from_pretrained("Xenova/distilbert-base-uncased-distilled-squad")
|
| 31 |
qa_model = pipeline("question-answering", model=model, tokenizer=tokenizer, framework="ort")
|
| 32 |
|
|
|
|
| 92 |
|
| 93 |
# Compute cosine similarity with stored embeddings
|
| 94 |
cos_scores = util.cos_sim(question_embedding, embeddings)[0]
|
| 95 |
+
top_k = min(2, len(corpus)) # Get top 2 or less if fewer paragraphs
|
| 96 |
top_indices = np.argsort(-cos_scores)[:top_k]
|
| 97 |
|
| 98 |
# Retrieve context (top 3 paragraphs)
|