首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在本地加载StanfordNLP模型

在本地加载StanfordNLP模型
EN

Stack Overflow用户
提问于 2019-07-17 22:30:58
回答 2查看 1.2K关注 0票数 2

我正在尝试从本地计算机加载StanfordNLP (python)的英文模型,但找不到正确的导入语句来执行此操作。可以使用哪些命令?是否有可用的pip安装程序来加载英语模型?

我已经尝试使用download命令来执行此操作,但是我的机器要求在本地添加所有文件。我从https://stanfordnlp.github.io/CoreNLP/下载了英语的jar文件,但不确定是否需要英语和英语的KBP版本。

EN

回答 2

Stack Overflow用户

发布于 2020-03-15 11:30:23

模型下载目录集为/home/sf

pip install stanfordnlp # install stanfordnlp

import stanfordnlp stanfordnlp.download("en") # here after 'Y' one set custom directory path

local_dir_store_model = "/home/sf" english_model_dir = "/home/sf/en_ewt_models" tokienizer_en_pt_file = "/home/sf/en_ewt_models/en_ewt_tokenizer.pt"

nlp = stanfordnlp.Pipeline(models_dir=local_dir_store_model,processors = 'tokenize,mwt,lemma,pos') doc = nlp("""One of the most wonderful things in life is to wake up and enjoy a cuddle with somebody; unless you are in prison"""") doc.sentences[0].print_tokens()

票数 3
EN

Stack Overflow用户

发布于 2019-07-19 03:52:26

我不清楚你想做什么。

如果希望运行all-Python管道,可以下载文件并在Python代码中运行它们,方法是为每个注释器指定路径,如本例所示。

代码语言:javascript
复制
import stanfordnlp

config = {
    'processors': 'tokenize,mwt,pos,lemma,depparse', # Comma-separated list of processors to use
    'lang': 'fr', # Language code for the language to build the Pipeline in
    'tokenize_model_path': './fr_gsd_models/fr_gsd_tokenizer.pt', # Processor-specific arguments are set with keys "{processor_name}_{argument_name}"
    'mwt_model_path': './fr_gsd_models/fr_gsd_mwt_expander.pt',
    'pos_model_path': './fr_gsd_models/fr_gsd_tagger.pt',
    'pos_pretrain_path': './fr_gsd_models/fr_gsd.pretrain.pt',
    'lemma_model_path': './fr_gsd_models/fr_gsd_lemmatizer.pt',
    'depparse_model_path': './fr_gsd_models/fr_gsd_parser.pt',
    'depparse_pretrain_path': './fr_gsd_models/fr_gsd.pretrain.pt'
}
nlp = stanfordnlp.Pipeline(**config) # Initialize the pipeline using a configuration dict
doc = nlp("Van Gogh grandit au sein d'une famille de l'ancienne bourgeoisie.") # Run the pipeline on input text
doc.sentences[0].print_tokens()

如果要使用Python接口运行Java服务器,则需要下载Java jar文件并启动服务器。完整信息请点击此处:https://stanfordnlp.github.io/CoreNLP/corenlp-server.html

然后,您可以使用Python接口访问服务器。完整信息请点击此处:https://stanfordnlp.github.io/stanfordnlp/corenlp_client.html

但为了清楚起见,jar文件不应该与纯Python管道一起使用。这些是用来运行Java服务器的。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57078311

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档