noamaanMulla-03/transformers-issues huggingface dataset:
Fix grammar in tokenizer_summary docs
Author: derenrich
Pull request: yes

"to make ensure" is redundant. minor grammar nit.

# What does this PR do?
Fixes typo in docs.
<!--
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.
-->


## Before submitting
- [x] 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.


Comments:
_The documentation is not available anymore as the PR was closed or merged._
TF MT5 embeddings resize
Author: gante
Pull request: yes

# What does this PR do?

Fixes #13839 

In MT5, the `get_output_embeddings()` method does not return a layer, returns a `tf.Tensor` with the weights. As such, `self._get_word_embedding_weight(self.get_output_embeddings())` was failing, as it expected a layer. Since the point of `_get_word_embedding_weight` is to get the weights, added a return for the case where we already have the weights. Also added tests to ensure we don't regress.

Comments:
_The documentation is not available anymore as the PR was closed or merged._
Example script to edit kenlm arpa file does not work correctly in kaggle notebook
Author: R4ZZ3
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! -->

Kaggle Python environment with GPU acceleration
- `transformers` version: 4.12.5
- Platform: Linux-5.10.68+-x86_64-with-debian-bullseye-sid
- Python version: 3.7.12
- PyTorch version (GPU?): 1.9.1 (True)
- Tensorflow version (GPU?): 2.6.2 (True)
- Flax version (CPU?/GPU?/TPU?): 0.3.6 (gpu)
- Jax version: 0.2.25
- JaxLib version: 0.1.70
- Using GPU in script?: No
- Using distributed or parallel set-up in script?: No

### Who can help
@patrickvonplaten 

The problem arises when using:
* [ ] the official example scripts: (give details below) https://huggingface.co/blog/wav2vec2-with-ngram


The tasks I am working on is: Training KenLM and using KenLM with xlsr

## To reproduce

