Skip to content

Commit ccd226c

Browse files
authored
Use warning instead of error in map_token_to_id (#285)
1 parent 885255c commit ccd226c

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

texar/torch/data/tokenizers/tokenizer_base.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@
2020

2121
from typing import Any, Dict, List, Optional, Tuple, overload
2222

23-
import os
2423
import json
24+
import os
25+
import warnings
2526

2627
from texar.torch.module_base import ModuleBase
2728

@@ -380,11 +381,11 @@ def map_token_to_id(self, tokens):
380381
for token in tokens:
381382
ids.append(self._map_token_to_id_with_added_voc(token))
382383
if len(ids) > self.max_len:
383-
raise ValueError(
384+
warnings.warn(
384385
"Token indices sequence length is longer than the specified "
385386
"maximum sequence length for this model ({} > {}). Running "
386387
"this sequence through the model will result in indexing "
387-
"errors".format(len(ids), self.max_len))
388+
"errors".format(len(ids), self.max_len), UserWarning)
388389
return ids
389390

390391
# pylint: enable=unused-argument,function-redefined

0 commit comments

Comments
 (0)