AI bot that could answer your questions

Hi, I am Yash Makan and am back with another cool episode. Today as I was reading my school textbooks a thought came to my mind that wouldn’t that be cool if python program can learn all the questions from my textbook. So in today’s blog, we are develo…


This content originally appeared on DEV Community and was authored by Yash Makan

Hi, I am Yash Makan and am back with another cool episode. Today as I was reading my school textbooks a thought came to my mind that wouldn't that be cool if python program can learn all the questions from my textbook. So in today's blog, we are developing a question answering bot. What this means is that you can feed this bot some data and ask questions from the textbook and the bot will give answers to each question pretty precisely.

answer the questions

Introduction

Here we will use a library known as transformers. This library is made by huggingface and has a lot of models available for different tasks. This library is my favourite and you should check other models out as well. Each model will have a tokenizer which will be in charge of preparing the inputs for a model. This means that whenever you are generating the output you must pass the model and tokenizer. There is also an easy way which is using pipeline(). These pipelines are objects that abstract most of the complex code from the library. In this tutorial, we are using the pipeline. For example, in this blog, we are using the question-answering pipeline. This will clear once we code.

Installation

pip install transformers

Let's Start Small

source code

The code is pretty straightforward. We are first importing pipeline from transformers. Then we are initializing the question_answering pipeline. After that, we input the question and get the result by passing the question and context in the question_answering pipeline. Here the context is the paragraph or the initial text from which the bot finds the answers. At last, the result is printed.

You see the more you provide the context, the better and widely the bot will return the result.

what else? 🧑🏼

So you see the power with just a few lines of code we achieved a bot that can learn stuff very easily, more accurately and a lot faster than us. But you must be thinking about what can you do to make this better. And the answer is to provide more context. Here are some ideas for this project:

  • Scrape Wikipedia Articles and feed the data in the script. For example, scrape all the links related to history from Wikipedia(as much as you can) and then scrape the text from each page and put it together. This will create a bot that will know a lot about history I mean a lot...
  • Are you a college student? If yes then you can feed your cs book as pdf in the script and ask questions. The program will be able to answer your questions. 👨🏼‍🎓

Conclusion

So you see it's that easy to make a question answering bot. I really hope that you liked this post. If yes then do hit the like button and don't forget to bookmark the post as well. I hope that this post is worth sharing with everyone. If you have any doubts about anything to add then you are welcome to add the message in the discussion below. Will meet with you guys next time till then b-bye!

More Articles by Author

My Socials


This content originally appeared on DEV Community and was authored by Yash Makan


Print Share Comment Cite Upload Translate Updates
APA

Yash Makan | Sciencx (2021-11-17T11:44:54+00:00) AI bot that could answer your questions. Retrieved from https://www.scien.cx/2021/11/17/ai-bot-that-could-answer-your-questions/

MLA
" » AI bot that could answer your questions." Yash Makan | Sciencx - Wednesday November 17, 2021, https://www.scien.cx/2021/11/17/ai-bot-that-could-answer-your-questions/
HARVARD
Yash Makan | Sciencx Wednesday November 17, 2021 » AI bot that could answer your questions., viewed ,<https://www.scien.cx/2021/11/17/ai-bot-that-could-answer-your-questions/>
VANCOUVER
Yash Makan | Sciencx - » AI bot that could answer your questions. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/11/17/ai-bot-that-could-answer-your-questions/
CHICAGO
" » AI bot that could answer your questions." Yash Makan | Sciencx - Accessed . https://www.scien.cx/2021/11/17/ai-bot-that-could-answer-your-questions/
IEEE
" » AI bot that could answer your questions." Yash Makan | Sciencx [Online]. Available: https://www.scien.cx/2021/11/17/ai-bot-that-could-answer-your-questions/. [Accessed: ]
rf:citation
» AI bot that could answer your questions | Yash Makan | Sciencx | https://www.scien.cx/2021/11/17/ai-bot-that-could-answer-your-questions/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.