# Generate dataset for fine tuning on PDF(s)

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fgenerate-dataset-for-fine-tuning-on-pdf-s%2F104902%3E%5C
**Category:** 🤗Transformers\
**Created:** [September 2, 2024, 6:29am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fgenerate-dataset-for-fine-tuning-on-pdf-s%2F104902 "2024-09-02T06:29:57Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![sujitrect](https://avatars.discourse-cdn.com/v4/letter/s/c4cdca/32.png) [@sujitrect](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fsujitrect)%5C
**Post date:** [September 2, 2024, 6:29am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fgenerate-dataset-for-fine-tuning-on-pdf-s%2F104902%2F1 "2024-09-02T06:29:57Z")

</div>

Hi Everyone,  
Most of the resources regarding finetuning use a pre-existing dataset.  
Given that I have one PDF, how do I generate a dataset which can be used for finetuning, so that I can use the fine tuned model for answering user queries in context of the document?

I understand that RAG is recommended mechanism for this use case, but I want to try out finetuning anyways, but stuck on how to generate dataset.  
I have seen suggestions on a mechanism where people have used LLM to generate questions and prepare dataset. But, how can that cover all possible questions that can be asked. Also, I am not finding any concrete implementation.  
Please help me point to any githubs that do this already on a sample pdf.

---

<div class="post-metadata">

**Author:** ![John6666](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/john6666/32/27664_2.png) [@John6666](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FJohn6666)%5C
**Post date:** [September 2, 2024, 6:43am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fgenerate-dataset-for-fine-tuning-on-pdf-s%2F104902%2F2 "2024-09-02T06:43:44Z")

</div>

I know it’s not the exact answer, but maybe the logic in this space will help.  
Because there is no PDF conversion in the original HF functionality, so it must be converted manually internally and fed to the LLM.

> **[RAG PDF CHATBOT - a Hugging Face Space by prithivMLmods](https://huggingface.co/spaces/prithivMLmods/RAG-PDF-CHATBOT)**
>
> pdf scraper RAG

> **[app.py · prithivMLmods/RAG-PDF-CHATBOT at main](https://huggingface.co/spaces/prithivMLmods/RAG-PDF-CHATBOT/blob/main/app.py)**
>
> We’re on a journey to advance and democratize artificial intelligence through open source and open science.

I think someone made a space for converting PDFs to datasets, but I can’t find it.  
Maybe it’s somewhere in this.

> **[Spaces - Hugging Face](https://huggingface.co/spaces?sort=trending&search=pdf)**
>
> Discover amazing ML apps made by the community

---

<div class="post-metadata">

**Author:** ![mikehemberger](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/mikehemberger/32/28013_2.png) [@mikehemberger](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fmikehemberger)%5C
**Post date:** [September 2, 2024, 7:06am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fgenerate-dataset-for-fine-tuning-on-pdf-s%2F104902%2F3 "2024-09-02T07:06:03Z")

</div>

Hi @sujitrect ,  
In any case (RAG or fine-tuning) you have to extract information from the PDF. Both [LangChain](https://github.com/langchain-ai/langchain/blob/master/cookbook/Multi_modal_RAG.ipynb) and [LlamaIndex](https://docs.llamaindex.ai/en/stable/api_reference/readers/smart_pdf_loader/) have the functionality that you need. Hope this helps establishing your dataset.

From there onwards everything depends on what you want to fine-tune the model for. For QA I would definitely start using RAG. This can then serve as a baseline that you can compare your fine-tuning efforts to.

Best,  
M

---

<div class="post-metadata">

**Author:** ![rishisuresh](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/rishisuresh/32/30142_2.png) [@rishisuresh](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Frishisuresh)%5C
**Post date:** [September 3, 2024, 3:57am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fgenerate-dataset-for-fine-tuning-on-pdf-s%2F104902%2F4 "2024-09-03T03:57:20Z")

</div>

@sujitrect - Thank you for asking this question. I was asking the same question to my friends as well. Am following this thread.

---

<div class="post-metadata">

**Author:** ![rishisuresh](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/rishisuresh/32/30142_2.png) [@rishisuresh](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Frishisuresh)%5C
**Post date:** [September 3, 2024, 4:06am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fgenerate-dataset-for-fine-tuning-on-pdf-s%2F104902%2F5 "2024-09-03T04:06:38Z")

</div>

@mikehemberger - I am a newbie here. From what I understand, the HF models are meant for 1 particular task type (QA, Text Gen, Seq2Seq, Classification etc). We would like to fine-tune a pretrained model (like Mistral or Llama) to gain knowledge on the numerous domain specific documents we have. We are expecting to use the finetuned model for mostly question answering or summarization. In case of QA, we can come up with 1000s of questions/answers pairs to train the model. However, they wont be sufficient to cover all the knowledge that the documents have. So, the question is how do we feed all the documents for finetuning instead of training it just with 1000s of questions/answers. We can use RAG but what if we want to use the finetuning approach. Any insights will greatly help. Thank you!

---

<div class="post-metadata">

**Author:** ![mikehemberger](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/mikehemberger/32/28013_2.png) [@mikehemberger](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fmikehemberger)%5C
**Post date:** [September 3, 2024, 8:53am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fgenerate-dataset-for-fine-tuning-on-pdf-s%2F104902%2F6 "2024-09-03T08:53:29Z")

</div>

Hi @rishisuresh ,  
I’m definitely not an expert on this but that’s sounds like you’re looking for an unsupervised approach to fine-tuning (as you want to cover many-to-all knowledge in your dataset but - I assume - the documents vary in structure and information content, rendering manual information extraction not feasible).  
As far as I understand the current LLM situation that would be the case of „pretraining“ using next word prediction (most likely also not feasible) or using [PEFT](https://huggingface.co/blog/peft).  
I haven’t done either of those yet, sorry.  
Hope someone is able to help.  
Best,  
M

---

<div class="post-metadata">

**Author:** ![rishisuresh](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/rishisuresh/32/30142_2.png) [@rishisuresh](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Frishisuresh)%5C
**Post date:** [September 3, 2024, 1:08pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fgenerate-dataset-for-fine-tuning-on-pdf-s%2F104902%2F7 "2024-09-03T13:08:43Z")

</div>

Thanks a lot @mikehemberger

---

<div class="post-metadata">

**Author:** ![ayabongaqwabi](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/ayabongaqwabi/32/52055_2.png) [@ayabongaqwabi](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fayabongaqwabi)%5C
**Post date:** [August 3, 2025, 5:56pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fgenerate-dataset-for-fine-tuning-on-pdf-s%2F104902%2F8 "2025-08-03T17:56:48Z")

</div>

I have a tool similar to what you are looking for [GitHub - AyabongaQwabi/historybook\_to\_dataset: Converts a history book to a machine learning dataset for model finetuning](https://github.com/AyabongaQwabi/historybook_to_dataset)
