Unsupported value type BatchEncoding returned by IteratorSpec._serialize
Hi all!I’m having a go at fine tuning BERT for a regression problem (given a passage of text, predict it’s readability score) as a part ofa Kaggle competition.To do so I’m doing the following:1. Loading BERT tokenizer and applying it to the datasetfrom transformers import BertTokenizer, TFBertModel
tokenizer = BertTokenizer.from_pretrained('bert-base-uncased')

# df_raw is the training dataset
tokens = tokenizer(list(df_raw['excerpt']), padding='max_length', truncation=True, return_tensors="np")2. Adding the target column and creating a TensorFlow datasettokens_w_labels = tokens.copy()
tokens_w_labels['target'] = df_raw['target']

tokens_dataset = tf.data.Dataset.from_tensor_slices(
    tokens_w_labels
)3. Loading a sequence classification model, and attempting to fine tuneimport tensorflow as tf
from transformers import TFAutoModelForSequenceClassification

# num_labels=1 should produce regression (numerical) output
model = TFAutoModelForSequenceClassification.from_pretrained("bert-base-uncased", num_labels=1)

# Compile with relevant metrics / loss
model.compile(
    optimizer='adam',
    loss='mean_squared_error',
    metrics=['mean_absolute_error', 'mean_squared_error'],
)

# Removed validation data for time being
model.fit(
    tokens_dataset,
    batch_size=8,
    epochs=3
)It’s at this step that I get an error: Unsupported value type BatchEncoding returned by IteratorSpec._serialize. I’ve tried a few different setups and I can’t figure out where the issue is.The specific part of TensorFlow that the error code comes from ishere.Any pointers on what’s going wrong here?
2021-07-02T16:07:14Z
Eventually got this working - appears that the error was in step 2, where I was combining the target column with the tokenized labelsbeforecreating the dataset.I also needed to turn the tokenized labels into adict.# This version works
train_dataset = tf.data.Dataset.from_tensor_slices((
    dict(tokens_w_labels),
    df_raw['target'].values
))
2021-11-04T07:19:10Z
replace ‘tokens_dataset’ by ‘tokens_dataset[‘input_ids’]’