Steps to reproduce the behavior:
At step:
![image](https://user-images.githubusercontent.com/25264037/149226114-7f52e449-f319-4893-97b0-1a1b333b4f99.png)

if I run it like that my output in kenlm.arpa is (count is updated correctly but < /s > line is not added )
![image](https://user-images.githubusercontent.com/25264037/149225404-074f09b7-8ad0-42c2-9a71-44057dcabdae.png)

Once I  change that code above to (Inserting that change as a code block did not make the problem visible, sublime code and kaggle notebook images below)
![image](https://user-images.githubusercontent.com/25264037/149228896-ef8a0893-a16e-47f1-9eb8-9a67ece01aea.png)



![image](https://user-images.githubusercontent.com/25264037/149227673-de309990-3b1f-4d68-9df7-78823095e6c9.png)



I get correct output
![image](https://user-images.githubusercontent.com/25264037/149225552-0b657b14-5ae2-4885-9bac-20261f2e262d.png)


## Expected behavior

<!-- A clear and concise description of what you would expect to happen. -->


Comments:
I see thanks a lot for reporting the problem here! Indeed, the regex I use in the blog is not general enough. I'll change it! Thanks a lot for reporting it here and seems like you solved your problem already :-)

Should be fixed here: https://github.com/huggingface/blog/pull/206

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.

Fixed
Can GPT2DoubleHeadsModel be used for regular next token prediction task without adjusting its head?
Author: h56cho
Pull request: no

Hello,

According to the HuggingFace Transformer's website (https://huggingface.co/transformers/model_doc/gpt2.html#gpt2doubleheadsmodel), **GPT2DoubleHeadsModel** is the GPT2 Model transformer with a language modelling and a multiple-choice classification head on top e.g. for RocStories/SWAG tasks. 

Does this mean that we can use the **GPT2DoubleHeadsModel** for the regular language modelling task (i.e. next word prediction) without modifying its head? or would I need to adjust the head of **GPT2DoubleHeadsModel** if I want to do the next word prediction, since GPT2DoubleHeadsModel is for answering multiple-choice type questions only?

Thank you,


Comments:
You don't need to do anything in order to make it predict the next word. That's what it is. But you may consider finetuning it with your own dataset.

Hello,

Thank you for your reply.
so the **GPT2DoubleHeadsModel** (NOT GPT2LMHeadModel but the DoubleHeadsModel), without any adjustment on its head, can be used for any "non-multiple-choice-based" next token prediction, as well as for the multiple-choice questions?

Thank you,

Edit:
I'm not sure. I did missread the GPT2DoubleHeadsModel.

If GPT2DoubleHeadsModel can process both multiple-choice questions as well as non-multiple-choice next token predictions without any adjustment, why did HuggingFace make 2 different GPT2 models -- GPT2DoubleHeadsModel and GPT2LMHeadModel ?

Can GPT2DoubleHeadsModel process both multiple-choice questions as well as non-multiple-choice next token predictions without any further adjustment(s) [e.g. adjustment on its head, etc,]?

So?
How can I update special token ids?
Author: vitalyshalumov
Pull request: no

I am combining a tokenizer from model A with apretrained model B. 
I want to align special token ids.
I am able to change the token name such as 
 but I cannot change the token id number. 
How can I aproach this problem?

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://discuss.huggingface.co) instead?

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.
Cannot fine-tune google/mobilebert-uncased using native Pytorch
Author: jeffreyyu0602
Pull request: no

## Environment info
- `transformers` version: 4.12.5
- Platform: Linux-4.4.0-210-generic-x86_64-with-glibc2.23
- Python version: 3.9.7
- PyTorch version (GPU?): 1.10.0 (False)
- Tensorflow version (GPU?): 2.4.1 (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
@LysandreJik  @sgugger

## To reproduce

Steps to reproduce the behavior:

1. Follow the "fine-tuning in native PyTorch" section in "Fine-tuning a pretrained model" on the official documentation
2. Replace "bert-base-cased" with "google/mobilebert-uncased"
3. Add max_length=171 argument to tokenize function

## Expected behavior

The model fine-tuned with native PyTorch reach the same accuracy as the model fine-tuned with a Trainer. But instead the accuracy stucks around 50% and even dropped after one epoch.

I am wondering if the huggingface Trainer class used some training techniques that I must add in native PyTorch in order for the model to be properly fine-tuned. I looked into the Trainer class but didn't find anything special. Any help is appreciated.

Comments:
Hi,

For training-related questions, please refer to the forum. See [here](https://discuss.huggingface.co/search?q=mobilebert) for all MobileBERT-related questions for instance.

We like to keep Github issues for bugs/feature requests.

Thank you!

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.
Not able to log training and validation loss to visualise in tensor-board as tfevents?
Author: pratikchhapolika
Pull request: no

I am downloading the model https://huggingface.co/microsoft/Multilingual-MiniLM-L12-H384/tree/main microsoft/Multilingual-MiniLM-L12-H384 and then using it.

Transformer Version: '4.11.3'

I have written the below code:


```
def compute_metrics(eval_pred):
    logits, labels = eval_pred
   

    predictions = np.argmax(logits, axis=-1)
    
    acc = np.sum(predictions == labels) / predictions.shape[0]
    
    return {"accuracy" : acc}
```

```
model = tr.BertForSequenceClassification.from_pretrained("/home/pc/minilm_model",num_labels=2)
model.to(device)

print("hello")

training_args = tr.TrainingArguments(
    output_dir='/home/pc/proj/results2',          # output directory
    num_train_epochs=10,              # total number of training epochs
    per_device_train_batch_size=16,  # batch size per device during training
    per_device_eval_batch_size=32,   # batch size for evaluation
    learning_rate=2e-5,
    warmup_steps=1000,                # number of warmup steps for learning rate scheduler
    weight_decay=0.01,               # strength of weight decay
    logging_dir='./logs',            # directory for storing logs
    logging_steps=1000,
    evaluation_strategy="epoch",
    save_strategy="no"
)


trainer = tr.Trainer(
    model=model,                         # the instantiated 🤗 Transformers model to be trained
    args=training_args,                  # training arguments, defined above
    train_dataset=train_data,         # training dataset
    eval_dataset=val_data,             # evaluation dataset
    compute_metrics=compute_metrics
)

```
Is there way to retrieve my ( **I  want to use tensor-board**) :

1. **Training loss** for every epoch
2. **Validation loss** for every epoch

I do not see anything in my log directory apart from model arguments which is empty?

**How can I save my Training and validation loss so that tensorboard events captures it.**




Comments:
I am not so sure, but try to run your code **without** `logging_steps=1000,`, it might solve your problem.
You are training your model for 10 epochs but you are telling it to log it at every 1000th epoch.

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.
word_ids method is not available on fast tokenizers when using "prepare_for_model"
Author: ohmeow
Pull request: no

Tokenizer: RoBERTa

```
hf_tokenizer = AutoTokenizer.from_pretrained("roberta-base")
hf_tokenizer.is_fast # = True

```
```
inputs = hf_tokenizer("This is a test")
print(inputs.word_ids())
input_ids = inputs["input_ids"]
```
Returns: `[None, 0, 1, 2, 3, None]`

```
inputs2 = hf_tokenizer.prepare_for_model(input_ids)
print(inputs2.word_ids())
```
Returns this error:
~/miniconda3/envs/blurr/lib/python3.9/site-packages/transformers/tokenization_utils_base.py in word_ids(self, batch_index)
    351         """
    352         if not self._encodings:
--> 353             raise ValueError("word_ids() is not available when using Python-based tokenizers")
    354         return self._encodings[batch_index].word_ids
    355 

ValueError: word_ids() is not available when using Python-based tokenizers

**Expected result**
Both approaches should return `[None, 0, 1, 2, 3, None]`


Comments:
Hi,

The `prepare_for_model` is not a user-facing method, it's recommended to just call the tokenizer (as in your first code snippet). The `prepare_for_model` method does not set the `_encodings` field of `BatchEncoding` (this is only done in the `_encode_plus` and `_batch_encode_plus` methods of `tokenization_utils_fast.py` (as seen [here](https://github.com/huggingface/transformers/blob/2e9af294940083915ccb2740a7c8d5b154194f15/src/transformers/tokenization_utils_fast.py#L520) and [here](https://github.com/huggingface/transformers/blob/2e9af294940083915ccb2740a7c8d5b154194f15/src/transformers/tokenization_utils_fast.py#L472) respectively).

`prepare_for_model` is the only method that works like calling the tokenizer, but with input_ids as input (which is what several of my pre-processed datasets have). Is there another method call I could use that takes input_ids and includes the ability to add padding, truncation, etc...?

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.
Fix processors
Author: NielsRogge
Pull request: yes

# What does this PR do?

This PR aims to fix import checks for processors of multi-modal models, like those of LayoutLMv2, TrOCR and ViLT.

The bare minimum for a processor is PIL (assuming one creates a processor by combining a feature extractor and a slow tokenizer). If one combines a feature extractor and a fast tokenizer, both PIL and tokenizers should be available.

Questions:
- should I also update the general init file?
- should I add the availability to load both the slow and fast tokenizer to a processor? e.g. ViltProcessor currently only allows the fast one

To do:

- [ ] Fix AutoProcessor API for TrOCR (#14884) 
- [ ] Fix the slow integration tests (by not using the `AutoTokenizer` API in the `from_pretrained` method)

Comments:
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_15280). All of your documentation changes will be reflected on that endpoint.

A much better fix was provided in #15549. Therefore, closing.
Make Swin work with VisionEncoderDecoderModel
Author: NielsRogge
Pull request: yes

# What does this PR do?

This PR sets the `hidden_size` attribute of the config of Swin Transformer, allowing it to be used with the `VisionEncoderDecoderModel` framework.


It also adds an attribute_map to the config of Swin Transformer.

Fixes #15526 

Comments:
_The documentation is not available anymore as the PR was closed or merged._
Report only the failed imports in `requires_backends`
Author: tkukurin
Pull request: yes

# What does this PR do?

Minor QoL improvement. Current checks in `requires_backends` seem to dump all import failures at once even when only a subset fails. This PR just makes it so that only the relevant messages are communicated to the user.

Based on #11100 I think this is the only file that needs changing (no additional doc updates or some such).

## 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?

@LysandreJik 
@sgugger


Comments:
_The documentation is not available anymore as the PR was closed or merged._
Register feature extractor
Author: sgugger
Pull request: yes

# What does this PR do?

This PR adds the register method to `AutoFeatureExtractor`, to allow the user to register their own feature extractor classes, like for models, configurtations and tokenizers (it's based on #15630 so it's better to review this once the other PR is merged).

Comments:
_The documentation is not available anymore as the PR was closed or merged._
How to convert  tf_model.h5 to tf_model.ckpt
Author: kusumlata123
Pull request: no

bert model folder containd these files:

config.json
tf_model.h5
tokenizer_config.json
tokenizer.json
vocab.txt
instead of these if we require these files
 bert_config.json
 bert_model.ckpt.data-00000-of-00001
 bert_model.ckpt.index
 bert_model.ckpt.meta
 vocab.txt
then how to do this

Comments:
Hey @kusumlata123 👋 

The format you'd like to have BERT in is a TensorFlow 1.x format, which we don't support. There are two possible paths you could follow:
1. Migrate to Tensorflow 2.x, and get full compatibility with our models;
2. Attempt to convert our Keras `.h5` model into a TF 1.x checkpoint (e.g. see [here](https://stackoverflow.com/questions/45466020/how-to-export-keras-h5-to-tensorflow-pb)). However, we have no guarantees this will work :)

I'm closing the issue as there are no actions we can do from our end.
* How to convert pytorch.bin to  *.ckpt files
Author: kusumlata123
Pull request: no
Labels: name: Migration


Model I am using MuRIL BERT 

Language I am using the model on Indian language

bert model folder containd these files:

config.json
tf_model.h5
tokenizer_config.json
tokenizer.json
vocab.txt
instead of these if we require these files
bert_config.json
bert_model.ckpt.data-00000-of-00001
bert_model.ckpt.index
bert_model.ckpt.meta
vocab.txt
then how to do this
 Problem is that 
* How to convert pytorch.bin to  *.ckpt files

Comments:
 i need .ckpt files because in my code , I need these file otherwise I  have to change in my whole code and that will take lot of time

(already replied to in #15490)
Fix ASR pipelines from local directories with wav2vec models that have language models attached
Author: versae
Pull request: yes

# What does this PR do?

Fixes #15589.


## 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://discord.com/channels/879548962464493619/930507803339137024/939885949633064960
- [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).
- [x] 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, @Narsil 


Comments:
_The documentation is not available anymore as the PR was closed or merged._

Sure thing, I'll add the test tomorrow 👍🏼 

@versae you need to protect your test with @require_torch  or @require_pyctcdecode (not sure what was failing)

@Narsil, thanks! Sorry for all the mess with the commits. I'm trying to figure out what's going on. You guys have a pretty serious CI setup and I don't even have a local GPU. I'll mark it as WIP until I think is ready.

@versae No worries, it is indeed a pretty involved test suite.

If you want to run it, you don't need to run it entirely though:

```
RUN_PIPELINE_TESTS=1 pytest -sv tests/test_pipelines_automatic_speech_recognition.py::AutomaticSpeechRecognitionPipelineTests::test_with_local_lm_fast
```
or
```
RUN_PIPELINE_TESTS=1  pytest -sv tests/test_pipelines_automatic_speech_recognition.py
```

These only run on CPU for instance.

Should run only the test you are creating, making it much easier to debug. And don't hesitate to ask for help if you don't understand what's happening the `@require` are easy to miss, and hard to understand once they occur for instance.

Thanks for the PR! 

Alright, I think it's ready now. Thanks y'all for all the awesome libraries you open source!
LayoutLMv2Model can not be imported from transformers
Author: yagmur-q
Pull request: no

Hi @NielsRogge 

Getting error when calling LayoutLMv2Model class with `from transformers import LayoutLMv2Model` as instructed at the [official documentation](https://huggingface.co/docs/transformers/model_doc/layoutxlm)

`ImportError: cannot import name 'LayoutLMv2Model' from transformers (unknown location)`


It should be under **transformers/models/layoutlmv2/modeling_layoutlmv2.py**

I have `transformers` version: 4.5.1:



Comments:
The issue has been resolved. LayoutLMv2Model class exist in `transformers=4.16.2` version

what about installing from the source 

```
!git clone https://github.com/huggingface/transformers.git
%cd transformers
!pip install -e .
```

i tried to run run_mlm.py but got many errors in importing the modules
Allow custom code for Processors
Author: sgugger
Pull request: yes

# What does this PR do?

This PR allows code for dynamic processors, with the same API as configurations, feature extractors, models and tokenizers.

There needs to be a slight change in the way the `auto_map` field is stored in the dynamic tokenizers: we need to have a dict there like in the other configs. This PR changes the way new dynamic tokenizer configs are saved with backward compatibility to read the legacy formats. This is also checked with a test loading a dynamic tokenizer with the new and old format.

Comments:
_The documentation is not available anymore as the PR was closed or merged._

Very clean! Thanks