Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions src/transformers/models/reformer/modeling_reformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2377,15 +2377,17 @@ def forward(
>>> tokenizer.add_special_tokens({"mask_token": "[MASK]"}) # doctest: +IGNORE_RESULT
>>> inputs = tokenizer("The capital of France is [MASK].", return_tensors="pt")

>>> # resize model's embedding matrix
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This tiny model checkpoint has some issue. Using fast tokenizer, we get vocab size 1000, while using slow tokenizer, it is 320 (something like that).

This is due to the fact the tiny model creation (the old version) sometimes fail to convert a fast tokenizer to slow tokenizer, and it's not clear to me if the slow tokenizer was uploaded separately after the creation, or if there is something strange and the creation gives a slow tokenizer anyway but with smaller vocab size.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(it's would be better to eventually use the v2 of tiny model creation script though for doctest if necessary)

>>> model.resize_token_embeddings(new_num_tokens=model.config.vocab_size + 1) # doctest: +IGNORE_RESULT

>>> with torch.no_grad():
... logits = model(**inputs).logits

>>> # retrieve index of [MASK]
>>> mask_token_index = (inputs.input_ids == tokenizer.mask_token_id)[0].nonzero(as_tuple=True)[0]

>>> predicted_token_id = logits[0, mask_token_index].argmax(axis=-1)
>>> tokenizer.decode(predicted_token_id)
'it'
>>> predicted_token = tokenizer.decode(predicted_token_id)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

output is random

```

```python
Expand All @@ -2396,8 +2398,7 @@ def forward(
... )

>>> outputs = model(**inputs, labels=labels)
>>> round(outputs.loss.item(), 2)
7.09
>>> loss = round(outputs.loss.item(), 2)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

output is random

```
"""
return_dict = return_dict if return_dict is not None else self.config.use_return_dict
Expand Down Expand Up @@ -2494,8 +2495,7 @@ def forward(
... logits = model(**inputs).logits

>>> predicted_class_id = logits.argmax().item()
>>> model.config.id2label[predicted_class_id]
'LABEL_0'
>>> label = model.config.id2label[predicted_class_id]
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

output is random, as this checkpoint is not seq. classification model.

```

```python
Expand All @@ -2507,8 +2507,6 @@ def forward(

>>> labels = torch.tensor(1)
>>> loss = model(**inputs, labels=labels).loss
>>> round(loss.item(), 2)
0.68
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

output is random, as this checkpoint is not seq. classification model.

```
"""
return_dict = return_dict if return_dict is not None else self.config.use_return_dict
Expand Down