noamaanMulla-03/transformers-issues huggingface dataset:
Unable to call .from_pretrained() for Roberta Model
Author: akku1506
Pull request: no

### Defined a class that inherits from RobertaPretrainedModel

This class is defined to concat image and text embedding

    class XLMRobertaWithImageConcatenationMultiOutputClassifier(RobertaPreTrainedModel):

        def __init__(self,  config_bert , num_labels):

          super(XLMRobertaWithImageConcatenationMultiOutputClassifier, self).__init__(config_bert)
          self.num_labels = num_labels
          self.num_another_labels = num_another_labels
          self.bert = RobertaModel(config_bert)
          self.backbone = models.resnet50(pretrained = False)        
          num_features = self.backbone.fc.in_features
          self.img_hidden_size = 512
          self.pre_classify_hidden = 512        
          self.pre_classify_fc = torch.nn.Linear(config_bert.hidden_size + self.img_hidden_size, self.pre_classify_hidden)
          self.classifier = torch.nn.Linear(self.pre_classify_hidden, num_labels)
          self.apply(self._init_weights)



### Trying to call XLMRobertaWithImageConcatenationMultiOutputClassifier from pretrained

        model = XLMRobertaWithImageConcatenationMultiOutputClassifier.from_pretrained( 'roberta-base', num_labels = NUM_CLASSES)

### Error
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-22-d0dbf641e2da> in <module>
---> 17 model = XLMRobertaWithImageConcatenationMultiOutputClassifier.from_pretrained('roberta-base', num_labels=NUM_CLASSES)

~/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/transformers/modeling_utils.py in from_pretrained(cls, pretrained_model_name_or_path, *model_args, **kwargs)
   1323         else:
   1324             with no_init_weights(_enable=_fast_init):
-> 1325                 model = cls(config, *model_args, **model_kwargs)
   1326 
   1327         if from_pt:

TypeError: __init__() missing 1 required positional argument: 'num_labels'

Is there something I am missing? Despite giving num_labels it still asks for that parameter? Any idea or help would be highly appreciated.


Comments:
Maybe you can try specifying `num_labels` as a positional argument instead of a keyword argument, like the following:

```
model = XLMRobertaWithImageConcatenationMultiOutputClassifier.from_pretrained( 'roberta-base', NUM_CLASSES)
```



Hi!

@qqaatw is right, model_args to `init` should be passed as positional arguments instead as `kwargs`, the `kwargs` are passed to `config` init.

Another way to do this would be to add `num_labels` to configuration and then access that as `config.num_labels` in the model. Then you could pass it as `kwargs` to `from_pretarained`.

@qqaatw you are absolutely correct about not giving num_labels as keyword argument! I finally implemented like @patil-suraj suggested to fetch num_labels and another_num_labels from a configuration.
BertTokenizerFast can not tokenize [MASK] to 4 id
Author: chicuong209
Pull request: no

I'm training a bert model and  bert tokenizer from scratch on my custom dataset. I'm using BertWordPieceTokenizer to train and BertTokenizerFast to load it. But BertTokenizerFast cannot convert [MASK] token to 4 id. When I try to use BertTokenizer, it works but the process of training model is very slow. Here is my code:

```py
from tokenizers import BertWordPieceTokenizer
tokenizer = BertWordPieceTokenizer(
    clean_text=True,
    strip_accents=False,
    lowercase=False,
)
tokenizer.train(
    "./data/bert/training_data.txt",
    vocab_size=30000,
    min_frequency=2,
    show_progress=True,
    special_tokens=["[PAD]", "[UNK]", "[CLS]", "[SEP]", "[MASK]"],
    limit_alphabet=1000,
    wordpieces_prefix="##",
)
from transformers import BertTokenizerFast
tokenizer = BertTokenizerFast(
    vocab_file= "bert_tokenizer/vocab.txt",
    do_lower_case = False,
    max_len=128
)
```
After that I try encode a string with [MASK] token like this
```
tokenizer.encode("Hapi [MASK] cá thát lát rút xương ướp sả 250g")
[2, 5656, 55, 5078, 56, 608, 1829, 730, 789, 906, 1527, 1150, 644, 3]
```
It returns a result that not including id 4 for [MASK] token

