File tree Expand file tree Collapse file tree 1 file changed +5
-2
lines changed Expand file tree Collapse file tree 1 file changed +5
-2
lines changed Original file line number Diff line number Diff line change 3
3
4
4
import os
5
5
import re
6
+ import threading
6
7
from typing import Optional , Dict , List , Iterable
7
8
8
9
import attr
@@ -58,6 +59,7 @@ def __init__(self,
58
59
** config_kw ):
59
60
self .config = GlueModelConfig (** config_kw )
60
61
self ._load_model (model_name_or_path )
62
+ self ._lock = threading .Lock ()
61
63
62
64
def _load_model (self , model_name_or_path ):
63
65
"""Load model. Can be overridden for testing."""
@@ -76,8 +78,9 @@ def _load_model(self, model_name_or_path):
76
78
config = model_config )
77
79
78
80
def _get_tokens (self , ex : JsonDict , field_name : str ) -> List [str ]:
79
- return (ex .get ("tokens_" + field_name ) or
80
- self .tokenizer .tokenize (ex [field_name ]))
81
+ with self ._lock :
82
+ return (ex .get ("tokens_" + field_name ) or
83
+ self .tokenizer .tokenize (ex [field_name ]))
81
84
82
85
def _preprocess (self , inputs : Iterable [JsonDict ]) -> Dict [str , tf .Tensor ]:
83
86
# Use pretokenized input if available.
You can’t perform that action at this time.
0 commit comments