Invalid argument:  assertion failed: [Condition x == y did not hold element-wise:] [x (loss/output_1_loss/SparseSoftmaxCrossEntropyWithLogits/Shape_1:0) = ] [32 1] [y (loss/output_1_loss/SparseSoftmaxCrossEntropyWithLogits/strided_slice:0) = ] [32 128]
I'm trying to run TFBertForTokenClassification with tensorflow_datasets.load('glue/sst2'):

```py
import tensorflow as tf
import tensorflow_datasets
from transformers import *

tokenizer = BertTokenizer.from_pretrained('bert-base-uncased')
model = TFBertForTokenClassification.from_pretrained('bert-base-uncased')
data = tensorflow_datasets.load('glue/sst2')

train_dataset = glue_convert_examples_to_features(data['train'], tokenizer, max_length=128, task='sst-2')
valid_dataset = glue_convert_examples_to_features(data['validation'], tokenizer, max_length=128, task='sst-2')
train_dataset = train_dataset.shuffle(100).batch(32).repeat(2)
valid_dataset = valid_dataset.batch(64)

optimizer = tf.keras.optimizers.Adam(learning_rate=3e-5, epsilon=1e-08, clipnorm=1.0)
loss = tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True)
metric = tf.keras.metrics.SparseCategoricalAccuracy('accuracy')
model.compile(optimizer=optimizer, loss=loss, metrics=[metric])

history = model.fit(train_dataset, epochs=2, steps_per_epoch=115,
                    validation_data=valid_dataset, validation_steps=7)
```


while model.fit I get this error:

```
Train for 115 steps, validate for 7 steps
Epoch 1/2
WARNING:tensorflow:Gradients do not exist for variables ['tf_bert_for_token_classification_1/bert/pooler/dense/kernel:0', 'tf_bert_for_token_classification_1/bert/pooler/dense/bias:0'] when minimizing the loss.
WARNING:tensorflow:Gradients do not exist for variables ['tf_bert_for_token_classification_1/bert/pooler/dense/kernel:0', 'tf_bert_for_token_classification_1/bert/pooler/dense/bias:0'] when minimizing the loss.
WARNING:tensorflow:Gradients do not exist for variables ['tf_bert_for_token_classification_1/bert/pooler/dense/kernel:0', 'tf_bert_for_token_classification_1/bert/pooler/dense/bias:0'] when minimizing the loss.
WARNING:tensorflow:Gradients do not exist for variables ['tf_bert_for_token_classification_1/bert/pooler/dense/kernel:0', 'tf_bert_for_token_classification_1/bert/pooler/dense/bias:0'] when minimizing the loss.
  1/115 [..............................] - ETA: 25:00
---------------------------------------------------------------------------
InvalidArgumentError                      Traceback (most recent call last)
<ipython-input-15-f52b3b390355> in <module>()
      1 history = model.fit(train_dataset, epochs=2, steps_per_epoch=115,
----> 2                     validation_data=valid_dataset, validation_steps=7)

11 frames
/usr/local/lib/python3.6/dist-packages/six.py in raise_from(value, from_value)

InvalidArgumentError: 2 root error(s) found.
  (0) Invalid argument:  assertion failed: [Condition x == y did not hold element-wise:] [x (loss/output_1_loss/SparseSoftmaxCrossEntropyWithLogits/Shape_1:0) = ] [32 1] [y (loss/output_1_loss/SparseSoftmaxCrossEntropyWithLogits/strided_slice:0) = ] [32 128]
	 [[node loss/output_1_loss/SparseSoftmaxCrossEntropyWithLogits/assert_equal_1/Assert/Assert (defined at <ipython-input-15-f52b3b390355>:2) ]]
	 [[Reshape_824/_584]]
  (1) Invalid argument:  assertion failed: [Condition x == y did not hold element-wise:] [x (loss/output_1_loss/SparseSoftmaxCrossEntropyWithLogits/Shape_1:0) = ] [32 1] [y (loss/output_1_loss/SparseSoftmaxCrossEntropyWithLogits/strided_slice:0) = ] [32 128]
	 [[node loss/output_1_loss/SparseSoftmaxCrossEntropyWithLogits/assert_equal_1/Assert/Assert (defined at <ipython-input-15-f52b3b390355>:2) ]]
0 successful operations.
0 derived errors ignored. [Op:__inference_distributed_function_477134]

Function call stack:
distributed_function -> distributed_function
```
Hi, GLUE is a sequence classification task, not a token classification task. The model you're using classifies tokens instead of entires sequences, and therefore has a different output than what is expected by the GLUE task.

Change this line:

```py
model = TFBertForTokenClassification.from_pretrained('bert-base-uncased')
```

to this:

```py
model = TFBertForSequenceClassification.from_pretrained('bert-base-uncased')
```

for it to work.<|||||>This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
