Repository: huggingface/transformers
Pull request: Fix pipeline tests

# What does this PR do?

As per the title. Fix tests after https://github.com/huggingface/transformers/pull/43195

Changed files:
filename: tests/pipelines/test_pipelines_question_answering.py
patch: @@ -197,20 +197,6 @@ def test_small_model_pt_bf16(self):
 
         self.assertEqual(nested_simplify(outputs), {"score": 0.063, "start": 0, "end": 11, "answer": "HuggingFace"})
 
-    @require_torch
-    def test_small_model_pt_iterator(self):
-        # https://github.com/huggingface/transformers/issues/18510
-        pipe = pipeline(model="sshleifer/tiny-distilbert-base-cased-distilled-squad", batch_size=16)
-
-        def data():
-            for i in range(10):
-                yield {"question": "Where was HuggingFace founded ?", "context": "HuggingFace was founded in Paris."}
-
-        for outputs in pipe(data()):
-            self.assertEqual(
-                nested_simplify(outputs), {"score": 0.063, "start": 0, "end": 11, "answer": "HuggingFace"}
-            )
-
     @require_torch
     def test_small_model_pt_softmax_trick(self):
         question_answerer = pipeline(
@@ -314,45 +300,43 @@ def test_large_model_issue(self):
             model="mrm8488/bert-multi-cased-finetuned-xquadv1",
         )
         outputs = qa_pipeline(
-            {
-                "context": (
-                    "Yes Bank founder Rana Kapoor has approached the Bombay High Court, challenging a special court's"
-                    " order from August this year that had remanded him in police custody for a week in a multi-crore"
-                    " loan fraud case. Kapoor, who is currently lodged in Taloja Jail, is an accused in the loan fraud"
-                    " case and some related matters being probed by the CBI and Enforcement Directorate. A single"
-                    " bench presided over by Justice S K Shinde on Tuesday posted the plea for further hearing on"
-                    " October 14. In his plea filed through advocate Vijay Agarwal, Kapoor claimed that the special"
-                    " court's order permitting the CBI's request for police custody on August 14 was illegal and in"
-                    " breach of the due process of law. Therefore, his police custody and subsequent judicial custody"
-                    " in the case were all illegal. Kapoor has urged the High Court to quash and set aside the special"
-                    " court's order dated August 14. As per his plea, in August this year, the CBI had moved two"
-                    " applications before the special court, one seeking permission to arrest Kapoor, who was already"
-                    " in judicial custody at the time in another case, and the other, seeking his police custody."
-                    " While the special court refused to grant permission to the CBI to arrest Kapoor, it granted the"
-                    " central agency's plea for his custody. Kapoor, however, said in his plea that before filing an"
-                    " application for his arrest, the CBI had not followed the process of issuing him a notice under"
-                    " Section 41 of the CrPC for appearance before it. He further said that the CBI had not taken"
-                    " prior sanction as mandated under section 17 A of the Prevention of Corruption Act for"
-                    " prosecuting him. The special court, however, had said in its order at the time that as Kapoor"
-                    " was already in judicial custody in another case and was not a free man the procedure mandated"
-                    " under Section 41 of the CrPC need not have been adhered to as far as issuing a prior notice of"
-                    " appearance was concerned. ADVERTISING It had also said that case records showed that the"
-                    " investigating officer had taken an approval from a managing director of Yes Bank before"
-                    " beginning the proceedings against Kapoor and such a permission was a valid sanction. However,"
-                    " Kapoor in his plea said that the above order was bad in law and sought that it be quashed and"
-                    " set aside. The law mandated that if initial action was not in consonance with legal procedures,"
-                    " then all subsequent actions must be held as illegal, he said, urging the High Court to declare"
-                    " the CBI remand and custody and all subsequent proceedings including the further custody as"
-                    " illegal and void ab-initio. In a separate plea before the High Court, Kapoor's daughter Rakhee"
-                    " Kapoor-Tandon has sought exemption from in-person appearance before a special PMLA court. Rakhee"
-                    " has stated that she is a resident of the United Kingdom and is unable to travel to India owing"
-                    " to restrictions imposed due to the COVID-19 pandemic. According to the CBI, in the present case,"
-                    " Kapoor had obtained a gratification or pecuniary advantage of ₹ 307 crore, and thereby caused"
-                    " Yes Bank a loss of ₹ 1,800 crore by extending credit facilities to Avantha Group, when it was"
-                    " not eligible for the same"
-                ),
-                "question": "Is this person involved in fraud?",
-            }
+            context=(
+                "Yes Bank founder Rana Kapoor has approached the Bombay High Court, challenging a special court's"
+                " order from August this year that had remanded him in police custody for a week in a multi-crore"
+                " loan fraud case. Kapoor, who is currently lodged in Taloja Jail, is an accused in the loan fraud"
+                " case and some related matters being probed by the CBI and Enforcement Directorate. A single"
+                " bench presided over by Justice S K Shinde on Tuesday posted the plea for further hearing on"
+                " October 14. In his plea filed through advocate Vijay Agarwal, Kapoor claimed that the special"
+                " court's order permitting the CBI's request for police custody on August 14 was illegal and in"
+                " breach of the due process of law. Therefore, his police custody and subsequent judicial custody"
+                " in the case were all illegal. Kapoor has urged the High Court to quash and set aside the special"
+                " court's order dated August 14. As per his plea, in August this year, the CBI had moved two"
+                " applications before the special court, one seeking permission to arrest Kapoor, who was already"
+                " in judicial custody at the time in another case, and the other, seeking his police custody."
+                " While the special court refused to grant permission to the CBI to arrest Kapoor, it granted the"
+                " central agency's plea for his custody. Kapoor, however, said in his plea that before filing an"
+                " application for his arrest, the CBI had not followed the process of issuing him a notice under"
+                " Section 41 of the CrPC for appearance before it. He further said that the CBI had not taken"
+                " prior sanction as mandated under section 17 A of the Prevention of Corruption Act for"
+                " prosecuting him. The special court, however, had said in its order at the time that as Kapoor"
+                " was already in judicial custody in another case and was not a free man the procedure mandated"
+                " under Section 41 of the CrPC need not have been adhered to as far as issuing a prior notice of"
+                " appearance was concerned. ADVERTISING It had also said that case records showed that the"
+                " investigating officer had taken an approval from a managing director of Yes Bank before"
+                " beginning the proceedings against Kapoor and such a permission was a valid sanction. However,"
+                " Kapoor in his plea said that the above order was bad in law and sought that it be quashed and"
+                " set aside. The law mandated that if initial action was not in consonance with legal procedures,"
+                " then all subsequent actions must be held as illegal, he said, urging the High Court to declare"
+                " the CBI remand and custody and all subsequent proceedings including the further custody as"
+                " illegal and void ab-initio. In a separate plea before the High Court, Kapoor's daughter Rakhee"
+                " Kapoor-Tandon has sought exemption from in-person appearance before a special PMLA court. Rakhee"
+                " has stated that she is a resident of the United Kingdom and is unable to travel to India owing"
+                " to restrictions imposed due to the COVID-19 pandemic. According to the CBI, in the present case,"
+                " Kapoor had obtained a gratification or pecuniary advantage of ₹ 307 crore, and thereby caused"
+                " Yes Bank a loss of ₹ 1,800 crore by extending credit facilities to Avantha Group, when it was"
+                " not eligible for the same"
+            ),
+            question="Is this person involved in fraud?",
         )
         self.assertEqual(
             nested_simplify(outputs),

filename: tests/pipelines/test_pipelines_text_classification.py
patch: @@ -72,33 +72,6 @@ def test_small_model_pt(self):
         outputs = text_classifier("This is great !", top_k=1)
         self.assertEqual(nested_simplify(outputs), [{"label": "LABEL_0", "score": 0.504}])
 
-        # Legacy behavior
-        outputs = text_classifier("This is great !", return_all_scores=False)
-        self.assertEqual(nested_simplify(outputs), [{"label": "LABEL_0", "score": 0.504}])
-
-        outputs = text_classifier("This is great !", return_all_scores=True)
-        self.assertEqual(
-            nested_simplify(outputs), [[{"label": "LABEL_0", "score": 0.504}, {"label": "LABEL_1", "score": 0.496}]]
-        )
-
-        outputs = text_classifier(["This is great !", "Something else"], return_all_scores=True)
-        self.assertEqual(
-            nested_simplify(outputs),
-            [
-                [{"label": "LABEL_0", "score": 0.504}, {"label": "LABEL_1", "score": 0.496}],
-                [{"label": "LABEL_0", "score": 0.504}, {"label": "LABEL_1", "score": 0.496}],
-            ],
-        )
-
-        outputs = text_classifier(["This is great !", "Something else"], return_all_scores=False)
-        self.assertEqual(
-            nested_simplify(outputs),
-            [
-                {"label": "LABEL_0", "score": 0.504},
-                {"label": "LABEL_0", "score": 0.504},
-            ],
-        )
-
         # Do not apply any function to output for regression tasks
         # hack: changing problem_type artificially (so keep this test at last)
         text_classifier.model.config.problem_type = "regression"

filename: tests/pipelines/test_pipelines_token_classification.py
patch: @@ -211,15 +211,6 @@ def run_aggregation_strategy(self, model, tokenizer):
             ],
         )
 
-        with self.assertWarns(UserWarning):
-            token_classifier = pipeline(task="ner", model=model, tokenizer=tokenizer, grouped_entities=True)
-        self.assertEqual(token_classifier._postprocess_params["aggregation_strategy"], AggregationStrategy.SIMPLE)
-        with self.assertWarns(UserWarning):
-            token_classifier = pipeline(
-                task="ner", model=model, tokenizer=tokenizer, grouped_entities=True, ignore_subwords=True
-            )
-        self.assertEqual(token_classifier._postprocess_params["aggregation_strategy"], AggregationStrategy.FIRST)
-
     @slow
     @require_torch
     def test_chunking(self):
@@ -925,7 +916,9 @@ def test_pt_ignore_subwords_slow_tokenizer_raises(self):
     @slow
     @require_torch
     def test_simple(self):
-        token_classifier = pipeline(task="ner", model="dslim/bert-base-NER", grouped_entities=True)
+        token_classifier = pipeline(
+            task="ner", model="dslim/bert-base-NER", aggregation_strategy=AggregationStrategy.SIMPLE
+        )
         sentence = "Hello Sarah Jessica Parker who Jessica lives in New York"
         sentence2 = "This is a simple test"
         output = token_classifier(sentence)