Summarization
Transformers
PyTorch
TensorFlow
JAX
Rust
Safetensors
English
bart
text2text-generation
Eval Results (legacy)
Instructions to use facebook/bart-large-cnn with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use facebook/bart-large-cnn with Transformers:
# Use a pipeline as a high-level helper # Warning: Pipeline type "summarization" is no longer supported in transformers v5. # You must load the model directly (see below) or downgrade to v4.x with: # 'pip install "transformers<5.0.0' from transformers import pipeline pipe = pipeline("summarization", model="facebook/bart-large-cnn")# Load model directly from transformers import AutoTokenizer, AutoModelForSeq2SeqLM tokenizer = AutoTokenizer.from_pretrained("facebook/bart-large-cnn") model = AutoModelForSeq2SeqLM.from_pretrained("facebook/bart-large-cnn") - Inference
- Notebooks
- Google Colab
- Kaggle
docs: update BART model card to remove deprecated summarization pipeline usage
#99
by kanavbansal - opened
README.md
CHANGED
|
@@ -61,12 +61,17 @@ You can use this model for text summarization.
|
|
| 61 |
|
| 62 |
### How to use
|
| 63 |
|
| 64 |
-
|
| 65 |
|
| 66 |
```python
|
| 67 |
-
from transformers import
|
|
|
|
| 68 |
|
| 69 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
|
| 71 |
ARTICLE = """ New York (CNN)When Liana Barrientos was 23 years old, she got married in Westchester County, New York.
|
| 72 |
A year later, she got married again in Westchester County, but to a different man and without divorcing her first husband.
|
|
@@ -86,7 +91,22 @@ Investigation Division. Seven of the men are from so-called "red-flagged" countr
|
|
| 86 |
Her eighth husband, Rashid Rajput, was deported in 2006 to his native Pakistan after an investigation by the Joint Terrorism Task Force.
|
| 87 |
If convicted, Barrientos faces up to four years in prison. Her next court appearance is scheduled for May 18.
|
| 88 |
"""
|
| 89 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
>>> [{'summary_text': 'Liana Barrientos, 39, is charged with two counts of "offering a false instrument for filing in the first degree" In total, she has been married 10 times, with nine of her marriages occurring between 1999 and 2002. She is believed to still be married to four men.'}]
|
| 91 |
```
|
| 92 |
|
|
|
|
| 61 |
|
| 62 |
### How to use
|
| 63 |
|
| 64 |
+
The following contains a code snippet illustrating how to use the model to summarize on given inputs.
|
| 65 |
|
| 66 |
```python
|
| 67 |
+
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
|
| 68 |
+
from transformers import GenerationConfig
|
| 69 |
|
| 70 |
+
# Load tokenizer
|
| 71 |
+
bart_tokenizer = AutoTokenizer.from_pretrained("facebook/bart-large-cnn")
|
| 72 |
+
|
| 73 |
+
# Load model
|
| 74 |
+
bart_model = AutoModelForSeq2SeqLM.from_pretrained("facebook/bart-large-cnn")
|
| 75 |
|
| 76 |
ARTICLE = """ New York (CNN)When Liana Barrientos was 23 years old, she got married in Westchester County, New York.
|
| 77 |
A year later, she got married again in Westchester County, but to a different man and without divorcing her first husband.
|
|
|
|
| 91 |
Her eighth husband, Rashid Rajput, was deported in 2006 to his native Pakistan after an investigation by the Joint Terrorism Task Force.
|
| 92 |
If convicted, Barrientos faces up to four years in prison. Her next court appearance is scheduled for May 18.
|
| 93 |
"""
|
| 94 |
+
|
| 95 |
+
input_ids_map = bart_tokenizer(ARTICLE, return_tensors="pt")
|
| 96 |
+
|
| 97 |
+
generation_config = GenerationConfig(
|
| 98 |
+
max_new_tokens=130,
|
| 99 |
+
temperature=0.7,
|
| 100 |
+
do_sample=False,
|
| 101 |
+
)
|
| 102 |
+
|
| 103 |
+
output_ids = bart_model.generate(
|
| 104 |
+
**input_ids_map,
|
| 105 |
+
generation_config=generation_config,
|
| 106 |
+
)
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
print(bart_tokenizer.decode(output_ids[0], skip_special_tokens=True))
|
| 110 |
>>> [{'summary_text': 'Liana Barrientos, 39, is charged with two counts of "offering a false instrument for filing in the first degree" In total, she has been married 10 times, with nine of her marriages occurring between 1999 and 2002. She is believed to still be married to four men.'}]
|
| 111 |
```
|
| 112 |
|