Small undergraduate project for the course in Statistical Methods for Machine Learning, to practice with Hugging Face models and the LangChain library
The main goal of the project is to create a prompt chain that can build a deck of flashcards from a pdf file given as input.
Specifically, the purpose is to give learning support to students in STEM (and other) courses by automating the process of creating useful tools such as flashcards.
We used google/flan-t5-base
from HuggingFace.
T5 is an encoder-decoder model pre-trained on a multi-task mixture of unsupervised and supervised tasks and for which each task is converted into a text-to-text format. T5 works well on a variety of tasks out-of-the-box by prepending a different prefix to the input corresponding to each task, (e.g., for translation: translate English to German: …, for summarization: summarize: ….).
Flan is a pretraining methods that is based on prompting. The Flan-T5 are T5 models trained on the Flan collection of datasets which include: taskmaster2
, djaym7/wiki_dialog
, deepmind/code_contests
, lambada, gsm8k
, aqua_rat
, esnli
, quasc
and qed
.
If you want to test the code follow the following steps:
- Run all the cells in the notebook
- Download the
flashcards.txt
file in the samecontent
directory. This txt file contains one questione-asnwer pair per line.
We build three blocks for our chain:
- summary block that takes as input the text chuck and writing style and then summarizes the chunk itself to meet the maximum number of tokens to be given as input to the model locally;
- question block which takes as input the text summary from the previous block and returns a plausible question about it;
- answer block that takes as input both the text summary and the question constructed in the previous blocks and formulates an ad hoc answer.
We can define below a list of improvements to the project:
- make a division of the text into blocks based on data mining algorithms in order to create summaries as clear and specific as possible;
- grouping question-answer pairs into decks about the same topic using, for example, Latent Semantic Analysis or Clustering techniques;
- use the Openai API and combine the three hand-defined blocks into a SequentialChain of langchain.
Our chain was defined on the basis of a free, open, runnable LLM without GPU, but that does not guarantee high quality of results. In fact, the real power of langchain can really be harnessed in combination with the Openai model and API.