noamaanMulla-03/transformers-issues huggingface dataset:
`tokenizer.special_tokens_map` has stringified list for "additional_special_tokens" value.
Author: erip
Pull request: no

## Environment info

- `transformers` version: 4.8.2
- Platform: macOS-10.15.7-x86_64-i386-64bit
- Python version: 3.8.10
- PyTorch version (GPU?): 1.9.0 (False)
- 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?: No
- Using distributed or parallel set-up in script?: No

### Who can help
@LysandreJik maybe?

## Information

Model I am using (Bert, XLNet ...): XLMRoberta

The problem arises when using:
* [ ] the official example scripts: (give details below)
* [X] my own modified scripts: (give details below)

The tasks I am working on is:
* [ ] an official GLUE/SQUaD task: (give the name)
* [ ] my own task or dataset: (give details below)

## To reproduce

Steps to reproduce the behavior:

1. `>>> from transformers import XLMRobertaTokenizer`
2. `>>> m = XLMRobertaTokenizer.from_pretrained('xlm-roberta-base')`
3. `>>> m.add_special_tokens({"additional_special_tokens": ["<space>"]})`
4. `>>> m.special_tokens_map['additional_special_tokens'] == "['<space>']" # True`

## Expected behavior

The value should be a list containing the special characters. :-) The work-around is to use the `additional_special_tokens` attribute directly. 

Comments:
That seems like an issue indeed! Pinging @SaulLu 

Thank you for your issue @erip! This seems to be a bug to me as well, I just opened a PR #12759 that should solve this problem. Now the command:
```python
from transformers import AutoTokenizer
m = AutoTokenizer.from_pretrained('xlm-roberta-base')
m.add_special_tokens({"additional_special_tokens": ["<space>"]})
print(m.special_tokens_map['additional_special_tokens'] == ['<space>'])
```
should output:
```
True
```
Doc - expecting `push_to_hub` method for Tokenizers to be also in the Tokenizer class doc pages
Author: thomwolf
Pull request: no

# 🚀 Doc request

The gist is in the title. I was expecting the doc/docstring for the `push_to_hub` method for Tokenizers to be also in the Tokenizer class doc pages, e.g. on the main `Tokenizer` API landing page: https://huggingface.co/transformers/main_classes/tokenizer.html


Comments:
cc @sgugger
Fix push_to_hub docstring and make it appear in doc
Author: sgugger
Pull request: yes

# What does this PR do?

As pointed out in #12700, the documentation of `psuh_to_hub` was not appearing in the objects like `PretrainedConfig`, `PreTrainedModel` or `PreTrainedTokenzier`. This PR addresses that. It also customizes the documentation for each object (in particular the example) but since I didn't want to make (and maintain) five copies of the docstring, I'm reusing the technique we use for Flax docstrings (copy the method and then adapt its docstring). I think it's okay to have a refactored approach here since it's for the internals of the lib but let me know.

This PR also simplifies the doc page of the tokenizer by using the `special_members` keyword for the methods we want to force to appear even if they are not redefined in the subclass, instead of naming everything in `members`.

Fixes #12700


Comments:
How can we predict story future based on past events?
Author: krigeta
Pull request: no

Hello, is it possible to predict story future events on the basis of past events using transformer?

Comments:
Hi,

