【问题标题】:How to load Stanfordnlp pipeline without printing the load processor messages如何在不打印负载处理器消息的情况下加载 Stanfordnlp 管道
【发布时间】:2019-11-15 07:42:13
【问题描述】:

我正在尝试使用 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', 'lang': 'en', 'shorthand': 'en_ewt', 'mode': 'predict'}
---
Loading: lemma
With settings: 
{'model_path': 'C:\\path\\stanfordnlp_resources\\en_ewt_models\\en_ewt_lemmatizer.pt', 'lang': 'en', 'shorthand': 'en_ewt', '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', 'pretrain_path': 'C:\\path\\stanfordnlp_resources\\en_ewt_models\\en_ewt.pretrain.pt', 'lang': 'en', 'shorthand': 'en_ewt', 'mode': 'predict'}
Done loading processors!
---
('The', '2', 'det')
('weather', '4', 'nsubj')
('is', '4', 'cop')
('nice', '0', 'root')
('today', '4', 'obl:tmod')
('.', '4', 'punct')

我使用 Anaconda 安装了 Stanfordnlp 并使用 Jupyter 笔记本。有没有办法跳过消息,因为我只需要依赖项。

【问题讨论】:

    标签: python-3.x jupyter-notebook anaconda stanford-nlp


    【解决方案1】:

    如果您只想摆脱 Jupyter 笔记本中的这些行,您可以在调用管道后立即清除输出;

    from IPython.display import clear_output
    
    ...
    
    nlp = stanfordnlp.Pipeline(**config)
    clear_output()
    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-14
      • 2021-08-01
      • 2010-11-23
      • 1970-01-01
      相关资源
      最近更新 更多