当前位置: 首页>>代码示例>>Python>>正文


Python symbols.ORTH属性代码示例

本文整理汇总了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() 
开发者ID:ConvLab,项目名称:ConvLab,代码行数:29,代码来源:nlu.py

示例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}]) 
开发者ID:jrzaurin,项目名称:pytorch-widedeep,代码行数:5,代码来源:fastai_transforms.py

示例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() 
开发者ID:jgontrum,项目名称:spacy-api-docker,代码行数:17,代码来源:app.py

示例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] 
开发者ID:outcastofmusic,项目名称:quick-nlp,代码行数:13,代码来源:spacy_tokenizer.py


注:本文中的spacy.symbols.ORTH属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。