我正在尝试使用Stanfordnlp获取单词的依赖关系。我已经下载了英语模型,并能够加载模型以获得文本中单词的依赖关系。但是,它还将打印整个加载过程消息。
示例代码:
import stanfordnlp
config = {
'processors': 'tokenize,pos,lemma,depparse',# Comma-separated list of processors to use
'lang': 'en',# Language code for the language to build the Pipeline in
'tokenize_model_path': 'C:\\path\\stanfordnlp_resources\\en_ewt_models\\en_ewt_tokenizer.pt','pos_model_path': 'C:\\path\\stanfordnlp_resources\\en_ewt_models\\en_ewt_tagger.pt','pos_pretrain_path': 'C:\\path\\stanfordnlp_resources\\en_ewt_models\\en_ewt.pretrain.pt','lemma_model_path': 'C:\\path\\stanfordnlp_resources\\en_ewt_models\\en_ewt_lemmatizer.pt','depparse_model_path': 'C:\\path\\stanfordnlp_resources\\en_ewt_models\\en_ewt_parser.pt','depparse_pretrain_path': 'C:\\path\\stanfordnlp_resources\\en_ewt_models\\en_ewt.pretrain.pt'
}
text = 'The weather is nice today.'
# This downloads the English models for the neural pipeline
nlp = stanfordnlp.Pipeline(**config) # This sets up a default neural pipeline in English
doc = nlp(text)
doc.sentences[0].print_dependencies()
>>>
Use device: cpu
---
Loading: tokenize
With settings:
{'model_path': 'C:\\path\\stanfordnlp_resources\\en_ewt_models\\en_ewt_tokenizer.pt','lang': 'en','shorthand': 'en_ewt','mode': 'predict'}
---
Loading: pos
With settings:
{'model_path': 'C:\\path\\stanfordnlp_resources\\en_ewt_models\\en_ewt_tagger.pt','pretrain_path': 'C:\\path\\stanfordnlp_resources\\en_ewt_models\\en_ewt.pretrain.pt','mode': 'predict'}
---
Loading: lemma
With settings:
{'model_path': 'C:\\path\\stanfordnlp_resources\\en_ewt_models\\en_ewt_lemmatizer.pt','mode': 'predict'}
Building an attentional Seq2Seq model...
Using a Bi-LSTM encoder
Using soft attention for LSTM.
Finetune all embeddings.
[Running seq2seq lemmatizer with edit classifier]
---
Loading: depparse
With settings:
{'model_path': 'C:\\path\\stanfordnlp_resources\\en_ewt_models\\en_ewt_parser.pt','mode': 'predict'}
Done loading processors!
---
('The','2','det')
('weather','4','nsubj')
('is','cop')
('nice','0','root')
('today','obl:tmod')
('.','punct')
我使用Anaconda安装了Stanfordnlp,并使用Jupyter笔记本电脑。有没有一种方法可以跳过消息,因为我只需要依赖项。