Repository: deepset-ai/haystack

Issue:
Add type hints to all component `__init__` constructor parameters
**Describe the bug**

We don't specify type hints for many parameters in component constructors. Here is the QuestionGenerator's `__init__` constructor to illustrate this issue:

```
def __init__(
        self,
        model_name_or_path="valhalla/t5-base-e2e-qg",
        model_version=None,
        num_beams=4,
        max_length=256,
        no_repeat_ngram_size=3,
        length_penalty=1.5,
        early_stopping=True,
        split_length=50,
        split_overlap=10,
        use_gpu=True,
        prompt="generate questions:",
        num_queries_per_doc=1,
        sep_token: str = "<sep>",
        batch_size: int = 16,
        progress_bar: bool = True,
        use_auth_token: Optional[Union[str, bool]] = None,
        devices: Optional[List[Union[str, torch.device]]] = None,
    ):
``` 
We specify types for the last five parameters but not other parameters. This inconsistency hasn't caused any major issue yet, but it might, and, after all, it is an inconsistency we should correct. The direct consequence I have discovered is that the generated JSON schema doesn't specify the type property for these parameters. In conclusion, for some properties, the Haystack schema has the type field/property, and for others, it doesn't!

Although there are no obvious failures due to this inconsistency, there are no guarantees there might be some in the future. dC tooling will appreciate having types for each component property.

**Error message**
No error messages were found; there might be silent failures now and in the future.

**Expected behavior**
We should add type hints for all components' __init__ parameters.

**Additional context**
None

**To Reproduce**
Open any Haystack component and view the __init__ method :-)

**FAQ Check**
- [x] Have you had a look at [our new FAQ page](https://haystack.deepset.ai/overview/faq)?

**System:**
 - OS: 
 - GPU/CPU:
 - Haystack version (commit or version number): 
 - DocumentStore:
 - Reader:
 - Retriever:



Discussion:

Resolving patch:
diff --git a/haystack/nodes/extractor/entity.py b/haystack/nodes/extractor/entity.py
--- a/haystack/nodes/extractor/entity.py
+++ b/haystack/nodes/extractor/entity.py
@@ -25,6 +25,7 @@ class EntityExtractor(BaseComponent):
     The entities extracted by this Node will populate Document.entities
 
     :param model_name_or_path: The name of the model to use for entity extraction.
+    :param model_version: The version of the model to use for entity extraction.
     :param use_gpu: Whether to use the GPU or not.
     :param batch_size: The batch size to use for entity extraction.
     :param progress_bar: Whether to show a progress bar or not.
@@ -44,6 +45,7 @@ class EntityExtractor(BaseComponent):
     def __init__(
         self,
         model_name_or_path: str = "dslim/bert-base-NER",
+        model_version: Optional[str] = None,
         use_gpu: bool = True,
         batch_size: int = 16,
         progress_bar: bool = True,
@@ -58,7 +60,7 @@ def __init__(
 
         tokenizer = AutoTokenizer.from_pretrained(model_name_or_path, use_auth_token=use_auth_token)
         token_classifier = AutoModelForTokenClassification.from_pretrained(
-            model_name_or_path, use_auth_token=use_auth_token
+            model_name_or_path, use_auth_token=use_auth_token, revision=model_version
         )
         token_classifier.to(str(self.devices[0]))
         self.model = pipeline(
diff --git a/haystack/nodes/question_generator/question_generator.py b/haystack/nodes/question_generator/question_generator.py
--- a/haystack/nodes/question_generator/question_generator.py
+++ b/haystack/nodes/question_generator/question_generator.py
@@ -31,18 +31,18 @@ class QuestionGenerator(BaseComponent):
 
     def __init__(
         self,
-        model_name_or_path="valhalla/t5-base-e2e-qg",
-        model_version=None,
-        num_beams=4,
-        max_length=256,
-        no_repeat_ngram_size=3,
-        length_penalty=1.5,
-        early_stopping=True,
-        split_length=50,
-        split_overlap=10,
-        use_gpu=True,
-        prompt="generate questions:",
-        num_queries_per_doc=1,
+        model_name_or_path: str = "valhalla/t5-base-e2e-qg",
+        model_version: Optional[str] = None,
+        num_beams: int = 4,
+        max_length: int = 256,
+        no_repeat_ngram_size: int = 3,
+        length_penalty: float = 1.5,
+        early_stopping: bool = True,
+        split_length: int = 50,
+        split_overlap: int = 10,
+        use_gpu: bool = True,
+        prompt: str = "generate questions:",
+        num_queries_per_doc: int = 1,
         sep_token: str = "<sep>",
         batch_size: int = 16,
         progress_bar: bool = True,
@@ -79,7 +79,9 @@ def __init__(
                 f"Multiple devices are not supported in {self.__class__.__name__} inference, "
                 f"using the first device {self.devices[0]}."
             )
-        self.model = AutoModelForSeq2SeqLM.from_pretrained(model_name_or_path, use_auth_token=use_auth_token)
+        self.model = AutoModelForSeq2SeqLM.from_pretrained(
+            model_name_or_path, revision=model_version, use_auth_token=use_auth_token
+        )
         self.model.to(str(self.devices[0]))
         self.tokenizer = AutoTokenizer.from_pretrained(model_name_or_path, use_auth_token=use_auth_token)
         self.num_beams = num_beams
diff --git a/haystack/nodes/retriever/text2sparql.py b/haystack/nodes/retriever/text2sparql.py
--- a/haystack/nodes/retriever/text2sparql.py
+++ b/haystack/nodes/retriever/text2sparql.py
@@ -2,6 +2,8 @@
 
 import logging
 from transformers import BartForConditionalGeneration, BartTokenizer
+
+from haystack.document_stores import BaseKnowledgeGraph
 from haystack.nodes.retriever.base import BaseGraphRetriever
 
 
@@ -16,13 +18,19 @@ class Text2SparqlRetriever(BaseGraphRetriever):
     """
 
     def __init__(
-        self, knowledge_graph, model_name_or_path, top_k: int = 1, use_auth_token: Optional[Union[str, bool]] = None
+        self,
+        knowledge_graph: BaseKnowledgeGraph,
+        model_name_or_path: str = None,
+        model_version: Optional[str] = None,
+        top_k: int = 1,
+        use_auth_token: Optional[Union[str, bool]] = None,
     ):
         """
         Init the Retriever by providing a knowledge graph and a pre-trained BART model
 
         :param knowledge_graph: An instance of BaseKnowledgeGraph on which to execute SPARQL queries.
         :param model_name_or_path: Name of or path to a pre-trained BartForConditionalGeneration model.
+        :param model_version: The version of the model to use for entity extraction.
         :param top_k: How many SPARQL queries to generate per text query.
         :param use_auth_token: The API token used to download private models from Huggingface.
                                If this parameter is set to `True`, then the token generated when running
@@ -35,7 +43,7 @@ def __init__(
         self.knowledge_graph = knowledge_graph
         # TODO We should extend this to any seq2seq models and use the AutoModel class
         self.model = BartForConditionalGeneration.from_pretrained(
-            model_name_or_path, forced_bos_token_id=0, use_auth_token=use_auth_token
+            model_name_or_path, forced_bos_token_id=0, use_auth_token=use_auth_token, revision=model_version
         )
         self.tok = BartTokenizer.from_pretrained(model_name_or_path, use_auth_token=use_auth_token)
         self.top_k = top_k


Test patch: