本文整理匯總了Python中spacy.symbols.ORTH屬性的典型用法代碼示例。如果您正苦於以下問題:Python symbols.ORTH屬性的具體用法?Python symbols.ORTH怎麽用?Python symbols.ORTH使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類spacy.symbols
的用法示例。
在下文中一共展示了symbols.ORTH屬性的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: from spacy import symbols [as 別名]
# 或者: from spacy.symbols import ORTH [as 別名]
def __init__(self,
archive_file=DEFAULT_ARCHIVE_FILE,
cuda_device=DEFAULT_CUDA_DEVICE,
model_file=None,
context_size=3):
""" Constructor for NLU class. """
self.context_size = context_size
check_for_gpu(cuda_device)
if not os.path.isfile(archive_file):
if not model_file:
raise Exception("No model for MILU is specified!")
archive_file = cached_path(model_file)
archive = load_archive(archive_file,
cuda_device=cuda_device)
self.tokenizer = SpacyWordSplitter(language="en_core_web_sm")
_special_case = [{ORTH: u"id", LEMMA: u"id"}]
self.tokenizer.spacy.tokenizer.add_special_case(u"id", _special_case)
dataset_reader_params = archive.config["dataset_reader"]
self.dataset_reader = DatasetReader.from_params(dataset_reader_params)
self.model = archive.model
self.model.eval()
示例2: add_special_cases
# 需要導入模塊: from spacy import symbols [as 別名]
# 或者: from spacy.symbols import ORTH [as 別名]
def add_special_cases(self, toks: Collection[str]):
for w in toks:
self.tok.tokenizer.add_special_case(w, [{ORTH: w}])
示例3: run
# 需要導入模塊: from spacy import symbols [as 別名]
# 或者: from spacy.symbols import ORTH [as 別名]
def run():
for model in MODELS:
print("Load model ", model)
loaded_model = get_model(model)
special_cases_str = os.getenv(f"{model}_special_cases", "")
if special_cases_str:
for special_case in special_cases_str.split(','):
loaded_model.tokenizer.add_special_case(
special_case,
[{ORTH: special_case}]
)
print("Loaded all models. Starting HTTP server.")
httpd = simple_server.make_server('0.0.0.0', 8000, APP)
httpd.serve_forever()
示例4: __init__
# 需要導入模塊: from spacy import symbols [as 別名]
# 或者: from spacy.symbols import ORTH [as 別名]
def __init__(self, language="en", special_cases=None, regex_cases=None):
self.nlp = spacy.load(language)
self.nlp.tokenizer.add_special_case('<eos>', [{ORTH: '<eos>'}])
self.nlp.tokenizer.add_special_case('<bos>', [{ORTH: '<bos>'}])
self.nlp.tokenizer.add_special_case('<sos>', [{ORTH: '<sos>'}])
self.nlp.tokenizer.add_special_case('<unk>', [{ORTH: '<unk>'}])
self.nlp.tokenizer.add_special_case('<pad>', [{ORTH: '<pad>'}])
special_cases = [] if special_cases is None else special_cases
for case in special_cases:
self.nlp.tokenizer.add_special_case(case, [{ORTH: case}])
self.regex_cases = [] if regex_cases is None else [re.compile(i, flags=re.IGNORECASE) for i in regex_cases]