pytorch TypeError: '<' not supported between instances of 'Example' and 'Example' when referring to iterator
I am trying to use my own dataset to classify text according to https://github.com/bentrevett/pytorch-sentiment-analysis/blob/master/5%20-%20Multi-class%20Sentiment%20Analysis.ipynb. My dataset is a csv of sentences and a class associated with it. there are 6 different classes:

sent                      class
'the fox is brown'        animal
'the house is big'        object
'one water is drinkable'  water
...


When running:

N_EPOCHS = 5

best_valid_loss = float('inf')

for epoch in range(N_EPOCHS):

    start_time = time.time()
    print(start_time)
    train_loss, train_acc = train(model, train_iterator, optimizer, criterion)
    #print(train_loss.type())
    #print(train_acc.type())
    valid_loss, valid_acc = evaluate(model, valid_iterator, criterion)

    end_time = time.time()

    epoch_mins, epoch_secs = epoch_time(start_time, end_time)

    if valid_loss &lt; best_valid_loss:
        best_valid_loss = valid_loss
        torch.save(model.state_dict(), 'tut5-model.pt')

    print(f'Epoch: {epoch+1:02} | Epoch Time: {epoch_mins}m {epoch_secs}s')
    print(f'\tTrain Loss: {train_loss:.3f} | Train Acc: {train_acc*100:.2f}%')
    print(f'\t Val. Loss: {valid_loss:.3f} |  Val. Acc: {valid_acc*100:.2f}%')


, I obtained the following error

1566460706.977012
epoch_loss
&lt;torchtext.data.iterator.BucketIterator object at 0x000001FABE907E80&gt;
TypeError: '&lt;' not supported between instances of 'Example' and 'Example'


pointing to:

TypeError                                 Traceback (most recent call last)
&lt;ipython-input-22-19e8a7eb204e&gt; in &lt;module&gt;()
     10     #print(train_loss.type())
     11     #print(train_acc.type())
---&gt; 12     valid_loss, valid_acc = evaluate(model, valid_iterator, criterion)
     13 
     14     end_time = time.time()

&lt;ipython-input-21-83b02f99bca7&gt; in evaluate(model, iterator, criterion)
      9         print('epoch_loss')
     10         print(iterator)
---&gt; 11         for batch in iterator:
     12             print('batch')
     13             predictions = model(batch.text)


I am new to pytorch, so only added a line to idenify iterator data type and got:

&lt;torchtext.data.iterator.BucketIterator object at 0x000001FABE907E80&gt;


I tried to determine specific attributes following  https://github.com/pytorch/text/blob/master/torchtext/data/iterator.py to no avail.

Any suggestions are appreciated.

The code for the evaluate (where the iterator is) method is:

def evaluate(model, iterator, criterion):

    epoch_loss = 0
    epoch_acc = 0

    model.eval()

    with torch.no_grad():
        print('epoch_loss')
        print(iterator)
        for batch in iterator:
            print('batch')
            predictions = model(batch.text)

            loss = criterion(predictions, batch.label)

            acc = categorical_accuracy(predictions, batch.label)

            epoch_loss += loss.item()
            epoch_acc += acc.item()

    return epoch_loss / len(iterator), epoch_acc / len(iterator)


I faced a similar issue and got it resolved by using sort_key and sort_within_batch while creating iterators.
train_iterator, valid_iterator = BucketIterator.splits(
    (train, valid), 
    batch_size = BATCH_SIZE,
    sort_key = lambda x: len(x.sent),
    sort_within_batch=True,
    device = device)

