Last active
August 2, 2023 12:41
-
-
Save valdo404/a134a2bd121a42e896558e4ff79f6e53 to your computer and use it in GitHub Desktop.
Some haystack test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
farm-haystack[all,inference]==1.19.0 | |
Flask-SQLAlchemy | |
torch | |
sentence-transformers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from haystack.utils import * | |
from haystack.nodes import * | |
from haystack.nodes.retriever import * | |
from haystack.nodes.reader import FARMReader | |
from haystack.pipelines import * | |
doc_dir = "." | |
from haystack.document_stores import InMemoryDocumentStore | |
document_store = InMemoryDocumentStore(use_bm25=True) | |
# Clean & load your documents into the DocumentStore | |
dicts = convert_files_to_docs(doc_dir, clean_func=clean_wiki_text) | |
document_store.write_documents(dicts) | |
# Retriever: A Fast and simple algo to identify the most promising candidate documents | |
retriever = BM25Retriever(document_store) | |
# Reader: Powerful but slower neural network trained for QA | |
model_name = "deepset/roberta-base-squad2" | |
reader = FARMReader(model_name) | |
# Pipeline: Combines all the components | |
pipe = ExtractiveQAPipeline(reader, retriever) | |
# Voilà! Ask a question! | |
question = "Which is you best python file ?" | |
prediction = pipe.run(query=question) | |
print_answers(prediction) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment