noamaanMulla-03/transformers-issues huggingface dataset:
Fixing typo in error message.
Author: Narsil
Pull request: yes

# What does this PR do?

<!--
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?

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.

@nielsRogge

<!-- 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:
@NielsRogge friendly ping.
Quality explain
Author: sgugger
Pull request: yes

# What does this PR do?

This PR reorganizes the quality checks by splitting the current `make quality` in two:
- `make quality` is the check on code style
- `make repo-consistency` contains all other general checks on the repo

Similarly in the CI checks, the old `check_repository_consistency` check (that tested links used in the library are on S3 back in the pre-git repo days) performs the checks of `make repo-consistency`, while `check-code-quality` only focuses on the code quality.

In practice, nothing changes for the users of `make fixup`, but users of `make quality` have to remember two different lines:
`make quality` and `make repo-consistency`.

I also have drafted a doc page explaining all those changes and what each check does (for advanced contributors as well as team members), with TODOs of checks I plan to add in the future.

One last future plan I also have is to make the `make repo-consistency` command perform all checks and report all failures at the end (instead of stopping at the first one).

Comments:
Thanks for the extended review @stas00 ! Will rename the page.
how to freeze specific layers of TFbert model and just train a classifier? 
Author: nerses0
Pull request: no

Could someone help me to freeze say first 3 layers of transformers.TFDistilBertModel.from_pretrained('distilbert-base-multilingual-cased'). I've tried recommendations for TF model from [#400](https://github.com/huggingface/transformers/issues/400) but it seems to freeze all layers at once.
Thanks in advance!

Comments:
I googled it, this should be working:

https://colab.research.google.com/drive/1EAVhQGdVvXbCu8gGq0lZ9dOnN4jJtvAj?usp=sharing

@NielsRogge thanks for the help! 

> I googled it, this should be working:
> 
> https://colab.research.google.com/drive/1EAVhQGdVvXbCu8gGq0lZ9dOnN4jJtvAj?usp=sharing


Thank you very much, this is very useful to me
LayoutXLM tokenizer issues after last update
Author: topolskib
Pull request: no

## Environment info
<!-- You can run the command `transformers-cli env` and copy-and-paste its output below.
     Don't forget to fill out the missing fields in that output! -->

- `transformers` version: 4.10.0
- Platform: Darwin-20.4.0-x86_64-i386-64bit
- Python version: 3.7.11
- PyTorch version (GPU?): 1.9.0 (False)
- Tensorflow version (GPU?): 2.4.0 (False)
- 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
@NielsRogge 


**Describe the bug**
I'm using the LayoutXLM. After the last update on huggingface, the tokenizer stopped working correctly.

The problem arises when using:
* [ ] the official example scripts: (give details below)
* [x] my own modified scripts: (give details below)

The tokenizer for `layoutxlm-base` has some mismatched token ids. They exceed the declared tokenizer vocabulary size, and they also have larger ids than the size of the embedding module in model.


**To Reproduce**
Steps to reproduce the behavior:
```
from transformers import AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained('microsoft/layoutxlm-base')
input_ = tokenizer(["foo"], boxes=[[0,0,12,12]], add_special_tokens=True) 
```
This produces
```
ValueError: Id not recognized
```

Tokenization works with `add_special_tokens=True`, but obviously adding special tokens manually causes the model to crash because of too large ids.

**Expected behavior**
Tokenization works with `add_special_tokens=True`, and the model's embeddings are adapted to new changes if necessary.




Comments:
Hi,

See https://github.com/NielsRogge/Transformers-Tutorials/issues/50#issuecomment-960502393

Update: I've restored the `tokenizer_class` attribute of the configuration of LayoutXLM, such that your tokenizer still works as expected.

However, once a new version of Transformers comes out, one can use `LayoutXLMTokenizer`/`LayoutXLMTokenizerFast` and the corresponding `LayoutXLMProcessor`, which allow you to prepare all the data for the model (see PR #14115). 

Thanks. I've just tested the changes and it works.
Add a method for substring(tokens / ids) checking to tokenizers.
Author: qqaatw
Pull request: no

# 🚀 Feature request

Adds a method to tokenizer to check whether a substring(tokens / ids) is included in evidence strings, or furthermore, get the starting and ending positions of the substring(tokens / ids).

The following code is an example for it:

```
from transformers import BertTokenizer

tokenizer = BertTokenizer.from_pretrained("bert-base-uncased")

input_str = ["There is a cute dog.", "There is a cute cat."]
substr = "cute dog"

input_ids = tokenizer(input_str).input_ids
sub_ids = tokenizer.encode(substr, add_special_tokens=False)

print(input_ids, sub_ids) # [[101, 2045, 2003, 1037, 10140, 3899, 1012, 102], [101, 2045, 2003, 1037, 10140, 4937, 1012, 102]] [10140, 3899]

# Added method
is_sub_tokens = tokenizer.is_sub_tokens(input_ids, sub_ids)

print(is_sub_tokens) # [True, False]
```

## Motivation

Some of question answering models require a label indicating whether an answer is included in the evidence strings, by adding this method, we can conveniently acquire this label.

## Your contribution

If no other concern and, I have some time, I'm willing to open a PR for it.

Any thoughts are welcomed :)

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.
I want to understand the source code of transformers. Where should I start? Is there a tutorial link? thank you very much!
Author: limengqigithub
Pull request: no
Labels: name: Migration

I want to understand the source code of transformers. Where should I start? Is there a tutorial link? thank you very much!

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.
Add failing test for ProphetBet batching
Author: deklanw
Pull request: yes

Following suggestion by @patrickvonplaten I created a failing test for this issue https://github.com/huggingface/transformers/issues/13612. It's a little over my head but I think this is what he meant.

I dunno if putting it as a `@slow` test under integration tests was the right choice. But, it seems to work. I sanity checked that this same test passes with T5 and BART (but didn't add the test for them).

Comments:
Hey @deklanw - thanks for the test! It currently fails no? 

@patrickvonplaten yep, it fails



Ok, I think we should try to fix it in this PR then as well :-) I'm a bit under-water at the moment, but I can try to fix it in like 2 weeks

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.
pipeline fill_mask.py - needs to convert input_ids to cpu before calling numpy
Author: huu4ontocord
Pull request: no

https://github.com/huggingface/transformers/blob/b7d264be0d70d5309dbf24a6c7ebba1e073bdda5/src/transformers/pipelines/fill_mask.py#L127

Should be 

tokens = input_ids.cpu().numpy()

```

from transformers import AutoTokenizer, AutoModel, AutoModelForMaskedLM, pipeline
#tokenizer = AutoTokenizer.from_pretrained("google/fnet-base")
#model = AutoModelForMaskedLM.from_pretrained("google/fnet-base").cuda()
tokenizer = AutoTokenizer.from_pretrained("bert-base-uncased")
model = AutoModelForMaskedLM.from_pretrained("bert-base-uncased").cuda().half()
unmasker = pipeline('fill-mask', model=model, tokenizer=tokenizer, device=0)
unmasker("Hello I'm a [MASK] model.")

[
    {"sequence": "hello i'm a new model.", "score": 0.12073223292827606, "token": 351, "token_str": "new"},
    {"sequence": "hello i'm a first model.", "score": 0.08501081168651581, "token": 478, "token_str": "first"},
    {"sequence": "hello i'm a next model.", "score": 0.060546260327100754, "token": 1037, "token_str": "next"},
    {"sequence": "hello i'm a last model.", "score": 0.038265593349933624, "token": 813, "token_str": "last"},
    {"sequence": "hello i'm a sister model.", "score": 0.033868927508592606, "token": 6232, "token_str": "sister"},
]
```
Will produce the right result with the change. But will raise an error without the change:

TypeError: can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.

Comments:
Indeed! Would you like to open a PR to fix this issue?

Maybe after I finish finding some more bugs... I'm looking at fnet and found another bug. I'm tryin to get fnet working in half mode...


Exactly same issue. 

https://colab.research.google.com/drive/1F7XxC1tTVCALBS6X8DEtEPZwXvznuLs7?usp=sharing

Reproducable at Colab.

Don't know just that line is issue, or more big issues are coming...
I'm looking on it too!



Hi,