Please ask this question on the [forum](https://discuss.huggingface.co/), rather than here. Github issues are mostly for bugs/feature requests.

Thanks.

Okay I will hop there

Hello @NielsRogge, I posted there but I think the forum is not so resposive. so it would be great if you help me with this request.

Please.

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.
Translation example generates the same input
Author: puraminy
Pull request: no

I trained the [translation](https://github.com/huggingface/transformers/tree/master/examples/pytorch/translation ) example, using a custom json file with the format specefied in README. 

It has a bug, I don't know where, but strangely it just generated the same input. For example if you set `--do_predict`, the `generated_predictions.txt` is some of (or in language or format) of inputs. 

Comments:
Hey @puraminy,

Could you provide a reproducible code snippet? Otherwise, it's very difficult to reproduce the error you got.

@patrickvonplaten 

Here is my code on github

https://github.com/puraminy/mt5-comet

you should be able to run `run_trans` in the root folder. You can see my settings there. I also changed `run_translation` a bit to adopt it with my local data. 

The data were also provided there. For test I decreased the number of train and test data in input parameters. I didn't check it recently, but I guess it's the last one with the error I specified above. 
There is another seq2seq task, which follows run_translation, named run_comet. That task is for English 2 English. It also generates the input than target. 
However, for now you can first try `run_trans` and for example check the generated texts by `do_predict`


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.
Create a torchscript version of Tokenizer in Bert
Author: soheilesm
Pull request: no

Hi, 

Not sure if a feature request is a proper flag for the below request: 

I want to create an executable version of Tokenizer for Bert - Below is a small code piece:

```
from transformers import AutoTokenizer, AutoModel
import torch

sentences = ['This framework generates tokens for each input sentence']
tokenizer_model = AutoTokenizer.from_pretrained("sentence-transformers/paraphrase-mpnet-base-v2", torchscript=True)
encoded_input = tokenizer_model(sentences, padding=True, truncation=True, max_length=128, return_tensors='pt')

# !!! complains that 'tokenizer_model' doesn't have eval()
tokenizer_model.eval();    

# !!! tokenizer_model takes list of sentences as inputs, how should I provide tensorial dummpy inputs?
traced_tokenizer_model = torch.jit.trace(tokenizer_model, dummpy_inputs)
torch.jit.save(traced_tokenizer_model, "traced_tokenize_bert.pt")
```
My first problem is that `tokenizer_model` doesn’t have `eval()` - So how I can follow the guideline for creating the traced_models.

My second problem is that the `tokenizer_model` takes as inputs a list of strings. How am I supposed to provide tensorial form dummy inputs to create the `traced_tokenizer_model`?


I have followed the instructions on your page for creating torchscripts but do not know how I can create one for the Tokenizer module above.



Comments:
Hello! I think you're mistaking tokenizers for models. The two are part of the NLP pipeline, but they're very different. The tokenizer prepares the inputs for the model - but it isn't a PyTorch module. It's either plain Python code, or a rust object with a Python wrapper (like it is the case here).

Since it's not a torch module - it doesn't make sense for it to have the `eval` method. Same for your second question, a tokenizer cannot be traced as it's not a torch module.

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.
channel_len specified but not used
Author: PhilipMay
Pull request: no

Here `channel_len` is specified but not used. Smells like a possible bug.

https://github.com/huggingface/transformers/blob/f063c56d942737d2c7aac93895cd8310afd9c7a4/src/transformers/models/ibert/quant_modules.py#L133

Comments:
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.

@LysandreJik or @sgugger could you please check this before it gets closed by the "stale bot"?

cc @kssteven418 

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.
Can't load config for [community model] : DeepESP/gpt2-spanish 
Author: ruanchaves
Pull request: no

## Environment info

- `transformers` version: 3.3.1
- Platform: Linux-4.15.0-135-generic-x86_64-with-Ubuntu-18.04-bionic
- Python version: 3.6.9
- PyTorch version (GPU?): 1.9.0+cu102 (True)
- Tensorflow version (GPU?): not installed (NA)
- Using GPU in script?: Yes
- Using distributed or parallel set-up in script?: No
- 
### Who can help

@julien-c 

@mfuntowicz 

## Information

`DeepESP/gpt2-spanish` is not recognized as a community model. 

Same issue as #6226 and #6688. 

As you can see from previous issues, this was supposedly fixed past year but for some reason this bug is back again.

## To reproduce

```
from transformers import AutoConfig
config = AutoConfig.from_pretrained("DeepESP/gpt2-spanish")
```

This will result in the following error message:

```
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/transformers/configuration_utils.py", line 359, in get_config_dict
    raise EnvironmentError
OSError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.6/dist-packages/transformers/configuration_auto.py", line 310, in from_pretrained
    config_dict, _ = PretrainedConfig.get_config_dict(pretrained_model_name_or_path, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/transformers/configuration_utils.py", line 368, in get_config_dict
    raise EnvironmentError(msg)
OSError: Can't load config for 'DeepESP/gpt2-spanish'. Make sure that:

- 'DeepESP/gpt2-spanish' is a correct model identifier listed on 'https://huggingface.co/models'

- or 'DeepESP/gpt2-spanish' is the correct path to a directory containing a config.json file
```

## Expected behavior

`DeepESP/gpt2-spanish` should be recognized as a community model on `AutoConfig`.

Comments:
Solved by upgrading `transformers` to a higher version.
[Bug?] question answering - end position of each input is weird
Author: woong97
Pull request: no

I run "python run_qa.py" in transformers/examples/pytorch/question-answering.
In prepare_train_features function, I think "end position" is lower than expected postiion.

I tested first example in examples(squad) in "prepare_train_features" function
For example, answer text = 'Saint Bernadette Soubirous'
print(tokenizer(answer_text))
=> return: {'input_ids': [101, 3002, 16595, 9648, 4674, 2061, 12083, 9711, 2271, 102], 'token_type_ids': [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 'attention_mask': [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]}

print(input_ids[tokenized_examples['start_positions'][0]:tokenized_examples['end_positions'][0]])
=> return: [3002, 16595, 9648, 4674, 2061, 12083, 9711]

=> Thus I think last token 2271 is dropped. 

For other input sentences, I think last token is dropped
Isn't it bug??

Comments:
I believe @sgugger worked on that script

Hi there, noticed you closed this so may have come to the same conclusion, but the "end_positions" will give you the position of the last token in the answer. So you should add a +1 in your slice to include that token at "end_positions".

Thank you for your reply.
I recognized my mistakes, thus I closed the issue myself.
Thank you for checking one more time.
Next time, I'll post the issue deliberately!

2021년 7월 16일 (금) 오전 2:13, Sylvain Gugger ***@***.***>님이 작성:

> Hi there, noticed you closed this so may have come to the same conclusion,
> but the "end_positions" will give you the position of the last token in the
> answer. So you should add a +1 in your slice to include that token at
> "end_positions".
>
> —
> You are receiving this because you modified the open/close state.
> Reply to this email directly, view it on GitHub
> <https://github.com/huggingface/transformers/issues/12708#issuecomment-880872726>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AOQH5YFSBA4AWDZPF77K3TLTX4JMJANCNFSM5AL5BOQQ>
> .
>
Error while performing eval on clm using gpt2 in flax
Author: AnantShankhdhar
Pull request: no

## Environment info
- `transformers` version: 4.9.0.dev0
- Platform: Linux-5.4.0-1043-gcp-x86_64-with-glibc2.29
- Python version: 3.8.10
- PyTorch version (GPU?): not installed (NA)
- Tensorflow version (GPU?): not installed (NA)
- Flax version (CPU?/GPU?/TPU?): 0.3.4 (tpu)
- Jax version: 0.2.16
- JaxLib version: 0.1.68
- Using GPU in script?: <fill in>
- Using distributed or parallel set-up in script?: <fill in>

@patrickvonplaten @patil-suraj 



## Information

Model I am using (Bert, XLNet ...):GPT2

The problem arises when using:
* [1 ] the official example scripts: (give details below)
using the examples/flax/language-modeling/run_clm_flax.py
* [ 2] my own modified scripts: (give details below):
a run.sh file of the format -
run.sh --param1 --param2


The tasks I am working on is:
* [ 1] my own task or dataset: (give details below):
* txt file containing rap lyrics starting with <BOS> and ending with <EOS>

## To reproduce

Steps to reproduce the behavior:

1.1.Make a new directory test and change to this directory
2.Add tokenizer.json and config.json from the gpt2 repo from (https://huggingface.co/gpt2/tree/main) to this repository
3.Make a run.sh file of the type run.sh --param1 --param2 and add evaluation parameters such --do_eval and --eval_steps
4.run the file ./run.sh


## Expected behavior
When evaluation occurs you will get the following error:
File "run_clm_flax.py", line 640, in <module>
    main()
  File "run_clm_flax.py", line 609, in main
    eval_metrics = get_metrics(eval_metrics)
  File "/home/anantshankhdhar/RapAiAnant/lib/python3.8/site-packages/flax/training/common_utils.py", line 53, in get_metrics
    return stack_forest(metrics_np)
  File "/home/anantshankhdhar/RapAiAnant/lib/python3.8/site-packages/flax/training/common_utils.py", line 45, in stack_forest
    return jax.tree_multimap(stack_args, *forest)
TypeError: tree_map() missing 1 required positional argument: 'tree'


Comments:
Hey @AnantShankhdhar - could you please provide the `run.sh` file?

The error was because the eval batch size was very high
Get the loss in LongformerForQuestionAnswering for fine-tuning
Author: hanane-djeddal
Pull request: no

Hello,

I'm trying to fine-tune **LongformerForQuestionAnswering** on a custom dataset. I've written a script for training (without using hugging face _Trainer_), and I need the loss of the model for that. On the Longformer docs page, it's written that : 

**loss** (torch.FloatTensor of shape (1,), optional, returned when labels is provided) – Total span extraction loss is the sum of a Cross-Entropy for the start and end positions.

Meaning that the model is supposed to return **loss** when the input _label_ is provided, however, the model takes no such an input (it's not mentioned in the doc, and the model generates an error when passing the input (label=...))

I've noticed that for **LongformerForMaskedLM** this is not an issue since the model does take _label_ as an input. 

I am wondering if there is a way to get the **loss** from LongformerForQuestionAnswering and perhaps to correct this on the docs page. 
Thanks! 


Comments:
In HuggingFace Transformers, `xxxForQuestionAnswering` models don't take a `labels` argument as input. Rather, one should provide `start_positions` and `end_positions`. These indicate which token are the start of the answer, and which token are the end of the answer.

Check out this notebook which showcases how to fine-tune a model for question-answering: https://github.com/huggingface/notebooks/blob/master/examples/question_answering.ipynb



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.
How to access training loss in TrainerCallback?
Author: saikatG
Pull request: no

Hi,

How can i access the current loss in the `on_step` function in `TrainerCallback`?

Comments:
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.
How can I add a CNN layer on top of bert model?
Author: zekaouinoureddine
Pull request: no

### Information
I'm working on a **binary classification task** and used **BERT** model from transformers library to do it using the custom model below:

```python
class BERT(nn.Module):
  def __init__(self):
    super(BERT, self).__init__()
    self.bert = BertModel.from_pretrained(BERT_PATH, return_dict=False)
    self.dropout = nn.Dropout(0.2)
    self.out = nn.Linear(768, 1)

  def forward(self, ids, mask, token_type_ids):
    outputs = self.bert(ids, attention_mask=mask,token_type_ids=token_type_ids)
    
    # Use the pooled output
    output = self.dropout(outputs[1]) 
    return self.out(output)
```
### What I'm looking for?
Now I'm looking to use a `CNN` layer on top of `BERT` with the following configurations to see how my model will perform:

```
self.cnn = nn.Sequential(
        nn.Conv2d(? ? ?),
        nn.ReLU(),
        nn.MaxPool2d(? ? ?)
    )
```

### The problem encountered.
I have already tried but encountered errors regarding setting the dimensions. In your opinion what configuration should I put in the sequential model to avoid the problem of adjusting the dimensions? If you can **copy-paste** my code and offer me the final custom model with the right **Sequential model included**, I will be thankful.

Comments:
Hi,

please ask this question on the [forum](https://discuss.huggingface.co/). We like to keep Github issues for bugs/feature requests.

Thanks. 

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.
Add DETR
Author: NielsRogge
Pull request: yes

# What does this PR do?

It adds Facebook AI's DETR model (end-to-end object detection with Transformers). It's a clean PR based on #11506. 

The 3 models are called `DetrModel`, `DetrForObjectDetection` and `DetrForSegmentation`. The latter was first called `DetrForPanopticSegmentation`, but as it can also be used to do only instance segmentation, I renamed it. 

To do:

- [x] address remaining comments
- [x] fix remaining tests (there are still 2 tests failing for `test_modeling_detr.py`) - here I'd like some help
- [x] add remaining checkpoints to the hub 
- [ ] add notebooks to showcase how to do inference/fine-tuning on custom data
- [x] perhaps also write more documentation

Comments:
@LysandreJik all comments are addressed, also added 2 community notebooks. PR is ready!
Flax MLM: Allow validation split when loading dataset from local file
Author: fgaim
Pull request: yes

# What does this PR do?

In Flax training scripts for MLM, CLM, and T5, this PR enables the option to apply validation-split-percentage when loading datasets from local file. This option already worked when loading standard HF datasets but was missing for local files.


## Who can review?

@patrickvonplaten @patil-suraj 




Comments:
Documentation of longformer model is confusinng
Author: pratikchhapolika
Pull request: no

### Who can help


#Documentation: @sgugger

Models:
- longformer, reformer, transfoxl, xlnet: @patrickvonplaten




Examples:
- maintained examples (not research project or legacy): @sgugger, @patil-suraj

## Information

Model I am using longformer:

The problem arises when using:
* [ ] the official example scripts: (give details below)


```
>>> import torch
>>> from transformers import LongformerModel, LongformerTokenizer

>>> model = LongformerModel.from_pretrained('allenai/longformer-base-4096')
>>> tokenizer = LongformerTokenizer.from_pretrained('allenai/longformer-base-4096')

>>> SAMPLE_TEXT = ' '.join(['Hello world! '] * 1000)  # long input document
>>> input_ids = torch.tensor(tokenizer.encode(SAMPLE_TEXT)).unsqueeze(0)  # batch of size 1

>>> # Attention mask values -- 0: no attention, 1: local attention, 2: global attention
>>> attention_mask = torch.ones(input_ids.shape, dtype=torch.long, device=input_ids.device) # initialize to local attention
>>> global_attention_mask = torch.zeros(input_ids.shape, dtype=torch.long, device=input_ids.device) # initialize to global attention to be deactivated for all tokens
>>> global_attention_mask[:, [1, 4, 21,]] = 1  # Set global attention to random tokens for the sake of this example
...                                     # Usually, set global attention based on the task. For example,
...                                     # classification: the 
 token
...                                     # QA: question tokens
...                                     # LM: potentially on the beginning of sentences and paragraphs
>>> outputs = model(input_ids, attention_mask=attention_mask, global_attention_mask=global_attention_mask)
>>> sequence_output = outputs.last_hidden_state
>>> pooled_output = outputs.pooler_output
```

In the documentation https://huggingface.co/transformers/model_doc/longformer.html#transformers.models.longformer.modeling_longformer.LongformerMaskedLMOutput it's saying 

Mask values selected in [0, 1]:

0 for local attention (a sliding window attention),

1 for global attention (tokens that attend to all other tokens, and all other tokens attend to them).

But in the code and in comment section :

# Attention mask values -- 0: no attention, 1: local attention, 2: global attention

**Why 3 sets of values here??**

`attention_mask = torch.ones(input_ids.shape, dtype=torch.long, device=input_ids.device) # initialize to local attention`

Here all are set to Global attention ( Setting it to 1)

global_attention_mask = torch.zeros(input_ids.shape, dtype=torch.long, device=input_ids.device) # initialize to global attention to be deactivated for all tokens



Comments:
Thanks for the issue! This PR: https://github.com/huggingface/transformers/pull/12809/files fixes the outdated comment.