Skip to content

Commit 723d96c

Browse files
Moved check out of the loop to avoid quadratic runtime.
1 parent 316a297 commit 723d96c

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

official/nlp/data/tagging_data_lib.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,10 @@ def _tokenize_example(example, max_length, tokenizer, text_preprocessing=None):
224224
max_length = max_length - 2
225225
new_examples = []
226226
new_example = InputExample(sentence_id=example.sentence_id, sub_sentence_id=0)
227-
for i, word in enumerate(example.words):
228-
if any([x < 0 for x in example.label_ids]):
229-
raise ValueError("Unexpected negative label_id: %s" % example.label_ids)
227+
if any([x < 0 for x in example.label_ids]):
228+
raise ValueError("Unexpected negative label_id: %s" % example.label_ids)
230229

230+
for i, word in enumerate(example.words):
231231
if text_preprocessing:
232232
word = text_preprocessing(word)
233233
subwords = tokenizer.tokenize(word)

0 commit comments

Comments
 (0)