We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
TransformersSummarizer crashes if given long input
If the TransformersSummarizer is given an input that is longer than the model's max_seq_len, an error will be thrown. Instead, I think a warning message should be printed to console and the input text should be truncated so that the Node can still run.
TransformersSummarizer crashes if given long input
If the TransformersSummarizer is given an input that is longer than the model's max_seq_len, an error will be thrown. Instead, I think a warning message should be printed to console and the input text should be truncated so that the Node can still run.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `haystack/summarizer/transformers.py`
Content:
```
1 import logging
2 from typing import List, Optional
3 
4 from transformers import pipeline
5 from transformers.models.auto.modeling_auto import AutoModelForSeq2SeqLM
6 
7 from haystack import Document
8 from haystack.summarizer.base import BaseSummarizer
9 
10 logger = logging.getLogger(__name__)
11 
12 
13 class TransformersSummarizer(BaseSummarizer):
14     """
15         Transformer based model to summarize the documents using the HuggingFace's transformers framework
16 
17         You can use any model that has been fine-tuned on a summarization task. For example:
18         '`bart-large-cnn`', '`t5-small`', '`t5-base`', '`t5-large`', '`t5-3b`', '`t5-11b`'.
19         See the up-to-date list of available models on
20         `huggingface.co/models <https://huggingface.co/models?filter=summarization>`__
21 
22         **Example**
23 
24         ```python
25         |     docs = [Document(text="PG&E stated it scheduled the blackouts in response to forecasts for high winds amid dry conditions."
26         |            "The aim is to reduce the risk of wildfires. Nearly 800 thousand customers were scheduled to be affected by"
27         |            "the shutoffs which were expected to last through at least midday tomorrow.")]
28         |
29         |     # Summarize
30         |     summary = summarizer.predict(
31         |        documents=docs,
32         |        generate_single_summary=True
33         |     )
34         |
35         |     # Show results (List of Documents, containing summary and original text)
36         |     print(summary)
37         |
38         |    [
39         |      {
40         |        "text": "California's largest electricity provider has turned off power to hundreds of thousands of customers.",
41         |        ...
42         |        "meta": {
43         |          "context": "PGE stated it scheduled the blackouts in response to forecasts for high winds amid dry conditions. ..."
44         |              },
45         |        ...
46         |      },
47         ```
48     """
49 
50     def __init__(
51             self,
52             model_name_or_path: str = "google/pegasus-xsum",
53             model_version: Optional[str] = None,
54             tokenizer: Optional[str] = None,
55             max_length: int = 200,
56             min_length: int = 5,
57             use_gpu: int = 0,
58             clean_up_tokenization_spaces: bool = True,
59             separator_for_single_summary: str = " ",
60             generate_single_summary: bool = False,
61     ):
62         """
63         Load a Summarization model from Transformers.
64         See the up-to-date list of available models at
65         https://huggingface.co/models?filter=summarization
66 
67         :param model_name_or_path: Directory of a saved model or the name of a public model e.g.
68                                    'facebook/rag-token-nq', 'facebook/rag-sequence-nq'.
69                                    See https://huggingface.co/models?filter=summarization for full list of available models.
70         :param model_version: The version of model to use from the HuggingFace model hub. Can be tag name, branch name, or commit hash.
71         :param tokenizer: Name of the tokenizer (usually the same as model)
72         :param max_length: Maximum length of summarized text
73         :param min_length: Minimum length of summarized text
74         :param use_gpu: If < 0, then use cpu. If >= 0, this is the ordinal of the gpu to use
75         :param clean_up_tokenization_spaces: Whether or not to clean up the potential extra spaces in the text output
76         :param separator_for_single_summary: If `generate_single_summary=True` in `predict()`, we need to join all docs
77                                              into a single text. This separator appears between those subsequent docs.
78         :param generate_single_summary: Whether to generate a single summary for all documents or one summary per document.
79                                         If set to "True", all docs will be joined to a single string that will then
80                                         be summarized.
81                                         Important: The summary will depend on the order of the supplied documents!
82         """
83 
84         # save init parameters to enable export of component config as YAML
85         self.set_config(
86             model_name_or_path=model_name_or_path, model_version=model_version, tokenizer=tokenizer,
87             max_length=max_length, min_length=min_length, use_gpu=use_gpu,
88             clean_up_tokenization_spaces=clean_up_tokenization_spaces,
89             separator_for_single_summary=separator_for_single_summary, generate_single_summary=generate_single_summary,
90         )
91 
92         # TODO AutoModelForSeq2SeqLM is only necessary with transformers==4.1.1, with newer versions use the pipeline directly
93         if tokenizer is None:
94             tokenizer = model_name_or_path
95         model = AutoModelForSeq2SeqLM.from_pretrained(pretrained_model_name_or_path=model_name_or_path, revision=model_version)
96         self.summarizer = pipeline("summarization", model=model, tokenizer=tokenizer, device=use_gpu)
97         self.max_length = max_length
98         self.min_length = min_length
99         self.clean_up_tokenization_spaces = clean_up_tokenization_spaces
100         self.separator_for_single_summary = separator_for_single_summary
101         self.generate_single_summary = generate_single_summary
102 
103     def predict(self, documents: List[Document], generate_single_summary: Optional[bool] = None) -> List[Document]:
104         """
105         Produce the summarization from the supplied documents.
106         These document can for example be retrieved via the Retriever.
107 
108         :param documents: Related documents (e.g. coming from a retriever) that the answer shall be conditioned on.
109         :param generate_single_summary: Whether to generate a single summary for all documents or one summary per document.
110                                         If set to "True", all docs will be joined to a single string that will then
111                                         be summarized.
112                                         Important: The summary will depend on the order of the supplied documents!
113         :return: List of Documents, where Document.text contains the summarization and Document.meta["context"]
114                  the original, not summarized text
115         """
116 
117         if self.min_length > self.max_length:
118             raise AttributeError("min_length cannot be greater than max_length")
119 
120         if len(documents) == 0:
121             raise AttributeError("Summarizer needs at least one document to produce a summary.")
122 
123         if generate_single_summary is None:
124             generate_single_summary = self.generate_single_summary
125 
126         contexts: List[str] = [doc.text for doc in documents]
127 
128         if generate_single_summary:
129             # Documents order is very important to produce summary.
130             # Different order of same documents produce different summary.
131             contexts = [self.separator_for_single_summary.join(contexts)]
132 
133         summaries = self.summarizer(
134             contexts,
135             min_length=self.min_length,
136             max_length=self.max_length,
137             return_text=True,
138             clean_up_tokenization_spaces=self.clean_up_tokenization_spaces,
139         )
140 
141         result: List[Document] = []
142 
143         for context, summarized_answer in zip(contexts, summaries):
144             cur_doc = Document(text=summarized_answer['summary_text'], meta={"context": context})
145             result.append(cur_doc)
146 
147         return result
148
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/haystack/summarizer/transformers.py b/haystack/summarizer/transformers.py
--- a/haystack/summarizer/transformers.py
+++ b/haystack/summarizer/transformers.py
@@ -1,5 +1,5 @@
 import logging
-from typing import List, Optional
+from typing import List, Optional, Set
 
 from transformers import pipeline
 from transformers.models.auto.modeling_auto import AutoModelForSeq2SeqLM
@@ -99,8 +99,10 @@
         self.clean_up_tokenization_spaces = clean_up_tokenization_spaces
         self.separator_for_single_summary = separator_for_single_summary
         self.generate_single_summary = generate_single_summary
+        self.print_log: Set[str] = set()
 
-    def predict(self, documents: List[Document], generate_single_summary: Optional[bool] = None) -> List[Document]:
+    def predict(self, documents: List[Document], generate_single_summary: Optional[bool] = None,
+                truncation: bool = True) -> List[Document]:
         """
         Produce the summarization from the supplied documents.
         These document can for example be retrieved via the Retriever.
