# Finetuning BART for Abstractive Text Summarisation

**URL:** <https://discuss.huggingface.co/t/finetuning-bart-for-abstractive-text-summarisation/13430>\
**Category:** Beginners\
**Created:** [January 6, 2022, 11:06am UTC](https://discuss.huggingface.co/t/finetuning-bart-for-abstractive-text-summarisation/13430 "2022-01-06T11:06:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![adhamalhossary](https://avatars.discourse-cdn.com/v4/letter/a/cc9497/32.png) [@adhamalhossary](https://discuss.huggingface.co/u/adhamalhossary)\
**Post date:** [January 6, 2022, 11:06am UTC](https://discuss.huggingface.co/t/finetuning-bart-for-abstractive-text-summarisation/13430/1 "2022-01-06T11:06:07Z")

</div>

Hello All,

I have been stuck on the following for a few days and I would really appreciate some help on this.

I am currently working on an abstractive summarisation project and I am trying to finetune BART on my custom dataset. I used the [finetuning script](https://github.com/huggingface/transformers/blob/master/examples/pytorch/summarization/run_summarization.py) provided by hugging face as follows:

```auto
python run_summarization.py \
    --model_name_or_path facebook/bart-base \
    --do_train \
    --do_eval \
    --do_pred \
    --train_file {train_path} \
    --validation_file {validation_path} \
    --test_file {test_path} \
    --text_column full_text \
    --summary_column summary \
    --output_dir training \
    --overwrite_output_dir \
    --per_device_train_batch_size=4 \
    --per_device_eval_batch_size=4 \
    --num_train_epochs=3 \
    --predict_with_generate \
    --save_steps=500 \
    --logging_first_step=True \
    --logging_steps=500 \
    --eval_steps=500

```

I get promising results from the predictions generated from this training script. I am getting generated summaries of about 100 words each in the generated\_predictions.txt outputted by the script. However, when I try to use the checkpoint of the fine-tuned model to generate further predictions I get terrible results:

```auto
model = BartForConditionalGeneration.from_pretrained('./training')
tokenizer = BartTokenizer.from_pretrained('./training')

max_input_length = 1024
max_target_length = 128

text = {example text of around 500 words}

model_inputs = tokenizer(text, max_length=max_input_length,
                         truncation=True, return_tensors='pt')

pred = model.generate(model_inputs['input_ids'])

tokenizer.decode(pred[0])

```

I get a summary of an incomplete sentence made up of 10-15 words.

I am just really confused as BART has been finetuned and I am getting completely different results relative to predictions made by the training script. My question is how can I use any checkpoint to generate the same results?

---

<div class="post-metadata">

**Author:** ![mahmutc](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/mahmutc/32/52583_2.png) [@mahmutc](https://discuss.huggingface.co/u/mahmutc)\
**Post date:** [September 9, 2024, 1:29pm UTC](https://discuss.huggingface.co/t/finetuning-bart-for-abstractive-text-summarisation/13430/2 "2024-09-09T13:29:47Z")

</div>

I guess you can use the script without do\_train argument.

The following guide uses `BartForConditionalGeneration` as well. I’m not sure adding max\_length makes a difference.

> **[BART](https://huggingface.co/docs/transformers/en/model_doc/bart#transformers.BartForConditionalGeneration.forward.example)**
>
> We’re on a journey to advance and democratize artificial intelligence through open source and open science.

Or you don’t have enough data/example in your training dataset.
