# Data Format while finetuning Llama2 for json extraction?

**URL:** <https://discuss.huggingface.co/t/data-format-while-finetuning-llama2-for-json-extraction/61236>\
**Category:** Beginners\
**Created:** [November 6, 2023, 2:18pm UTC](https://discuss.huggingface.co/t/data-format-while-finetuning-llama2-for-json-extraction/61236 "2023-11-06T14:18:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![seinfeld](https://avatars.discourse-cdn.com/v4/letter/s/ccd318/32.png) [@seinfeld](https://discuss.huggingface.co/u/seinfeld)\
**Post date:** [November 6, 2023, 2:18pm UTC](https://discuss.huggingface.co/t/data-format-while-finetuning-llama2-for-json-extraction/61236/1 "2023-11-06T14:18:24Z")

</div>

I have a task in mind where i want the Llama-2 to be finetuned to generate jsons in a particular format from sentences.  
I have looked at several finetuning examples and datasets such as [https://www.philschmid.de/sagemaker-llama2-qlora](https://www.philschmid.de/sagemaker-llama2-qlora) which use `instruction, response and context` to train the model.  
What to put in my context? I tried putting the sentence in the instruction category and put the json format it should use in the context category. But in case context is same for all examples. I this correct? Is there an alternative way to do this?

---

<div class="post-metadata">

**Author:** ![developer0313testing](https://avatars.discourse-cdn.com/v4/letter/d/b5e925/32.png) [@developer0313testing](https://discuss.huggingface.co/u/developer0313testing)\
**Post date:** [November 10, 2023, 5:30pm UTC](https://discuss.huggingface.co/t/data-format-while-finetuning-llama2-for-json-extraction/61236/2 "2023-11-10T17:30:46Z")

</div>

hello, did you get the result you wanted? i was trying to do something similar but failing.  
basically, i wanted it to extract specific item names from text and then get me their unique codes taught to the model by finetuning. it somewhat does the extraction correctly but fetching the unique code is where i fail.

---

<div class="post-metadata">

**Author:** ![seinfeld](https://avatars.discourse-cdn.com/v4/letter/s/ccd318/32.png) [@seinfeld](https://discuss.huggingface.co/u/seinfeld)\
**Post date:** [November 10, 2023, 9:02pm UTC](https://discuss.huggingface.co/t/data-format-while-finetuning-llama2-for-json-extraction/61236/3 "2023-11-10T21:02:42Z")

</div>

I did try adding the json it should fill in context and the actual sentence in the instruction, which worked for me(for most examples, not all).  
You could add the unique code in context and the instruction would be the sentence and telling it to extract.