Could you please tell me how to fix this problem? Because i'd like to use BertTokenizerFast to boost speed of my training process Thank you.

Comments:
You're loading the `vocab.txt` file and nothing else into the `BertTokenizerFast` so it is unaware of what the special tokens are.

Did you try saving the `tokenizers`' tokenizer object (as a `tokenizer.json` file) and loading that in the `BertTokenizerFast`?

> You're loading the `vocab.txt` file and nothing else into the `BertTokenizerFast` so it is unaware of what the special tokens are.
> 
> Did you try saving the `tokenizers`' tokenizer object (as a `tokenizer.json` file) and loading that in the `BertTokenizerFast`?

Thanks for your response. It works well if I use `BertTokenizerFast.from_pretrained()`
Add FSNER example in research_projects
Author: sayef
Pull request: yes

# What does this PR do?

- This PR adds example code for FSNER (few-shot named entity recognition) using huggingface's `transformers` library.
- Only prediction/inference code is provided, training code will be provided very soon.


## Before submitting
- [ ] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
- [x] Did you read the [contributor guideline](https://github.com/huggingface/transformers/blob/master/CONTRIBUTING.md#start-contributing-pull-requests),
      Pull Request section?
- [x] Was this discussed/approved via a Github issue or the [forum](https://discuss.huggingface.co/)? Please add a link
      to it if that's the case.
https://github.com/huggingface/transformers/pull/13155
- [ ] Did you make sure to update the documentation with your changes? Here are the
      [documentation guidelines](https://github.com/huggingface/transformers/tree/master/docs), and
      [here are tips on formatting docstrings](https://github.com/huggingface/transformers/tree/master/docs#writing-source-documentation).
- [ ] Did you write any new necessary tests?


## Who can review?

@NielsRogge @LysandreJik
Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

<!-- Your PR will be replied to more quickly if you can figure out the right person to tag with @

 If you know how to use git blame, that is the easiest way, otherwise, here is a rough guide of **who to tag**.
 Please tag fewer than 3 people.

Models:

- albert, bert, xlm: @LysandreJik
- blenderbot, bart, marian, pegasus, encoderdecoder,  t5: @patrickvonplaten, @patil-suraj
- longformer, reformer, transfoxl, xlnet: @patrickvonplaten
- fsmt: @stas00
- funnel: @sgugger
- gpt2: @patrickvonplaten, @LysandreJik
- rag: @patrickvonplaten, @lhoestq
- tensorflow: @LysandreJik

Library:

- benchmarks: @patrickvonplaten
- deepspeed: @stas00
- ray/raytune: @richardliaw, @amogkam
- text generation: @patrickvonplaten
- tokenizers: @n1t0, @LysandreJik
- trainer: @sgugger
- pipelines: @LysandreJik

Documentation: @sgugger

HF projects:

- datasets: [different repo](https://github.com/huggingface/datasets)
- rust tokenizers: [different repo](https://github.com/huggingface/tokenizers)

Examples:

- maintained examples (not research project or legacy): @sgugger, @patil-suraj
- research_projects/bert-loses-patience: @JetRunner
- research_projects/distillation: @VictorSanh

 -->


Comments:
Hey @LysandreJik,

Just pinging to have a look at this PR. Branch is same as before, only one more commit I pushed where I add 2 dependencies in  setup.py for using this as a standalone package.
Handle `UnicodeDecodeError` when loading config file
Author: qqaatw
Pull request: yes

# What does this PR do?

This PR handles the `UnicodeDecodeError` mentioned in #13674, providing a better error message.

## Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

@LysandreJik @sgugger 

Comments:
[ASR] Add official ASR CTC example to `examples/pytorch/speech-recognition`
Author: patrickvonplaten
Pull request: yes

This PR adds a generic speech recognition for CTC example. It has been tested for single GPU and distributed training on Common Voice and is being tested on Librispeech currently.

Once `datasets` has https://github.com/huggingface/datasets/pull/2324/files merged and made a new release I will slightly adapt the script to leverage the new audio feature.

A couple of example runs with this script:
- https://huggingface.co/patrickvonplaten/wav2vec2-common_voice-tr-demo
- https://huggingface.co/patrickvonplaten/wav2vec2-common_voice-tr-demo-dist

This example folder should have two additional scripts: 1 for Seq2Seq ASR + 1 for CTC + LM decoding which are left for future work

Comments:
Make assertions only if actually chunking forward
Author: joshdevins
Pull request: yes

This moves the assertion on checking input dimensions into a block that will only be called if the function is actually going to do chunking forward. This is often not the case at inference time and PyTorch tracing a model with this assertion in it leads to a tracing warning.

```
TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!
  input_tensor.shape[chunk_dim] == tensor_shape for input_tensor in input_tensors
```

Comments:
Asking @patrickvonplaten for review as it's on reformer

@LysandreJik This appears when tracing [sentence-transformers/all-MiniLM-L12-v2](https://huggingface.co/sentence-transformers/all-MiniLM-L12-v2), which doesn't seem to be a reformer 🤔 

Hey @joshdevins, 

I'm happy with the PR! Can you rebase to current master - it should fix the failing tests I think. Also could you maybe replace the `assert` statement by `if ... raise ValueError`? We are trying to move away from assert statements :-)
Use torch.unique_consecutive to check elements are same
Author: oToToT
Pull request: yes

# What does this PR do?

We use `torch.unique` here only to check whether every elements have the same value.
Therefore, we can use [`torch.unique_consecutive`](https://pytorch.org/docs/stable/generated/torch.unique_consecutive.html) here.

This function eliminates all but the first element from every consecutive group of equivalent elements.
Like, if we apply this function to `[1, 2, 2, 1]`, it will result in `[1, 2, 1]`.

As you could see, this is enough for checking whether every elements have the same value.

Since `torch.unique_consecutive` do less thing, it is much more faster.
On my computer, it is 25x faster on GPU and 15x faster on CPU.


## Before submitting
- [ ] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
- [x] Did you read the [contributor guideline](https://github.com/huggingface/transformers/blob/master/CONTRIBUTING.md#start-contributing-pull-requests),
      Pull Request section?
- [ ] Was this discussed/approved via a Github issue or the [forum](https://discuss.huggingface.co/)? Please add a link
      to it if that's the case.
- [ ] Did you make sure to update the documentation with your changes? Here are the
      [documentation guidelines](https://github.com/huggingface/transformers/tree/master/docs), and
      [here are tips on formatting docstrings](https://github.com/huggingface/transformers/tree/master/docs#writing-source-documentation).
- [ ] Did you write any new necessary tests?


## Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

@patrickvonplaten

Comments:
Pipeline “zero-shot-classification” gives “TypeError: __call__() takes 2 positional arguments but 3 were given.”
Author: Jcwscience
Pull request: no

- `transformers` version: 4.11.0.dev0
- Platform: Linux-4.9.253-rt168-tegra-aarch64-with-debian-buster-sid
- Python version: 3.6.13
- PyTorch version (GPU?): 1.9.0 (True)
- Tensorflow version (GPU?): not installed (NA)
- Flax version (CPU?/GPU?/TPU?): not installed (NA)
- Jax version: not installed
- JaxLib version: not installed
- Using GPU in script?: (True)
- Using distributed or parallel set-up in script?: (False)

@LysandreJik

## Information

Model I am using (‘facebook/bart-large-mnli’):

The problem arises when using:
the official example scripts: (basically)

```python
from transformers import pipeline

classify=pipeline('zero-shot-classification')

text=("Give me a weather report")
tags=["request_weather", "catch_fire"]

classify(text, tags)
```

The tasks I am working on is:
my own task or dataset:

It’s a bunch of ugly hacks on each other’s shoulders, in a trench coat, masquerading as a Python script.

## To reproduce

Steps to reproduce the behavior:

1. Run script

Result:

```bash
Traceback (most recent call last):
  File "test.py", line 8, in <module>
    classify(text, tags)
TypeError: __call__() takes 2 positional arguments but 3 were given
```

## Expected behavior

Literally anything but this. I am very confused. Please help, very much appreciated, getting gray hairs from this, thanks!


Comments:
Hello, it seems that there is an issue indeed, the argument is not recognized unless it is a keyword argument (cc @Narsil)

You can do the following in order to have your code work:
```py
classify(text, candidate_labels=tags)
```
which will output
```
{'sequence': 'Give me a weather report', 'labels': ['request_weather', 'catch_fire'], 'scores': [0.9743501543998718, 0.02564983256161213]}
```

@LysandreJik Ahh, ok so that’s what was happening. I’ll be curious to know when you find out what caused it. Thanks for the fix!

Hi @Jcwscience ,

There was a bit rework of pipelines to enable new features (GPU streaming most importantly), and this specific call option wasn't tested so we forgot to account for it.

FYI, in return we enabled this:

```python
classify=pipeline('zero-shot-classification', candidate_labels=["request_weather", "catch_fire"])

classify("text")
classify("something")
```

@Narsil 
Makes sense. Happens to my code about 3 times a day. I was honestly thrilled that I wasn't just doing something stupid! Thanks!

We will make a PR to fix that too.

PR is up for review.
Fixing zero-shot backward compatiblity
Author: Narsil
Pull request: yes

# What does this PR do?

Fixes #13697
<!--
Congratulations! You've made it this far! You're not quite done yet though.

Once merged, your PR is going to appear in the release notes with the title you set, so make sure it's a great title that fully reflects the extent of your awesome contribution.

Then, please replace this with a description of the change and which issue is fixed (if applicable). Please also include relevant motivation and context. List any dependencies (if any) that are required for this change.

Once you're done, someone will review your PR shortly (see the section "Who can review?" below to tag some potential reviewers). They may suggest changes to make the code even better. If no one reviewed your PR after a week has passed, don't hesitate to post a new comment @-mentioning the same persons---sometimes notifications get lost.
-->

<!-- Remove if not applicable -->

Fixes # (issue)

## Before submitting
- [ ] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
- [ ] Did you read the [contributor guideline](https://github.com/huggingface/transformers/blob/master/CONTRIBUTING.md#start-contributing-pull-requests),
      Pull Request section?
- [ ] Was this discussed/approved via a Github issue or the [forum](https://discuss.huggingface.co/)? Please add a link
      to it if that's the case.
- [ ] Did you make sure to update the documentation with your changes? Here are the
      [documentation guidelines](https://github.com/huggingface/transformers/tree/master/docs), and
      [here are tips on formatting docstrings](https://github.com/huggingface/transformers/tree/master/docs#writing-source-documentation).
- [ ] Did you write any new necessary tests?


## Who can review?

@LysandreJik

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

<!-- Your PR will be replied to more quickly if you can figure out the right person to tag with @

 If you know how to use git blame, that is the easiest way, otherwise, here is a rough guide of **who to tag**.
 Please tag fewer than 3 people.

Models:

- albert, bert, xlm: @LysandreJik
- blenderbot, bart, marian, pegasus, encoderdecoder,  t5: @patrickvonplaten, @patil-suraj
- longformer, reformer, transfoxl, xlnet: @patrickvonplaten
- fsmt: @stas00
- funnel: @sgugger
- gpt2: @patrickvonplaten, @LysandreJik
- rag: @patrickvonplaten, @lhoestq
- tensorflow: @LysandreJik

Library:

- benchmarks: @patrickvonplaten
- deepspeed: @stas00
- ray/raytune: @richardliaw, @amogkam
- text generation: @patrickvonplaten
- tokenizers: @n1t0, @LysandreJik
- trainer: @sgugger
- pipelines: @LysandreJik

Documentation: @sgugger

HF projects:

- datasets: [different repo](https://github.com/huggingface/datasets)
- rust tokenizers: [different repo](https://github.com/huggingface/tokenizers)

Examples:

- maintained examples (not research project or legacy): @sgugger, @patil-suraj
- research_projects/bert-loses-patience: @JetRunner
- research_projects/distillation: @VictorSanh

 -->

Comments:
Add system-wide requirements to 'transformers-cli env' documentation
Author: merleyc
Pull request: yes

# What does this PR do?

There are requirements that PIL and soundfile have on system-wide dependencies in order to run the command `transformer-cli env`.
This PR adds notes to the documentation about how to solve such system-wide dependencies below:

* Provide command to fix when sndfile library is not found

* Provide command to fix when the required GLIBCXX version is not found or installed

Fixes # 13270


## Before submitting
- [ X ] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
- [ X ] Did you read the [contributor guideline](https://github.com/huggingface/transformers/blob/master/CONTRIBUTING.md#start-contributing-pull-requests),
      Pull Request section?
- [ X ] Was this discussed/approved via a Github issue or the [forum](https://discuss.huggingface.co/)? Please add a link
      to it if that's the case.
It was discussed here: https://github.com/huggingface/transformers/issues/13270
- [ X ] Did you make sure to update the documentation with your changes? Here are the
      [documentation guidelines](https://github.com/huggingface/transformers/tree/master/docs), and
      [here are tips on formatting docstrings](https://github.com/huggingface/transformers/tree/master/docs#writing-source-documentation).
I changed only the documentation file needed.
- [ ] Did you write any new necessary tests?
No applicable to this PR since since it was documentation update only.


## Who can review?

@LysandreJik @sgugger

Comments:
Thank you, @LysandreJik . I opened a new issue considering your feedback.
Should I close this PR?

Thank you!

Yes, this can be closed. Thank you, @merleyc!
Add model card creation snippet to example scripts
Author: gchhablani
Pull request: yes

# What does this PR do?

This PR adds model card creation in case the `push_to_hub` argument is not used.

@patrickvonplaten 

Comments:
Looks good to me - thanks for the PR!

@sgugger Does this look fine? I went over the scripts in `pytorch` examples.

That's great! Can you just run `make style` on your branch to take care of the quality issue?
Autoregressive differentiable decoding? (no teacher forcing nor self-reconstruction)
Author: Ravoxsg
Pull request: no

# 🚀 Feature request

Hi, 

Is there any way to perform autoregressive differentiable decoding? 
As far as I know, for **encoder-decoder models** (e.g., T5, BART), we have the following:
- **.forward()** performs decoding using **teacher forcing**, or in the case of BART, shifts the _input_ids_ to the right if no _decoder_input_ids_ are given in order to do self-reconstruction. In that case the decoding is differentiable but not autoregressive as it uses teacher forcing (or some kind of supervision). 
- **.generate()** enables decoding using **greedy search**, **beam search**, or **top-k sampling**. In that case, the decoding is autoregressive but not differentiable. 

I would like to **_decode differentiably_** by using **plain autoregression**: at each decoding step t, we feed to the decoder the token generated at previous step t-1. By _differentiably_, I mean that we don't take the argmax() to select a single generated token. Rather, we use embeddings weighted by the logits, to get a pseudo-token that we can feed to the decoder at the next step. 
Such a technique of using weighted averages of embeddings as pseudo-tokens has been used in recent research:
https://arxiv.org/abs/1905.05621

We can implement this manually using a for loop over decoding steps calling .forward() at each step, but it is quite slow. 

## Motivation

The motivation behind this feature request is to be able to generate sequences differentiably without supervision, and fast, which can be very useful for several research purposes. 



Comments:
As far as I know, in generation phase, the autoregressive decoding procedures are all implemented in each searching method such as greedy search, meaning that the output embeddings will certainly be sampled by `argmax` or other sampling methods. Besides, the autoregressive decodings are all running in loop statement currently.

I think that implementing a method that solely performs autoregression and makes the output differentiable seems great and feasible, but if the bottleneck in your code is loop statement, this way may have no significant help in performance.

cc @patrickvonplaten 

Yeah currently gradient backprop is not really supported in `transformers` sadly. Think it would require some major changes to implemented this. Feel free to give it a stab! Would also be very interested in knowing how feasible this is in PyTorch!

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the [contributing guidelines](https://github.com/huggingface/transformers/blob/master/CONTRIBUTING.md) are likely to be ignored.