我正在尝试从本地计算机加载StanfordNLP (python)的英文模型,但找不到正确的导入语句来执行此操作。可以使用哪些命令?是否有可用的pip安装程序来加载英语模型?
我已经尝试使用download命令来执行此操作,但是我的机器要求在本地添加所有文件。我从https://stanfordnlp.github.io/CoreNLP/下载了英语的jar文件,但不确定是否需要英语和英语的KBP版本。
发布于 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()
发布于 2019-07-19 03:52:26
我不清楚你想做什么。
如果希望运行all-Python管道,可以下载文件并在Python代码中运行它们,方法是为每个注释器指定路径,如本例所示。
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服务器的。
https://stackoverflow.com/questions/57078311
复制相似问题