Self Service Learning Platform With Hugging Face Transformers!
Tags: transformer, huggingface, sagemaker, machinelearning
Published: 2023-06-30 19:58:32

### Introduction

#### About Quizify
The ` Self-Service Learning platform` can be converted to an innovative app designed to revolutionise your learning experience. With this powerful tool, users can effortlessly generate custom quizzes based on any PDF file they download from the web. Gone are the days of tedious manual summarisation and translation! this potential application leverages the cutting-edge capabilities of Hugging Face transformers to simplify the entire process. Once you've obtained a PDF, simply import it into the app and watch as the magic unfolds.

As students, parents, or job seekers, we often encounter situations where we need to summarise a document promptly and prepare questions for ourselves or our children. This inspired the concept of a self-service learning platform. 

This learning platform empowers you to retrieve files from the internet and summarise the document with ease. Not only that, but this app also offers built-in translation functionality, allowing you to understand the content in your preferred language. 

But the true power of our app lies in its ability to transform your summarised and translated document into an interactive question-answer service. By analysing the text and extracting relevant information, the app generates thought-provoking questions that test your understanding of the material. Whether you're a student striving for academic excellence or a professional looking to enhance your knowledge, the Self Service Quiz Generator platform is your go-to tool for efficient and engaging learning.

### Motivation
 
Words like _ChatGPT, Generative AI, LLM, LangChain, Hugging Face, Transformers,_ and many others have become part of our daily vocabulary, frequently heard and mentioned throughout the day.

Regrettably, it is challenging to keep pace with the rapid advancements in technology and acquire knowledge about every new development introduced in the tech world.

Being a part of the AWS Community Builder offers numerous advantages, one of which is the opportunity to participate in a variety of challenges ranging from openMic sessions to Hackathons like the current one. Each challenge provides a valuable learning experience. In this instance, we were presented with the #AiHackathon challenge to develop a tool utilising the [Transformer Tools](https://huggingface.co/docs/transformers/main/transformers_agents) framework. 

My unwavering desire to learn about ML concepts and the constantly evolving landscape of ML and AI has made it impossible for me to let go of this incredible learning opportunity!

### Process of shaping my idea

Prior to this challenge, I had no prior knowledge of Hugging Face Transformers and agents. To familiarise myself with the concept of transformers, I began by exploring tutorials and educational resources. As I delved deeper, I contemplated how to harness the immense potential of the Large Language Model technology.

With a more comprehensive understanding of the topic at hand, I embarked on a brainstorming session. After finalising the idea, I focused on outlining the features, which led me to develop this tool incorporating six custom Transformer Tools.

![Quizify Custom Tools](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v84702vmidzysdf5pei4.png)

#### Downloader Service

To begin, You should provide a valid URL for your PDF resource.

If you choose to enter a URL, The Hugging Face Agent will seamlessly download the file for you. This process utilises a custom tool known as the `download_file_tool` working silently behind the scenes to retrieve the document.

Currently, This proof of concept exclusively supports PDF files at this stage.

As an alternative, you have the option to upload your PDF file. Our agent will utilise a specialised tool called `read_file_tool` to process and extract the content from the document. The extracted information will be saved for further use within the platform.

#### Summarisation Service

Get ready to dive into the exciting features of our app. How about downloading a summarisation of your uploaded document or web content? Let's embark on this thrilling journey together!"
By asking the agent to summarise the file content, the Hugging Face agent will generate a summary of your document.


Please note that the summarisation model used by the agent is the `facebook/bart-large-cnn`, the results may not be perfect. If your document is excessively large, there is a chance it may encounter difficulties or exhibit unexpected behaviour while processing.

Here is an example how I have leveraged Transformers pipeline to summarise a large document:


#### Translation Service

Perhaps English is your second language, just like mine! Or you have found an amazing document to read but not in the language that you are familiar with, don't worry, I've got your back 😉. With this tool, you can select between `Italian`, `French`, and `Spanish` languages. Not only that, but you can also have the summary translated into your preferred language for better understanding.


#### Text-To-Speech Service

In addition to all we mentioned so far, if you are keen to listen to the summary or the original uploaded content, in this platform you will be able to generate audio from the file.


#### Quiz Generator Service

Have you studied the summary carefully? Great! That means you're ready, right? Now, let's ask our Hugging Face agent to generate some engaging multiple-choice questions for you! Get ready to put your knowledge to the test!

You have the freedom to choose the language in which you want to be examined! Simply select your desired language option. Additionally, you can specify the number of questions you would like in your requested exam. Tailor the examination experience according to your preferences!
Once the agent has gathered this information, it will utilise another specialised tool called `quiz_generator_tool` to generate the quiz for you. This tool is specifically designed to create dynamic and engaging quizzes based on your selected preferences. Sit back and let the quiz generation process unfold!

### Outcome and demonstration of Jupyter Notebook

The full Jupyter Notebook is available for reference at the provided [Link](https://github.com/RonakReyhani/quizify). To begin, start by installing the necessary dependencies and logging in to the Hugging Face hub. Afterward, the remaining steps are straightforward and easy to follow.

### Challenges I faced!

- When I began my learning journey, I sought answers to all my "Why" and "How" questions. However, since it's a relatively new topic, the availability of learning materials was limited. Therefore, I had to delve into documentation and explore relevant forums to find the information I needed. For instance, I had to search for guidance on configuring a custom Prompt run_template, such as "How to configure a custom Prompt run_template."

- Error message notebook_login! So I ended up using the `login` class instead of `notebook_login`

> ValueError(“Invalid token passed.”)

- By removing PreTools from the agent's toolBox, the agent's confusion can be reduced. However, it's important to note that the agent will still search for default tools, especially if they are within the same context, such as translation or summarisations.
- Unsuccessful attempts on using Streamlit and Vercel  as a fast and quick way to add a nice user interface in the such short time. 

![streamlit error](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s2v5qi18dbi23wnrqf2f.png)
 
- Managing dependencies for the tools proved to be a significant factor that discouraged me from considering combinations like AppSync/API Gateway and Lambda. Instead, I made a straightforward decision to implement the solution using a Jupyter Notebook, which allowed for easier dependency management.
- LLM models are so sensitive with "Text" as their input! Prompt engineering is a "Thing".
 
### What is next?

There are numerous ways to enhance this tool. First and foremost, it would be beneficial to transform the concept into an application by incorporating a user interface and providing proper API references to various tools. Additionally, the models can be fine-tuned and retrained to enhance the quality of each service, such as the Summarisation and Quiz Generator Tools.

### Reflection

![Architecture](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y131vqo7j9zcmbcy5vbm.png)


Throughout this entire journey, I have gained a wealth of knowledge about transformers and have witnessed the immense power of the Agent. I have successfully trained the most complex LLM Model and integrated it into the agent's toolbox. This has sparked my imagination, as I contemplate the vast possibilities of designing efficient systems with the agent at the centre, orchestrating decoupled tasks.

As the AiHackathon draws to a close, my enthusiasm remains undiminished, compelling me to revisit each challenge and seek their solutions one by one. I find myself continuously envisioning the end-to-end architecture of this solution in my mind. It is now time to bring this vision out of my head and construct it meticulously as a fully-fledged application.