haystack icon indicating copy to clipboard operation
haystack copied to clipboard

Tutorial 13 fails - TranslationWrapperPipeline wrapping QuestionAnswerGenerationPipeline fails to run

Open vblagoje opened this issue 3 years ago • 0 comments

Describe the bug Our recent changes for batching pipeline run support have caused a bug in TranslationWrapperPipeline when a wrapped pipeline is QuestionAnswerGenerationPipeline. This particular use case is demoed in Tutorial 13.

I have traced the bug to formatting_wrapper of the QuestionAnswerGenerationPipeline. The output format of the pipeline has been changed to support batched runs, but it seems that it has caused this issue for non-batched runs.

Error message

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
[/usr/local/lib/python3.7/dist-packages/haystack/pipelines/base.py](https://localhost:8080/#) in run(self, query, file_paths, labels, documents, meta, params, debug)
    508                     logger.debug(f"Running node `{node_id}` with input `{node_input}`")
--> 509                     node_output, stream_id = self.graph.nodes[node_id]["component"]._dispatch_run(**node_input)
    510                 except Exception as e:

6 frames
[/usr/local/lib/python3.7/dist-packages/haystack/nodes/base.py](https://localhost:8080/#) in _dispatch_run(self, **kwargs)
    200         """
--> 201         return self._dispatch_run_general(self.run, **kwargs)
    202 

[/usr/local/lib/python3.7/dist-packages/haystack/nodes/base.py](https://localhost:8080/#) in _dispatch_run_general(self, run_method, **kwargs)
    244 
--> 245         output, stream = run_method(**run_inputs, **run_params)
    246 

[/usr/local/lib/python3.7/dist-packages/haystack/nodes/translator/base.py](https://localhost:8080/#) in run(self, results, query, documents, answers, dict_key)
     62             _dict_key = dict_key or "text"
---> 63             translation_results["documents"] = self.translate(documents=documents, dict_key=_dict_key)  # type: ignore
     64 

[/usr/local/lib/python3.7/dist-packages/haystack/nodes/translator/transformers.py](https://localhost:8080/#) in translate(self, results, query, documents, dict_key)
    115             else:
--> 116                 if not isinstance(documents[0].get(dict_key, None), str):  # type: ignore
    117                     raise AttributeError(f"Dictionary should have {dict_key} key and it's value should be `str` type")

AttributeError: 'list' object has no attribute 'get'

Expected behavior The tutorial should finish without errors

To Reproduce Run Tutorial 13

vblagoje avatar Aug 05 '22 14:08 vblagoje

The reason for this bug is that the QuestionAnswerGenerationPipeline overwrites the reader's run method with its run_batch method. The reader's run_batch output, however, is not compatible with the translator's run method. We need to make sure, therefor, that the output_translator of the TranslationWrapperPipeline uses the run_batch method instead of run in case it is wrapped around a QuestionAnswerGenerationPipeline.

bogdankostic avatar Aug 12 '22 14:08 bogdankostic