docs: update BART model card to remove deprecated summarization pipeline usage

#99
Files changed (1) hide show
  1. README.md +24 -4
README.md CHANGED
@@ -61,12 +61,17 @@ You can use this model for text summarization.
61
 
62
  ### How to use
63
 
64
- Here is how to use this model with the [pipeline API](https://huggingface.co/transformers/main_classes/pipelines.html):
65
 
66
  ```python
67
- from transformers import pipeline
 
68
 
69
- summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
 
 
 
 
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
- print(summarizer(ARTICLE, max_length=130, min_length=30, do_sample=False))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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