Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from IPython.display import Image
|
| 2 |
+
Image(filename='Self_Attention.png')
|
| 3 |
+
|
| 4 |
+
# Code to ignore warnings
|
| 5 |
+
from transformers.utils import logging
|
| 6 |
+
logging.set_verbosity_error()
|
| 7 |
+
# Code 1 - Use a pipeline as a high-level helper
|
| 8 |
+
from transformers import pipeline
|
| 9 |
+
# Code 2 - create a summarizer object
|
| 10 |
+
summarizer = pipeline(task="summarization", model="facebook/bart-large-cnn")
|
| 11 |
+
text = """BART is a transformer encoder-encoder (seq2seq) model with a bidirectional (BERT-like) encoder and an autoregressive (GPT-like) decoder.
|
| 12 |
+
BART is pre-trained by (1) corrupting text with an arbitrary noising function, and (2) learning a model to reconstruct the original text.
|
| 13 |
+
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).
|
| 14 |
+
This particular checkpoint has been fine-tuned on CNN Daily Mail, a large collection of text-summary pairs."""
|
| 15 |
+
Summarize the text. the length here is in tokens
|
| 16 |
+
summary = summarizer(text, min_length=10, max_length=100)
|
| 17 |
+
summary
|