Skip to content

Instantly share code, notes, and snippets.

@valdo404
Last active August 2, 2023 12:41
Show Gist options
  • Save valdo404/a134a2bd121a42e896558e4ff79f6e53 to your computer and use it in GitHub Desktop.
Save valdo404/a134a2bd121a42e896558e4ff79f6e53 to your computer and use it in GitHub Desktop.
Some haystack test
farm-haystack[all,inference]==1.19.0
Flask-SQLAlchemy
torch
sentence-transformers
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