# BART Paraphrasing

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fbart-paraphrasing%2F312%3E%5C
**Category:** Beginners\
**Created:** [July 15, 2020, 9:57pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fbart-paraphrasing%2F312 "2020-07-15T21:57:55Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![zanderbush](https://avatars.discourse-cdn.com/v4/letter/z/13edae/32.png) [@zanderbush](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fzanderbush)%5C
**Post date:** [July 15, 2020, 9:57pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fbart-paraphrasing%2F312%2F1 "2020-07-15T21:57:55Z")

</div>

I’ve been using BART to summarize, and I have noticed some of the outputs resembling paraphrases.

Is there a way for me to build on this, and use the model for paraphrasing primarily?

```
from transformers import BartTokenizer, BartForConditionalGeneration, BartConfig
import torch

model = BartForConditionalGeneration.from_pretrained('facebook/bart-large-cnn')
tokenizer = BartTokenizer.from_pretrained('facebook/bart-large-cnn')
device = torch.device('cpu')

text = "At the core of the United States' mismanagement of the Coronavirus lies its distrust of science"

preprocess_text = text.strip().replace("\n","")
t5_prepared_Text = "summarize: "+preprocess_text
print ("original text preprocessed: \n", preprocess_text)

tokenized_text = tokenizer.encode(t5_prepared_Text, return_tensors="pt").to(device)

summary_ids = model.generate(tokenized_text,
                        num_beams=10,
                        no_repeat_ngram_size=1,
                        min_length=10,
                        num_return_sequences = 2,
                        max_length=20,
                        top_k = 100,
                        early_stopping=True)

output = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
output1 = tokenizer.decode(summary_ids[1], skip_special_tokens=True)

```

`Summarized Text: The United States' mismanagement of the Coronavirus is rooted in its distrust of science.`

I’d like to note that when I do “num\_return\_sequences” the answers are the same. That makes sense, but is there a way for me to get separate answers? I don’t believe seed to be built-in with BART.

---

<div class="post-metadata">

**Author:** ![valhalla](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/valhalla/32/4179_2.png) [@valhalla](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fvalhalla)%5C
**Post date:** [July 16, 2020, 5:32am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fbart-paraphrasing%2F312%2F2 "2020-07-16T05:32:07Z")

</div>

hi @zanderbush, sure BART should also work for paraphrasing. Just fine-tune it on a paraphrasing dataset.

There’s a small mistake in the way you are using `.generate`. If you want to do sampling you’ll need to set `num_beams` to 0 and and `do_sample` to `True` . And set `do_sample` to false and `num_beams` to \>1 for beam search. This [post](https://huggingface.co/blog/how-to-generate) explains how to use `generate`

---

<div class="post-metadata">

**Author:** ![zanderbush](https://avatars.discourse-cdn.com/v4/letter/z/13edae/32.png) [@zanderbush](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fzanderbush)%5C
**Post date:** [July 16, 2020, 8:08pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fbart-paraphrasing%2F312%2F3 "2020-07-16T20:08:12Z")

</div>

Thank you! I appreciate your help. I hope I am not probing too much, but I want to make sure I am doing this project in an efficient manner. Would T5 be better suited for paraphrasing?

---

<div class="post-metadata">

**Author:** ![valhalla](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/valhalla/32/4179_2.png) [@valhalla](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fvalhalla)%5C
**Post date:** [July 17, 2020, 4:26am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fbart-paraphrasing%2F312%2F4 "2020-07-17T04:26:27Z")

</div>

I’ve only tried T5 for paraphrasing, but BART should also work, you’ll need to experiment and see what works best for your goal. Here’s a T5 paraphrasing [project](https://madewithml.com/projects/1094/paraphrase-any-question-with-t5-text-to-text-transformer/)

---

<div class="post-metadata">

**Author:** ![Guen](https://avatars.discourse-cdn.com/v4/letter/g/c37758/32.png) [@Guen](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FGuen)%5C
**Post date:** [November 29, 2021, 7:58pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fbart-paraphrasing%2F312%2F5 "2021-11-29T19:58:05Z")

</div>

Hello, @zanderbush, do you have an example of how you implemented the training and data pre-processing for this task? I am looking around, but I’m struggling to find good examples on the topic - thank you in advance!

---

<div class="post-metadata">

**Author:** ![jbmaxwell](https://avatars.discourse-cdn.com/v4/letter/j/5daacb/32.png) [@jbmaxwell](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fjbmaxwell)%5C
**Post date:** [February 18, 2022, 6:06pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fbart-paraphrasing%2F312%2F6 "2022-02-18T18:06:44Z")

</div>

Jumping on this thread a bit, I’m wondering whether a form of paraphrasing might be possible just by doing within-language “translation” and using sampling (top\_k, top\_p, temperature) to reduce the likelihood of simply reproducing exact quotations. Does that make sense, in lieu of an actual paraphrasing dataset? I’m asking because I have a use case where a dataset does not exist.

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![jbmaxwell](https://avatars.discourse-cdn.com/v4/letter/j/5daacb/32.png) [@jbmaxwell](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fjbmaxwell)%5C
**Post date:** [February 18, 2022, 6:09pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fbart-paraphrasing%2F312%2F7 "2022-02-18T18:09:13Z")

</div>

Oh, also @valhalla, would it be possible to re-post the T5 paraphrasing project? That link has died.
