{{category python}} !!! spaCy {{outline}} ---- https://spacy.io/ !!インストール https://spacy.io/usage#quickstart *Windows のコンソールで pip install spacy *Windowsのシェルで管理者として実行(右ボタン) python -m spacy download en *Macの場合 pip3 install spacy python3 -m spacy download en_core_web_sm *Pythonのシェルで import spacy *それか、スクリプトの先頭に書いておく {{pre import spacy nlp = spacy.load('en_core_web_sm') 以下スクリプト }} !Anaconda NavigatorのEnvironmentsで追加できないときは、 https://github.com/conda/conda/issues/9423 *PowerShellで、 conda install -c conda-forge spacy conda install -c conda-forge spacy-model-en_core_web_sm https://anaconda.org/conda-forge/spacy !!関数 !依存関係の可視化 https://spacy.io/usage/visualizers {{pre import spacy from spacy import displacy nlp = spacy.load("en_core_web_sm") doc = nlp("This is a sentence.") displacy.serve(doc, style="dep") }} *Jupyter Notebookで実行する場合、最後のdisplacy.serveの代わりに、displacy.renderを使う。 {{pre sample = "Parents drive their children everywhere." sample_doc = nlp(sample) displacy.render(sample_doc, style="dep") }} {{ref_image parents.jpg}} !!Demo https://explosion.ai/demos/ !!References https://githubja.com/explosion/spacy https://ishitonton.hatenablog.com/entry/2018/11/24/004748 https://spacy.io/usage/spacy-101