Pythonライブラリ「Sumy」を使って文章の要約を爆速(2分)でやってみた。

アイキャッチ画像

英文の要約を行っていきます。

What’s Sumy?

Sumy is Simple library and command line utility for extracting summary from HTML pages or plain texts. The package also contains simple evaluation framework for text summaries.

また詳しいドキュメンテーションは公式GitHubに書いてあります。

Sumyのインストール

まず、Pythonをインストールしてない人はしてください。そこら辺はググれ。

そしてPyplからパッケージをインストールします。

pip install sumy

以上!

はい。これで約一分。

実際に要約する

はい。もう準備完了です。あとは題材を用意します。

要約する文章を決まる。

今回はThe NewYork Timesの記事を要約してみました。

一応画像等の要素を抜いた文章になります。

とは言っても今回ダウンロードとかする必要ありません。GistのRawファイルを読み込むだけなので。

いざやる。

SumyはPyttonのライブラリなんですけどコマンドラインからも利用することができます。

今回は5行に要約してみました。以下が入力例です。

 sumy lex-rank --length=5 --url=https://gist.githubusercontent.com/tomomi0115/d40dab33ae92af24592bdcb4ad796453/raw/18707e6ca3af17786944c3e6d238b5b9b9c7406a/aiw.txt

lengthパラメータに行数を入力し、urlパラメータに対象のテキストファイルのローカルパスorリンクを打ち込みます。

その他詳しいパラメータ等については公式Gitをご覧ください。https://github.com/miso-belica/sumy#usage

結果はこちら↓

結果

要約結果

Under a proposed law from the Australian Competition and Consumer Commission, both Google and Facebook would be required to negotiate with media publishers and compensate them for the content that appears on their sites.
Google began the day by unveiling a three-year global agreement with Rupert Murdoch’s News Corp to pay for the publisher’s news content, one of several such deals it has announced recently where it appears to be effectively capitulating to publishers’ demands.
In August, Facebook said it would block users and news organizations in Australia from sharing local and international news stories on its social network and Instagram if the bill were to move forward.
In 2009, Mr. Murdoch threatened to remove News Corp articles from Google, accusing the internet giant of stealing its content.
The move could prove deeply difficult for Australians, with publishers no longer being able to share or post any content from their Facebook pages and users unable to view news articles shared on Facebook by overseas publishers.

日本語結果【Google翻訳丸投げ】

あまりにもめんどかったのでGoogle先生に対処してもらいました。

オーストラリア競争消費者委員会から提案された法律の下では、GoogleとFacebookの両方がメディア出版社と交渉し、彼らのサイトに表示されるコンテンツに対して補償する必要があります。
Googleは、出版社のニュースコンテンツの支払いについて、ルパートマードックのニューズコーポレーションとの3年間のグローバル契約を発表することからこの日を始めました。これは、出版社の要求に効果的に降伏しているように見える最近発表されたいくつかの取引の1つです。
8月、Facebookは、法案が前進した場合、オーストラリアのユーザーとニュース組織がソーシャルネットワークとInstagramでローカルおよび国際的なニュース記事を共有することをブロックすると発表しました。
2009年、マードック氏は、インターネットの巨人がコンテンツを盗んだとして、GoogleからNewsCorpの記事を削除すると脅迫しました。
この動きはオーストラリア人にとって非常に困難である可能性があり、パブリッシャーはFacebookページのコンテンツを共有または投稿できなくなり、ユーザーは海外のパブリッシャーがFacebookで共有したニュース記事を表示できなくなります。
相当正確かつ早かったなって印象でした。

さいごに

所要時間はおよそ10秒程度でした。

ちょっと要約してみたい!けど時間がない!って人だったり今後Pythonとかで自然言語処理だったり深層学習だといった学びのテーマづくりをしてる人とかはぜひやってみてください。

以上。