Repository: deepset-ai/haystack

Issue:
Fine-tuning a Model on Your Own Data tutorial throws error
TypeError: forward() got an unexpected keyword argument 'passage_start_t'
a bunch of the parameters in "batch" also seem to throw the same error upon further investigation, such as "start_of_word"
It seems like it is attempting to train a distilbert base like model rather than BertForQuestionAnswering.

TypeError                                 Traceback (most recent call last)
[<ipython-input-7-a4d3bf4506f2>](https://localhost:8080/#) in <module>()
      5 # reader.train(data_dir=data_dir, train_filename="dev-v2.0-test.json", use_gpu=True, n_epochs=1, save_dir="my_model")
      6 # data_dir = "PATH/TO_YOUR/TRAIN_DATA"
----> 7 reader.train(data_dir=data_dir, train_filename="answers.json", use_gpu=True, n_epochs=1, save_dir="my_model")

3 frames
[/usr/local/lib/python3.7/dist-packages/haystack/nodes/reader/farm.py](https://localhost:8080/#) in train(self, data_dir, train_filename, dev_filename, test_filename, use_gpu, devices, batch_size, n_epochs, learning_rate, max_seq_len, warmup_proportion, dev_split, evaluate_every, save_dir, num_processes, use_amp, checkpoint_root_dir, checkpoint_every, checkpoints_to_keep, caching, cache_path)
    419             checkpoints_to_keep=checkpoints_to_keep,
    420             caching=caching,
--> 421             cache_path=cache_path,
    422         )
    423 

[/usr/local/lib/python3.7/dist-packages/haystack/nodes/reader/farm.py](https://localhost:8080/#) in _training_procedure(self, data_dir, train_filename, dev_filename, test_filename, use_gpu, devices, batch_size, n_epochs, learning_rate, max_seq_len, warmup_proportion, dev_split, evaluate_every, save_dir, num_processes, use_amp, checkpoint_root_dir, checkpoint_every, checkpoints_to_keep, teacher_model, teacher_batch_size, caching, cache_path, distillation_loss_weight, distillation_loss, temperature, tinybert, processor)
    325 
    326         # 5. Let it grow!
--> 327         self.inferencer.model = trainer.train()
    328         self.save(Path(save_dir))
    329 

[/usr/local/lib/python3.7/dist-packages/haystack/modeling/training/base.py](https://localhost:8080/#) in train(self)
    289                 batch = {key: batch[key].to(self.device) for key in batch}
    290                 
--> 291                 loss = self.compute_loss(batch, step)
    292 
    293                 # Perform  evaluation

[/usr/local/lib/python3.7/dist-packages/haystack/modeling/training/base.py](https://localhost:8080/#) in compute_loss(self, batch, step)
    373     def compute_loss(self, batch: dict, step: int) -> torch.Tensor:
    374         # Forward & backward pass through model
--> 375         logits = self.model.forward(**batch)
    376         per_sample_loss = self.model.logits_to_loss(logits=logits, global_step=self.global_step, **batch)
    377         return self.backward_propagate(per_sample_loss, step)
TypeError: forward() got an unexpected keyword argument 'passage_start_t'


Discussion:
Hi, @erenaldis could you provide us with the entirety of your code that was used when this error occurred? This will make it easier for us to help debug your problem. 

Additionally, could you provide us with a few example entries of data from your `answers.json` file? 
Hey @erenaldis, we need a bit more information from you to be able to help. So:

- Are you running https://github.com/deepset-ai/haystack/blob/master/tutorials/Tutorial2_Finetune_a_model_on_your_data.ipynb without changes, or did you modify it? 
   - if you didn't modify it, can you provide the link you found the code at? 
   - If you modified it, can you share the code directly?
- Are you running it with the same data provided by the tutorial, or on your data? 
   - If you're using your data, can you share a sample of it?
- Are you executing it locally or on Colab? 
   - If you're running locally, which version of Haystack are you using? 
   - If you're on Colab, is it a GPU environment?

Resolving patch:
diff --git a/haystack/modeling/training/base.py b/haystack/modeling/training/base.py
--- a/haystack/modeling/training/base.py
+++ b/haystack/modeling/training/base.py
@@ -17,6 +17,7 @@
 from haystack.modeling.data_handler.data_silo import DataSilo, DistillationDataSilo
 from haystack.modeling.evaluation.eval import Evaluator
 from haystack.modeling.model.adaptive_model import AdaptiveModel
+from haystack.modeling.model.biadaptive_model import BiAdaptiveModel
 from haystack.modeling.model.optimization import get_scheduler
 from haystack.modeling.utils import GracefulKiller
 from haystack.utils.experiment_tracking import Tracker as tracker
@@ -371,7 +372,24 @@ def train(self):
 
     def compute_loss(self, batch: dict, step: int) -> torch.Tensor:
         # Forward & backward pass through model
-        logits = self.model.forward(**batch)
+        if isinstance(self.model, AdaptiveModel):
+            logits = self.model.forward(
+                input_ids=batch["input_ids"], segment_ids=None, padding_mask=batch["padding_mask"]
+            )
+
+        elif isinstance(self.model, BiAdaptiveModel):
+            logits = self.model.forward(
+                query_input_ids=batch["query_input_ids"],
+                query_segment_ids=batch["query_segment_ids"],
+                query_attention_mask=batch["query_attention_mask"],
+                passage_input_ids=batch["passage_input_ids"],
+                passage_segment_ids=batch["passage_segment_ids"],
+                passage_attention_mask=batch["passage_attention_mask"],
+            )
+
+        else:
+            logits = self.model.forward(**batch)
+
         per_sample_loss = self.model.logits_to_loss(logits=logits, global_step=self.global_step, **batch)
         return self.backward_propagate(per_sample_loss, step)
 
diff --git a/haystack/nodes/retriever/dense.py b/haystack/nodes/retriever/dense.py
--- a/haystack/nodes/retriever/dense.py
+++ b/haystack/nodes/retriever/dense.py
@@ -26,7 +26,7 @@
 from haystack.document_stores import BaseDocumentStore
 from haystack.nodes.retriever.base import BaseRetriever
 from haystack.nodes.retriever._embedding_encoder import _EMBEDDING_ENCODERS
-from haystack.modeling.model.language_model import get_language_model
+from haystack.modeling.model.language_model import get_language_model, DPREncoder
 from haystack.modeling.model.biadaptive_model import BiAdaptiveModel
 from haystack.modeling.model.triadaptive_model import TriAdaptiveModel
 from haystack.modeling.model.prediction_head import TextSimilarityHead
@@ -161,8 +161,10 @@ def __init__(
             use_fast=use_fast_tokenizers,
             use_auth_token=use_auth_token,
         )
-        self.query_encoder = get_language_model(
-            pretrained_model_name_or_path=query_embedding_model, revision=model_version, use_auth_token=use_auth_token
+        self.query_encoder = DPREncoder(
+            pretrained_model_name_or_path=query_embedding_model,
+            model_type="DPRQuestionEncoder",
+            use_auth_token=use_auth_token,
         )
         self.passage_tokenizer = DPRContextEncoderTokenizerFast.from_pretrained(
             pretrained_model_name_or_path=passage_embedding_model,
@@ -171,8 +173,10 @@ def __init__(
             use_fast=use_fast_tokenizers,
             use_auth_token=use_auth_token,
         )
-        self.passage_encoder = get_language_model(
-            pretrained_model_name_or_path=passage_embedding_model, revision=model_version, use_auth_token=use_auth_token
+        self.passage_encoder = DPREncoder(
+            pretrained_model_name_or_path=passage_embedding_model,
+            model_type="DPRContextEncoder",
+            use_auth_token=use_auth_token,
         )
 
         self.processor = TextSimilarityProcessor(


Test patch: