[英]How to run Stanford CoreNLP for lemmatization on Google Colab?
有一個類似的問題,但是從那時起 google colab 發生了很大變化,我想知道如何在 Google Colab 上使用斯坦福 CoreNLP,專門用於詞形還原。
預期答案:
使用代碼:
!pip install stanfordnlp
import stanfordnlp
stanfordnlp.download("es")
nlp = stanfordnlp.Pipeline(processors='tokenize,mwt,pos,lemma')
doc = nlp("Barack Obama was born in Hawaii.")
print(*[f'word: {word.text+" "}\tlemma: {word.lemma}' for sent in doc.sentences for word in sent.words], sep='\n')
%tb
------------
Loading: tokenize
With settings:
{'model_path': '/root/stanfordnlp_resources/en_ewt_models/en_ewt_tokenizer.pt', 'lang': 'en', 'shorthand': 'en_ewt', 'mode': 'predict'}
Cannot load model from /root/stanfordnlp_resources/en_ewt_models/en_ewt_tokenizer.pt
An exception has occurred, use %tb to see the full traceback.
SystemExit: 1
/usr/local/lib/python3.6/dist-packages/IPython/core/interactiveshell.py:2890: UserWarning: To exit: use 'exit', 'quit', or Ctrl-D.
warn("To exit: use 'exit', 'quit', or Ctrl-D.", stacklevel=1)
將考慮任何改進問題的建議
也許最好使用新的StanfordNLP
而不是舊的CoreNLP
。
!pip install stanfordnlp
import stanfordnlp
stanfordnlp.download("en")
nlp = stanfordnlp.Pipeline(processors='tokenize,mwt,pos,lemma')
doc = nlp("Barack Obama was born in Hawaii.")
print(*[f'word: {word.text+" "}\tlemma: {word.lemma}' for sent in doc.sentences for word in sent.words], sep='\n')
你會得到這個輸出
word: Barack lemma: Barack
word: Obama lemma: Obama
word: was lemma: be
word: born lemma: bear
word: in lemma: in
word: Hawaii lemma: Hawaii
word: . lemma: .
這是一個示例筆記本。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.