src->transformers->generation_tf_util.py ->_generate_beam_search->outputs = self(**model_inputs)    why self ?There is not a function?
Author: RyanPeking
Pull request: no
Labels: name: wontfix

Traceback (most recent call last):
  File "D:\Program Files\JetBrains\PyCharm 2018.3.2\helpers\pydev\pydevd.py", line 1741, in <module>
    main()
  File "D:\Program Files\JetBrains\PyCharm 2018.3.2\helpers\pydev\pydevd.py", line 1735, in main
    globals = debugger.run(setup['file'], None, None, is_module)
  File "D:\Program Files\JetBrains\PyCharm 2018.3.2\helpers\pydev\pydevd.py", line 1135, in run
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "D:\Program Files\JetBrains\PyCharm 2018.3.2\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "D:/Github_project/transformers-master/src/transformers/generation_tf_utils.py", line 1128, in <module>
    use_cache = None,
  File "D:/Github_project/transformers-master/src/transformers/generation_tf_utils.py", line 625, in _generate_beam_search
    outputs = self(**model_inputs)  # (batch_size * num_beams, cur_len, vocab_size)
TypeError: 'TFGenerationMixin' object is not callable

Comments:
is self.generate?

Hello! Could you provide all the information relative to your environment as asked in the template, as well as the code that generates the error? Thanks!

Thanks for your replying!

outputs = self(**model_inputs)
This code appear in function _generate_beam_search and  _generate_no_beam_search.
The 'self' is instance of class, it is not callable, so it can be used like this? There is not a function name like self.generate?

Thus, i just test the genaration_tf_util.py, so i add the test code like this. And i delete unrelated code just for test this before 'while cur_len < max_length: model_inputs = self.prepare_inputs_for_generation(
                input_ids, past=past, attention_mask=attention_mask, use_cache=use_cache
            )':

My environment is:
windows
tensorflow               2.0.0rc0
numpy                    1.17.2


```
# my add
# if __name__ == '__main__':
#     a = TFGenerationMixin()
#     a._generate_beam_search(input_ids = None,
#                             cur_len = 10,
#                             max_length = 100,
#                             min_length = 5,
#                             do_sample = None,
#                             early_stopping = None,
#                             # num_beams = None,
#                             temperature = None,
#                             top_k = None,
#                             top_p = None,
#                             repetition_penalty = None,
#                             no_repeat_ngram_size=None,
#                             bad_words_ids = None,
#                             # bos_token_id = None,
#                             pad_token_id = None,
#                             eos_token_id = None,
#                             batch_size=4,
#                             num_return_sequences=None,
#                             length_penalty = None,
#                             num_beams=None,
#                             vocab_size=None,
#                             # no_repeat_ngram_size = None,
#                             # num_return_sequences = None,
#                             encoder_outputs=None,
#                             attention_mask = None,
#                             # decoder_start_token_id = None,
#                             use_cache = None,
#                         )

```

> Hello! Could you provide all the information relative to your environment as asked in the template, as well as the code that generates the error? Thanks!



The `self` is the instance of the class, calling it as `self(...)` results in calling the `__call__` method.

see https://www.geeksforgeeks.org/callable-in-python/

> The `self` is the instance of the class, calling it as `self(...)` results in calling the `__call__` method.

But  where is __call__ method of class TFGenerationMixin?

Ah, my bad, I hadn't taken a close enough look at your code. You can't initialize a `TFGenerationMixin` like this, as it is an abstract class. It is there to have TF classes inherit from that abstract class, not to be used as-is.

Could you tell me what you're trying to do so I could guide you towards the classes you should use?

TFPreTrainedModel inherit from TFGenerationMixin, and TFPreTrainedModel is base class for all TF models. Some TF models have __call__ method, leading to self(..) in TFGenerationMixin can be callable, that's right?

This question appear  just when I read the code, not for do something. 



This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.