This was normally fixed on master (well the exact proposed example does not work because the model is `half()` and `softmax` is not implemented for `f16` in PyTorch (you can either use `f32` or override the `_forward` method to cast things back to `f32` after it went through the model.

Does that help ?



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.

This was fixed on master, feel free to reopen.
'list' object has no attribute 'tolist error while using 'deepset/xlm-roberta-large-squad2'
Author: Nahid-tjk
Pull request: no

Hi there,

I am using 'deepset/xlm-roberta-large-squad2' for Question Answering prediction on my own dataset using transformers QuestionAnsweringPipeline. I get the following error and I can't handle it as it has something to do with 'p_mask' in preprocess(self, example, padding, doc_stride, max_question_len, max_seq_len) in transformers/pipelines/question_answering.py. The error that was thrown is:

AttributeError Traceback (most recent call last)
in ()
7 for i in range(len(qa_df)):
----> 9 prediction = QA_obj.predict_answers(qa_df.loc[i,'Question'], qa_df.loc[i,'ID'], [qa_df.loc[i,'Passage']])
10 all_predictions.append(prediction)
11

4 frames
/usr/local/lib/python3.7/dist-packages/transformers/pipelines/question_answering.py in preprocess(self, example, padding, doc_stride, max_question_len, max_seq_len)
314 attention_mask=attention_mask_span_idx,
315 token_type_ids=token_type_ids_span_idx,
--> 316 p_mask=p_mask[span_idx].tolist(),
317 encoding=encoded_inputs[span_idx],
318 # We don't use the rest of the values - and actually

AttributeError: 'list' object has no attribute 'tolist'

Any help would be much appreciated.
Thanks.


Comments:
Probably the same error as #13811, cc'ing @Narsil 

Should be fixed by https://github.com/huggingface/transformers/pull/13873 can you confirm ?

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.
Language model for wav2vec2.0 decoding
Author: EmreOzkose
Pull request: no

Hello, I implemented [wav2vec2.0 code](https://huggingface.co/blog/fine-tune-xlsr-wav2vec2) and a language model is not used for decoding. How can I add a language model (let's say a language model which is trained with KenLM) for decoding?

thanks in advance.

Comments:
Hello, thanks for opening an issue! We try to keep the github issues for bugs/feature requests.
Could you ask your question on the [forum](https://discusss.huggingface.co) instead?

You can ping @patrickvonplaten on the forum as he's the best suited to help you out.

Thanks!

I moved the question to the forum and @patrickvonplaten said that the feature is not supported for now, but will be soon. 
https://discuss.huggingface.co/t/language-model-for-wav2vec2-0-decoding/4434

I'm now working on this topic full time. 

We will most likely foster a closer collaboration between [pyctcdecode](https://github.com/kensho-technologies/pyctcdecode) and Transformers. [Here](https://github.com/patrickvonplaten/Wav2Vec2_PyCTCDecode) is a github repo that shows how to use `pyctcdecode` with Wav2Vec2 for LM supported decoding. It works quite well with KenLM.
AttributeError: 'T5Config' object has no attribute 'output_scores'
Author: MariamDundua
Pull request: no

## Environment info
<!-- You can run the command `transformers-cli env` and copy-and-paste its output below.
     Don't forget to fill out the missing fields in that output! -->

- `transformers` version:4.12.2

- Platform: Google collab
- Python version:
- PyTorch version (GPU?): Tesla K80
- Tensorflow version (GPU?):
- Using GPU in script?:yes
- Using distributed or parallel set-up in script?:

### Who can help
Text Generation: @patrickvonplaten @TevenLeScao
T5: @patrickvonplaten

## Information

Model I am using T5 base model in order to train in my custom dataset
`model=T5ForConditionalGeneration.from_pretrained(t5-base,return_dict=True)`

After training I want to predict answer  based on QC.

Here is the function which generates prediction of my trained model:
```
def generate_aswer(question,context):
  source_encoding=tokenizer(
    question,
    context,
    max_length=1000,
    padding='max_length',
    truncation='only_second',
    return_attention_mask=True,
    add_special_tokens=True,
    return_tensors='pt')

  generated_ids=model_up.model.generate(
      
      input_ids=source_encoding['input_ids'],
      attention_mask=source_encoding['attention_mask'],
      num_beams=1,
      max_length=400,
      repetition_penalty=2.5,
      length_penalty=1.0,
      early_stopping=True,
      use_cache=True)
  pred=[tokenizer.decode(generated_id,skip_special_tokens=True,clean_up_tokenization_spaces=True) for generated_id in generated_ids]
  return " ".join(pred)   
``` 
where model_up is my trained model.
when I am using question and context in order to predict answer function returns:

`AttributeError: 'T5Config' object has no attribute 'output_scores'`

I week ago this code worked 



Comments:
@MariamDundua May I ask why you are using ```model_up.model.generate``` instead of just ```model_up.generate``` ?
It will be very helpful If you could share the colab link. 😄 

@Atharva-Phatak Here is the  link
[github](https://github.com/MariamDundua/Mariam-Dundua/blob/master/t5_base_training_on_QA.ipynb)


I saw you are using PL. This might help : https://pytorch-lightning.readthedocs.io/en/latest/common/weights_loading.html

This solves the problem
```
from transformers import T5Config
config=T5Config.from_pretrained('t5-base')
model=T5ForConditionalGeneration.from_pretrained(model_t5,config=config)
```
transformers GPT-2 has wrong implementation in scale in Attention class
Author: zixiliuUSC
Pull request: no

https://github.com/openai/gpt-2/blob/a74da5d99abaaba920de8131d64da2862a8f213b/src/model.py#L94
https://github.com/huggingface/transformers/blob/a14d62b0b11e6cb0c64059606e4f8dbf78e40e41/src/transformers/models/gpt2/modeling_gpt2.py#L196

w = w / (float(v.size(-1)) ** 0.5) or w = w * (float(v.size(-1)) ** 0.5) ??

Comments:
@zixiliuUSC  `tf.rsqrt` stands for reciprocal of square root

> @zixiliuUSC `tf.rsqrt` stands for reciprocal of square root
Oh, I see. Thank you so much!
Can't see logger output
Author: parmarsuraj99
Pull request: no

# 🐛 Bug

## Information

Model I am using (Bert, XLNet ...): RoBERTa

Language I am using the model on (English, Chinese ...): Sanskrit

The problem arises when using:
* [x] the official example scripts: (give details below)
* [ ] my own modified scripts: (give details below)

The tasks I am working on is:
* [ ] an official GLUE/SQUaD task: (give the name)
* [x] my own task or dataset: (give details below)

## To reproduce

Steps to reproduce the behavior:

Can't see logger output showing model config and other parameters in Trainer that were printed in training_scripts.

1. 
```
from transformers import Trainer, TrainingArguments

training_args = TrainingArguments(
    output_dir="./model_path",
    overwrite_output_dir=True,
    num_train_epochs=1,
    per_gpu_train_batch_size=128,
    per_gpu_eval_batch_size =256,
    save_steps=1_000,
    save_total_limit=2,
    logging_first_step = True,
    do_train=True,
    do_eval = True,
    evaluate_during_training=True,
    logging_steps = 1000
)

trainer = Trainer(
    model=model,
    args=training_args,
    data_collator=data_collator,
    train_dataset=train_dataset,
    eval_dataset = valid_dataset,
    prediction_loss_only=True,
)
```
2.
```
%%time
trainer.train(model_path="./model_path")
```

Is it It is overriden by tqdm? 
but I can still see `Using deprecated `--per_gpu_train_batch_size` argument which will be removed in a future version. Using `--per_device_train_batch_size` is preferred.`

## Environment info

- `transformers` version: 2.10.0
- Platform: Linux-4.19.104+-x86_64-with-Ubuntu-18.04-bionic
- Python version: 3.6.9
- PyTorch version (GPU?): 1.6.0a0+916084d (False)
- Tensorflow version (GPU?): not installed (NA)
- Using GPU in script?: TPU
- Using distributed or parallel set-up in script?: No



Comments:
Hi, have you tried setting the logging level to `INFO`? You can do so with the following lines:

```py
import logging

logging.basicConfig(level=logging.INFO)
```

It worked! Thanks

Hey, this doesn't log the training progress by trainer.train() into a log file. I want to keep appending the training progress to my log file but all I get are the prints and the parameters info at the end of trainer.train(). What would be a way around to achieve this? @parmarsuraj99 @LysandreJik 

+1

same request. @parmarsuraj99  @LysandreJik 

Share a solution, not so elegant but works. 

I define a new `Callback` function, which logging the logs using the outside logger. And then pass it to the trainer.

```python
class LoggerLogCallback(transformers.TrainerCallback):
    def on_log(self, args, state, control, logs=None, **kwargs):
        control.should_log = False
        _ = logs.pop("total_flos", None)
        if state.is_local_process_zero:
            logger.info(logs) # using your custom logger
```
This problem happend when I train the model
Author: PPPHUB
Pull request: no

`The expanded size of the tensor (824) must match the existing size (512) at non-singleton dimension 1.  Target sizes: [32, 824].  Tensor sizes: [1, 512]`
why this happend and what should I do?

Comments:
We cannot identify the problem without additional context. Please provide the code that can reproduce this error.

Hi,

For training-related questions, please refer to 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.