dschandra commited on
Commit
36bf9cf
·
verified ·
1 Parent(s): a6bd74b

Create Knowledge_base.py

Browse files
Files changed (1) hide show
  1. Knowledge_base.py +17 -0
Knowledge_base.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import pipeline
2
+
3
+ # Initialize the DistilBERT QA model
4
+ qa_pipeline = pipeline("question-answering", model="distilbert-base-uncased-distilled-squad")
5
+
6
+ def generate_answer(question):
7
+ # The context can be a static text or dynamic content
8
+ context = """
9
+ Bill Gates is a co-founder of Microsoft, one of the largest software companies in the world.
10
+ He is an entrepreneur, software developer, and philanthropist, known for his role in the development of personal computing.
11
+ Gates also played a significant role in shaping the tech industry and later focused on philanthropy through the Bill and Melinda Gates Foundation.
12
+ """
13
+
14
+ # Use the model to extract the answer from the context
15
+ result = qa_pipeline(question=question, context=context)
16
+
17
+ return result['answer']