# Buggy code
def tokens_to_indices(
    self, tokens: List[Token], vocabulary: Vocabulary
) -> IndexedTokenList:
    self._matched_indexer._add_encoding_to_vocabulary_if_needed(vocabulary)

    wordpieces, offsets = self._allennlp_tokenizer.intra_word_tokenize(
        [t.text for t in tokens]
    )
    output: IndexedTokenList = {
        "token_ids": [t.text_id for t in wordpieces],
        "mask": [True] * len(tokens),  # for original tokens (i.e. word-level)
        "type_ids": [t.type_id for t in wordpieces],
        "offsets": offsets,
        "wordpiece_mask": [True]
        * len(wordpieces),  # for wordpieces (i.e. subword-level)
    }

    return self._matched_indexer._postprocess_output(output)


# Traceback (TypeError)
Traceback (most recent call last):
File "/home/arthur/question-generation/models/sg_dqg.py", line 156, in <module>
preprocess(args.ds)
File "/home/arthur/question-generation/models/sg_dqg.py", line 124, in preprocess
coreferences = coreference_resolution(evidences_list)
File "/home/arthur/question-generation/models/sg_dqg.py", line 74, in coreference_resolution
document="Besides its prominence in sports, Notre Dame is also a large, four-year, highly residential research University, and is consistently ranked among the top twenty universities in the United States  and as a major global university."
File "/home/arthur/anaconda3/envs/tensorflow_env/lib/python3.6/site-packages/allennlp_models/coref/coref_predictor.py", line 65, in predict
return self.predict_json({"document": document})
File "/home/arthur/anaconda3/envs/tensorflow_env/lib/python3.6/site-packages/allennlp/predictors/predictor.py", line 48, in predict_json
return self.predict_instance(instance)
File "/home/arthur/anaconda3/envs/tensorflow_env/lib/python3.6/site-packages/allennlp/predictors/predictor.py", line 171, in predict_instance
outputs = self._model.forward_on_instance(instance)
File "/home/arthur/anaconda3/envs/tensorflow_env/lib/python3.6/site-packages/allennlp/models/model.py", line 142, in forward_on_instance
return self.forward_on_instances([instance])[0]
File "/home/arthur/anaconda3/envs/tensorflow_env/lib/python3.6/site-packages/allennlp/models/model.py", line 167, in forward_on_instances
model_input = util.move_to_device(dataset.as_tensor_dict(), cuda_device)
File "/home/arthur/anaconda3/envs/tensorflow_env/lib/python3.6/site-packages/allennlp/data/batch.py", line 139, in as_tensor_dict
for field, tensors in instance.as_tensor_dict(lengths_to_use).items():
File "/home/arthur/anaconda3/envs/tensorflow_env/lib/python3.6/site-packages/allennlp/data/instance.py", line 99, in as_tensor_dict
tensors[field_name] = field.as_tensor(padding_lengths[field_name])
File "/home/arthur/anaconda3/envs/tensorflow_env/lib/python3.6/site-packages/allennlp/data/fields/text_field.py", line 103, in as_tensor
self._indexed_tokens[indexer_name], indexer_lengths[indexer_name]
File "/home/arthur/anaconda3/envs/tensorflow_env/lib/python3.6/site-packages/allennlp/data/token_indexers/pretrained_transformer_mismatched_indexer.py", line 96, in as_padded_tensor_dict
offsets_tokens, offsets_padding_lengths, default_value=lambda: (0, 0)
TypeError: not a sequence

# Fixed code
def tokens_to_indices(
    self, tokens: List[Token], vocabulary: Vocabulary
) -> IndexedTokenList:
    self._matched_indexer._add_encoding_to_vocabulary_if_needed(vocabulary)

    wordpieces, offsets = self._allennlp_tokenizer.intra_word_tokenize(
        [t.text for t in tokens]
    )

    # For tokens that don't correspond to any word pieces, we put (-1, -1) into the offsets.
    # That results in the embedding for the token to be all zeros.
    offsets = [x if x is not None else (-1, -1) for x in offsets]

    output: IndexedTokenList = {
        "token_ids": [t.text_id for t in wordpieces],
        "mask": [True] * len(tokens),  # for original tokens (i.e. word-level)
        "type_ids": [t.type_id for t in wordpieces],
        "offsets": offsets,
        "wordpiece_mask": [True]
        * len(wordpieces),  # for wordpieces (i.e. subword-level)
    }

    return self._matched_indexer._postprocess_output(output)