AttributeError: 'str' object has no attribute 'item' - Bert Fine tuning

You can’t write

loss, logits = model(...)

since v4, as the output of the model is a dictionary, so this will give you the keys (hence the fact your loss is a string) and not the values.

You can do:

loss, logits = model(...).to_tuple()

or

outputs = model(...)
loss = outputs.loss
logits = outputs.logits
1 Like