summpyというライブラリを試してみたくローカルで実行しました。環境はMacです。
pip install summpyが失敗
summpyをインストールしようとしたのですが、失敗しました。
sudo pip install summpy
Password:
The directory '/Users/pugiemonn/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/pugiemonn/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting summpy
Collecting networkx (from summpy)
Downloading networkx-1.11-py2.py3-none-any.whl (1.3MB)
100% |████████████████████████████████| 1.3MB 966kB/s
Requirement already satisfied (use --upgrade to upgrade): numpy in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from summpy)
Requirement already satisfied (use --upgrade to upgrade): scipy in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from summpy)
Collecting cherrypy (from summpy)
Collecting scikit-learn (from summpy)
Downloading scikit_learn-0.18-cp27-cp27m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (7.1MB)
100% |████████████████████████████████| 7.1MB 89kB/s
Collecting decorator>=3.4.0 (from networkx->summpy)
Downloading decorator-4.0.10-py2.py3-none-any.whl
Requirement already satisfied (use --upgrade to upgrade): six in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from cherrypy->summpy)
Installing collected packages: decorator, networkx, cherrypy, scikit-learn, summpy
Exception:
Traceback (most recent call last):
略
scikit-learnやら色々足りなくて失敗したみたいです。
パッケージをインストール
numpyも入れなくてはいけないようなので検索したサイトを参考にbrewでインストールしました。
brew install gcc
brew update
brew install numpy
brew link --overwrite numpy
上記を参考にしたサイトをメモし忘れてしまってログだけです。
お次はpipでsummpyをインストールです。
sudo pip install scikit-learn
sudo pip install cherrypy summpy
ここでサーバーを起動すると
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 162, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "/Library/Python/2.7/site-packages/summpy/server.py", line 11, in <module>
from . import tools
File "/Library/Python/2.7/site-packages/summpy/tools.py", line 66, in <module>
from .misc.janome_segmenter import word_segmenter_ja
File "/Library/Python/2.7/site-packages/summpy/misc/janome_segmenter.py", line 5, in <module>
from janome.tokenizer import Tokenizer
ImportError: No module named janome.tokenizer
janomeがないと言われます。
sudo pip install janome
janomeも入れてみました。
サーバーを起動
サーバー起動を試します。
python -m summpy.server -h 127.0.0.1 -p 8080
今度は成功しました。
Quick-start
curl http://127.0.0.1:8080/summarize\?sent_limit\=3\&text\=要約したい文章を入力。
こんな感じで投げると文章を要約してくれます。すごい(☝ ՞ਊ ՞)
ローカルでの確認
curlを利用する場合は、改行などを気にしなければいけないので用意されているGUI(以下のローカルURL)を利用したほうが楽だと感じました。
感想
最初全く別の要約文章をつくってくれるのかなと想像してしまったのですが、長い文章の中を一部抽出してくれるだけみたいです。
それでもやはり長文を数行に要約してくれるのは素晴らしくて感動しました。