@@ -110,6 +112,7 @@
                                         If set to "True", all docs will be joined to a single string that will then
                                         be summarized.
                                         Important: The summary will depend on the order of the supplied documents!
+        :param truncation: Truncate to a maximum length accepted by the model
         :return: List of Documents, where Document.text contains the summarization and Document.meta["context"]
                  the original, not summarized text
         """
@@ -130,12 +133,25 @@
             # Different order of same documents produce different summary.
             contexts = [self.separator_for_single_summary.join(contexts)]
 
+        encoded_input = self.summarizer.tokenizer(contexts, verbose=False)
+        for input_id in encoded_input['input_ids']:
+            tokens_count: int = len(input_id)
+            if tokens_count > self.summarizer.tokenizer.model_max_length:
+                truncation_warning = "One or more of your input document texts is longer than the specified " \
+                                     f"maximum sequence length for this summarizer model. "\
+                                     f"Generating summary from first {self.summarizer.tokenizer.model_max_length}"\
+                                     f" tokens."
+                if truncation_warning not in self.print_log:
+                    logger.warning(truncation_warning)
+                    self.print_log.add(truncation_warning)
+
         summaries = self.summarizer(
             contexts,
             min_length=self.min_length,
             max_length=self.max_length,
             return_text=True,
             clean_up_tokenization_spaces=self.clean_up_tokenization_spaces,
+            truncation=True,
         )
 
         result: List[Document] = []

{"golden_diff": "diff --git a/haystack/summarizer/transformers.py b/haystack/summarizer/transformers.py\n--- a/haystack/summarizer/transformers.py\n+++ b/haystack/summarizer/transformers.py\n@@ -1,5 +1,5 @@\n import logging\n-from typing import List, Optional\n+from typing import List, Optional, Set\n \n from transformers import pipeline\n from transformers.models.auto.modeling_auto import AutoModelForSeq2SeqLM\n@@ -99,8 +99,10 @@\n         self.clean_up_tokenization_spaces = clean_up_tokenization_spaces\n         self.separator_for_single_summary = separator_for_single_summary\n         self.generate_single_summary = generate_single_summary\n+        self.print_log: Set[str] = set()\n \n-    def predict(self, documents: List[Document], generate_single_summary: Optional[bool] = None) -> List[Document]:\n+    def predict(self, documents: List[Document], generate_single_summary: Optional[bool] = None,\n+                truncation: bool = True) -> List[Document]:\n         \"\"\"\n         Produce the summarization from the supplied documents.\n         These document can for example be retrieved via the Retriever.\n@@ -110,6 +112,7 @@\n                                         If set to \"True\", all docs will be joined to a single string that will then\n                                         be summarized.\n                                         Important: The summary will depend on the order of the supplied documents!\n+        :param truncation: Truncate to a maximum length accepted by the model\n         :return: List of Documents, where Document.text contains the summarization and Document.meta[\"context\"]\n                  the original, not summarized text\n         \"\"\"\n@@ -130,12 +133,25 @@\n             # Different order of same documents produce different summary.\n             contexts = [self.separator_for_single_summary.join(contexts)]\n \n+        encoded_input = self.summarizer.tokenizer(contexts, verbose=False)\n+        for input_id in encoded_input['input_ids']:\n+            tokens_count: int = len(input_id)\n+            if tokens_count > self.summarizer.tokenizer.model_max_length:\n+                truncation_warning = \"One or more of your input document texts is longer than the specified \" \\\n+                                     f\"maximum sequence length for this summarizer model. \"\\\n+                                     f\"Generating summary from first {self.summarizer.tokenizer.model_max_length}\"\\\n+                                     f\" tokens.\"\n+                if truncation_warning not in self.print_log:\n+                    logger.warning(truncation_warning)\n+                    self.print_log.add(truncation_warning)\n+\n         summaries = self.summarizer(\n             contexts,\n             min_length=self.min_length,\n             max_length=self.max_length,\n             return_text=True,\n             clean_up_tokenization_spaces=self.clean_up_tokenization_spaces,\n+            truncation=True,\n         )\n \n         result: List[Document] = []\n", "issue": "TransformersSummarizer crashes if given long input\nIf the TransformersSummarizer is given an input that is longer than the model's max_seq_len, an error will be thrown. Instead, I think a warning message should be printed to console and the input text should be truncated so that the Node can still run.\nTransformersSummarizer crashes if given long input\nIf the TransformersSummarizer is given an input that is longer than the model's max_seq_len, an error will be thrown. Instead, I think a warning message should be printed to console and the input text should be truncated so that the Node can still run.\n", "before_files": [{"content": "import logging\nfrom typing import List, Optional\n\nfrom transformers import pipeline\nfrom transformers.models.auto.modeling_auto import AutoModelForSeq2SeqLM\n\nfrom haystack import Document\nfrom haystack.summarizer.base import BaseSummarizer\n\nlogger = logging.getLogger(__name__)\n\n\nclass TransformersSummarizer(BaseSummarizer):\n    \"\"\"\n        Transformer based model to summarize the documents using the HuggingFace's transformers framework\n\n        You can use any model that has been fine-tuned on a summarization task. For example:\n        '`bart-large-cnn`', '`t5-small`', '`t5-base`', '`t5-large`', '`t5-3b`', '`t5-11b`'.\n        See the up-to-date list of available models on\n        `huggingface.co/models <https://huggingface.co/models?filter=summarization>`__\n\n        **Example**\n\n        ```python\n        |     docs = [Document(text=\"PG&E stated it scheduled the blackouts in response to forecasts for high winds amid dry conditions.\"\n        |            \"The aim is to reduce the risk of wildfires. Nearly 800 thousand customers were scheduled to be affected by\"\n        |            \"the shutoffs which were expected to last through at least midday tomorrow.\")]\n        |\n        |     # Summarize\n        |     summary = summarizer.predict(\n        |        documents=docs,\n        |        generate_single_summary=True\n        |     )\n        |\n        |     # Show results (List of Documents, containing summary and original text)\n        |     print(summary)\n        |\n        |    [\n        |      {\n        |        \"text\": \"California's largest electricity provider has turned off power to hundreds of thousands of customers.\",\n        |        ...\n        |        \"meta\": {\n        |          \"context\": \"PGE stated it scheduled the blackouts in response to forecasts for high winds amid dry conditions. ...\"\n        |              },\n        |        ...\n        |      },\n        ```\n    \"\"\"\n\n    def __init__(\n            self,\n            model_name_or_path: str = \"google/pegasus-xsum\",\n            model_version: Optional[str] = None,\n            tokenizer: Optional[str] = None,\n            max_length: int = 200,\n            min_length: int = 5,\n            use_gpu: int = 0,\n            clean_up_tokenization_spaces: bool = True,\n            separator_for_single_summary: str = \" \",\n            generate_single_summary: bool = False,\n    ):\n        \"\"\"\n        Load a Summarization model from Transformers.\n        See the up-to-date list of available models at\n        https://huggingface.co/models?filter=summarization\n\n        :param model_name_or_path: Directory of a saved model or the name of a public model e.g.\n                                   'facebook/rag-token-nq', 'facebook/rag-sequence-nq'.\n                                   See https://huggingface.co/models?filter=summarization for full list of available models.\n        :param model_version: The version of model to use from the HuggingFace model hub. Can be tag name, branch name, or commit hash.\n        :param tokenizer: Name of the tokenizer (usually the same as model)\n        :param max_length: Maximum length of summarized text\n        :param min_length: Minimum length of summarized text\n        :param use_gpu: If < 0, then use cpu. If >= 0, this is the ordinal of the gpu to use\n        :param clean_up_tokenization_spaces: Whether or not to clean up the potential extra spaces in the text output\n        :param separator_for_single_summary: If `generate_single_summary=True` in `predict()`, we need to join all docs\n                                             into a single text. This separator appears between those subsequent docs.\n        :param generate_single_summary: Whether to generate a single summary for all documents or one summary per document.\n                                        If set to \"True\", all docs will be joined to a single string that will then\n                                        be summarized.\n                                        Important: The summary will depend on the order of the supplied documents!\n        \"\"\"\n\n        # save init parameters to enable export of component config as YAML\n        self.set_config(\n            model_name_or_path=model_name_or_path, model_version=model_version, tokenizer=tokenizer,\n            max_length=max_length, min_length=min_length, use_gpu=use_gpu,\n            clean_up_tokenization_spaces=clean_up_tokenization_spaces,\n            separator_for_single_summary=separator_for_single_summary, generate_single_summary=generate_single_summary,\n        )\n\n        # TODO AutoModelForSeq2SeqLM is only necessary with transformers==4.1.1, with newer versions use the pipeline directly\n        if tokenizer is None:\n            tokenizer = model_name_or_path\n        model = AutoModelForSeq2SeqLM.from_pretrained(pretrained_model_name_or_path=model_name_or_path, revision=model_version)\n        self.summarizer = pipeline(\"summarization\", model=model, tokenizer=tokenizer, device=use_gpu)\n        self.max_length = max_length\n        self.min_length = min_length\n        self.clean_up_tokenization_spaces = clean_up_tokenization_spaces\n        self.separator_for_single_summary = separator_for_single_summary\n        self.generate_single_summary = generate_single_summary\n\n    def predict(self, documents: List[Document], generate_single_summary: Optional[bool] = None) -> List[Document]:\n        \"\"\"\n        Produce the summarization from the supplied documents.\n        These document can for example be retrieved via the Retriever.\n\n        :param documents: Related documents (e.g. coming from a retriever) that the answer shall be conditioned on.\n        :param generate_single_summary: Whether to generate a single summary for all documents or one summary per document.\n                                        If set to \"True\", all docs will be joined to a single string that will then\n                                        be summarized.\n                                        Important: The summary will depend on the order of the supplied documents!\n        :return: List of Documents, where Document.text contains the summarization and Document.meta[\"context\"]\n                 the original, not summarized text\n        \"\"\"\n\n        if self.min_length > self.max_length:\n            raise AttributeError(\"min_length cannot be greater than max_length\")\n\n        if len(documents) == 0:\n            raise AttributeError(\"Summarizer needs at least one document to produce a summary.\")\n\n        if generate_single_summary is None:\n            generate_single_summary = self.generate_single_summary\n\n        contexts: List[str] = [doc.text for doc in documents]\n\n        if generate_single_summary:\n            # Documents order is very important to produce summary.\n            # Different order of same documents produce different summary.\n            contexts = [self.separator_for_single_summary.join(contexts)]\n\n        summaries = self.summarizer(\n            contexts,\n            min_length=self.min_length,\n            max_length=self.max_length,\n            return_text=True,\n            clean_up_tokenization_spaces=self.clean_up_tokenization_spaces,\n        )\n\n        result: List[Document] = []\n\n        for context, summarized_answer in zip(contexts, summaries):\n            cur_doc = Document(text=summarized_answer['summary_text'], meta={\"context\": context})\n            result.append(cur_doc)\n\n        return result\n", "path": "haystack/summarizer/transformers.py"}], "after_files": [{"content": "import logging\nfrom typing import List, Optional, Set\n\nfrom transformers import pipeline\nfrom transformers.models.auto.modeling_auto import AutoModelForSeq2SeqLM\n\nfrom haystack import Document\nfrom haystack.summarizer.base import BaseSummarizer\n\nlogger = logging.getLogger(__name__)\n\n\nclass TransformersSummarizer(BaseSummarizer):\n    \"\"\"\n        Transformer based model to summarize the documents using the HuggingFace's transformers framework\n\n        You can use any model that has been fine-tuned on a summarization task. For example:\n        '`bart-large-cnn`', '`t5-small`', '`t5-base`', '`t5-large`', '`t5-3b`', '`t5-11b`'.\n        See the up-to-date list of available models on\n        `huggingface.co/models <https://huggingface.co/models?filter=summarization>`__\n\n        **Example**\n\n        ```python\n        |     docs = [Document(text=\"PG&E stated it scheduled the blackouts in response to forecasts for high winds amid dry conditions.\"\n        |            \"The aim is to reduce the risk of wildfires. Nearly 800 thousand customers were scheduled to be affected by\"\n        |            \"the shutoffs which were expected to last through at least midday tomorrow.\")]\n        |\n        |     # Summarize\n        |     summary = summarizer.predict(\n        |        documents=docs,\n        |        generate_single_summary=True\n        |     )\n        |\n        |     # Show results (List of Documents, containing summary and original text)\n        |     print(summary)\n        |\n        |    [\n        |      {\n        |        \"text\": \"California's largest electricity provider has turned off power to hundreds of thousands of customers.\",\n        |        ...\n        |        \"meta\": {\n        |          \"context\": \"PGE stated it scheduled the blackouts in response to forecasts for high winds amid dry conditions. ...\"\n        |              },\n        |        ...\n        |      },\n        ```\n    \"\"\"\n\n    def __init__(\n            self,\n            model_name_or_path: str = \"google/pegasus-xsum\",\n            model_version: Optional[str] = None,\n            tokenizer: Optional[str] = None,\n            max_length: int = 200,\n            min_length: int = 5,\n            use_gpu: int = 0,\n            clean_up_tokenization_spaces: bool = True,\n            separator_for_single_summary: str = \" \",\n            generate_single_summary: bool = False,\n    ):\n        \"\"\"\n        Load a Summarization model from Transformers.\n        See the up-to-date list of available models at\n        https://huggingface.co/models?filter=summarization\n\n        :param model_name_or_path: Directory of a saved model or the name of a public model e.g.\n                                   'facebook/rag-token-nq', 'facebook/rag-sequence-nq'.\n                                   See https://huggingface.co/models?filter=summarization for full list of available models.\n        :param model_version: The version of model to use from the HuggingFace model hub. Can be tag name, branch name, or commit hash.\n        :param tokenizer: Name of the tokenizer (usually the same as model)\n        :param max_length: Maximum length of summarized text\n        :param min_length: Minimum length of summarized text\n        :param use_gpu: If < 0, then use cpu. If >= 0, this is the ordinal of the gpu to use\n        :param clean_up_tokenization_spaces: Whether or not to clean up the potential extra spaces in the text output\n        :param separator_for_single_summary: If `generate_single_summary=True` in `predict()`, we need to join all docs\n                                             into a single text. This separator appears between those subsequent docs.\n        :param generate_single_summary: Whether to generate a single summary for all documents or one summary per document.\n                                        If set to \"True\", all docs will be joined to a single string that will then\n                                        be summarized.\n                                        Important: The summary will depend on the order of the supplied documents!\n        \"\"\"\n\n        # save init parameters to enable export of component config as YAML\n        self.set_config(\n            model_name_or_path=model_name_or_path, model_version=model_version, tokenizer=tokenizer,\n            max_length=max_length, min_length=min_length, use_gpu=use_gpu,\n            clean_up_tokenization_spaces=clean_up_tokenization_spaces,\n            separator_for_single_summary=separator_for_single_summary, generate_single_summary=generate_single_summary,\n        )\n\n        # TODO AutoModelForSeq2SeqLM is only necessary with transformers==4.1.1, with newer versions use the pipeline directly\n        if tokenizer is None:\n            tokenizer = model_name_or_path\n        model = AutoModelForSeq2SeqLM.from_pretrained(pretrained_model_name_or_path=model_name_or_path, revision=model_version)\n        self.summarizer = pipeline(\"summarization\", model=model, tokenizer=tokenizer, device=use_gpu)\n        self.max_length = max_length\n        self.min_length = min_length\n        self.clean_up_tokenization_spaces = clean_up_tokenization_spaces\n        self.separator_for_single_summary = separator_for_single_summary\n        self.generate_single_summary = generate_single_summary\n        self.print_log: Set[str] = set()\n\n    def predict(self, documents: List[Document], generate_single_summary: Optional[bool] = None,\n                truncation: bool = True) -> List[Document]:\n        \"\"\"\n        Produce the summarization from the supplied documents.\n        These document can for example be retrieved via the Retriever.\n\n        :param documents: Related documents (e.g. coming from a retriever) that the answer shall be conditioned on.\n        :param generate_single_summary: Whether to generate a single summary for all documents or one summary per document.\n                                        If set to \"True\", all docs will be joined to a single string that will then\n                                        be summarized.\n                                        Important: The summary will depend on the order of the supplied documents!\n        :param truncation: Truncate to a maximum length accepted by the model\n        :return: List of Documents, where Document.text contains the summarization and Document.meta[\"context\"]\n                 the original, not summarized text\n        \"\"\"\n\n        if self.min_length > self.max_length:\n            raise AttributeError(\"min_length cannot be greater than max_length\")\n\n        if len(documents) == 0:\n            raise AttributeError(\"Summarizer needs at least one document to produce a summary.\")\n\n        if generate_single_summary is None:\n            generate_single_summary = self.generate_single_summary\n\n        contexts: List[str] = [doc.text for doc in documents]\n\n        if generate_single_summary:\n            # Documents order is very important to produce summary.\n            # Different order of same documents produce different summary.\n            contexts = [self.separator_for_single_summary.join(contexts)]\n\n        encoded_input = self.summarizer.tokenizer(contexts, verbose=False)\n        for input_id in encoded_input['input_ids']:\n            tokens_count: int = len(input_id)\n            if tokens_count > self.summarizer.tokenizer.model_max_length:\n                truncation_warning = \"One or more of your input document texts is longer than the specified \" \\\n                                     f\"maximum sequence length for this summarizer model. \"\\\n                                     f\"Generating summary from first {self.summarizer.tokenizer.model_max_length}\"\\\n                                     f\" tokens.\"\n                if truncation_warning not in self.print_log:\n                    logger.warning(truncation_warning)\n                    self.print_log.add(truncation_warning)\n\n        summaries = self.summarizer(\n            contexts,\n            min_length=self.min_length,\n            max_length=self.max_length,\n            return_text=True,\n            clean_up_tokenization_spaces=self.clean_up_tokenization_spaces,\n            truncation=True,\n        )\n\n        result: List[Document] = []\n\n        for context, summarized_answer in zip(contexts, summaries):\n            cur_doc = Document(text=summarized_answer['summary_text'], meta={\"context\": context})\n            result.append(cur_doc)\n\n        return result\n", "path": "haystack/summarizer/transformers.py"}]}