# Buggy code
def __init__(
    self,
    tokenizer,
    max_seq_len,
    data_dir,
    label_list=None,
    metric=None,
    train_filename="train.tsv",
    dev_filename=None,
    test_filename="test.tsv",
    dev_split=0.1,
    delimiter="\t",
    quote_char="'",
    skiprows=None,
    label_column_name="label",
    multilabel=False,
    header=0,
    **kwargs,
):
    # TODO If an arg is misspelt, e.g. metrics, it will be swallowed silently by kwargs

    # Custom processor attributes
    self.delimiter = delimiter
    self.quote_char = quote_char
    self.skiprows = skiprows
    self.header = header

    super(TextClassificationProcessor, self).__init__(
        tokenizer=tokenizer,
        max_seq_len=max_seq_len,
        train_filename=train_filename,
        dev_filename=dev_filename,
        test_filename=test_filename,
        dev_split=dev_split,
        data_dir=data_dir,
        tasks={},
    )
    # TODO raise info when no task is added due to missing "metric" or "labels" arg
    if metric and label_list:
        if multilabel:
            task_type = "multilabel_classification"
        else:
            task_type = "classification"
        self.add_task(
            name="text_classification",
            metric=metric,
            label_list=label_list,
            label_column_name=label_column_name,
            task_type=task_type,
        )


# Traceback (KeyError)
10/17/2019 20:16:51 - INFO - pytorch_transformers.modeling_utils -   load
ing weights file https://s3.amazonaws.com/models.huggingface.co/bert/bert
-base-cased-pytorch_model.bin from cache at /root/.cache/torch/pytorch_tr
ansformers/35d8b9d36faaf46728a0192d82bf7d00137490cd6074e8500778afed552a67
e5.3fadbea36527ae472139fe84cddaa65454d7429f12d543d80bfc3ad70de55ac2
10/17/2019 20:16:54 - WARNING - farm.modeling.language_model -   Could no
t automatically detect from language model name what language it is.
We guess it's an *ENGLISH* model ...
If not: Init the language model by supplying the 'language' param.
Example: Bert.load('my_mysterious_model_name', language='de')
10/17/2019 20:16:58 - INFO - farm.modeling.optimization -   Number of opt
imization steps: 12220
Traceback (most recent call last):
File "run_all_experiments.py", line 36, in <module>
main()
File "run_all_experiments.py", line 33, in main
run_experiment(experiment)
File "/home/user/farm/experiment.py", line 147, in run_experiment
model = trainer.train(model)
File "/home/user/farm/train.py", line 129, in train
model.connect_heads_with_processor(self.data_silo.processor.tasks)
File "/home/user/farm/modeling/adaptive_model.py", line 233, in connect
_heads_with_processor
head.label_tensor_name = tasks[head.task_name]["label_tensor_name"]
KeyError: 'question_answering'

# Fixed code
def __init__(
    self,
    tokenizer,
    max_seq_len,
    data_dir,
    label_list=None,
    metric=None,
    train_filename="train.tsv",
    dev_filename=None,
    test_filename="test.tsv",
    dev_split=0.1,
    delimiter="\t",
    quote_char="'",
    skiprows=None,
    label_column_name="label",
    multilabel=False,
    header=0,
    **kwargs,
):
    # TODO If an arg is misspelt, e.g. metrics, it will be swallowed silently by kwargs

    # Custom processor attributes
    self.delimiter = delimiter
    self.quote_char = quote_char
    self.skiprows = skiprows
    self.header = header

    super(TextClassificationProcessor, self).__init__(
        tokenizer=tokenizer,
        max_seq_len=max_seq_len,
        train_filename=train_filename,
        dev_filename=dev_filename,
        test_filename=test_filename,
        dev_split=dev_split,
        data_dir=data_dir,
        tasks={},
    )
    # TODO raise info when no task is added due to missing "metric" or "labels" arg
    if metric and label_list:
        if multilabel:
            task_type = "multilabel_classification"
        else:
            task_type = "classification"
        self.add_task(
            name="text_classification",
            metric=metric,
            label_list=label_list,
            label_column_name=label_column_name,
            task_type=task_type,
        )
    else:
        logger.info(
            "Initialized processor without tasks. Supply `metric` and `label_list` to the constructor for "
            "using the default task or add a custom task later via processor.add_task()"
        )