File size: 1,069 Bytes
132f714 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | from IPython.display import Image
Image(filename='Self_Attention.png')
# Code to ignore warnings
from transformers.utils import logging
logging.set_verbosity_error()
# Code 1 - Use a pipeline as a high-level helper
from transformers import pipeline
# Code 2 - create a summarizer object
summarizer = pipeline(task="summarization", model="facebook/bart-large-cnn")
text = """BART is a transformer encoder-encoder (seq2seq) model with a bidirectional (BERT-like) encoder and an autoregressive (GPT-like) decoder.
BART is pre-trained by (1) corrupting text with an arbitrary noising function, and (2) learning a model to reconstruct the original text.
BART is particularly effective when fine-tuned for text generation (e.g. summarization, translation) but also works well for comprehension tasks (e.g. text classification, question answering).
This particular checkpoint has been fine-tuned on CNN Daily Mail, a large collection of text-summary pairs."""
Summarize the text. the length here is in tokens
summary = summarizer(text, min_length=10, max_length=100)
summary |