prose 、純粋なGOの自然言語加工ライブラリ(英語のみ)です。トークン化、セグメンテーション、スピーチの一部のタグ付け、および指定された励起抽出をサポートします。
図書館のパフォーマンスに関する詳細な要約は、 prose v2.0.0の導入:NLPを導入します。
$ go get github.com/jdkato/prose/v2 package main
import (
"fmt"
"log"
"github.com/jdkato/prose/v2"
)
func main () {
// Create a new document with the default configuration:
doc , err := prose . NewDocument ( "Go is an open-source programming language created at Google." )
if err != nil {
log . Fatal ( err )
}
// Iterate over the doc's tokens:
for _ , tok := range doc . Tokens () {
fmt . Println ( tok . Text , tok . Tag , tok . Label )
// Go NNP B-GPE
// is VBZ O
// an DT O
// ...
}
// Iterate over the doc's named-entities:
for _ , ent := range doc . Entities () {
fmt . Println ( ent . Text , ent . Label )
// Go GPE
// Google GPE
}
// Iterate over the doc's sentences:
for _ , sent := range doc . Sentences () {
fmt . Println ( sent . Text )
// Go is an open-source programming language created at Google.
}
}ドキュメント作成プロセスは、次の一連のステップに準拠しています。
tokenization -> POS tagging -> NE extraction
segmentation
適切な機能オプションを渡すことにより、各ステップが無効になっている場合があります(後の手順が不要であると仮定します)。たとえば、名前付きエンティティ抽出を無効にするには、次のことを行います。
doc , err := prose . NewDocument (
"Go is an open-source programming language created at Google." ,
prose . WithExtraction ( false ))prose 、以下に示す単語以外の文字スパンを含む最新のテキストを処理できるトークナイザーが含まれています。
| タイプ | 例 |
|---|---|
| メールアドレス | [email protected] |
| ハッシュタグ | #trending |
| 言及 | @jdkato |
| URL | https://github.com/jdkato/prose |
| 絵文字 | :-) 、 >:( 、 o_0など。 |
package main
import (
"fmt"
"log"
"github.com/jdkato/prose/v2"
)
func main () {
// Create a new document with the default configuration:
doc , err := prose . NewDocument ( "@jdkato, go to http://example.com thanks :)." )
if err != nil {
log . Fatal ( err )
}
// Iterate over the doc's tokens:
for _ , tok := range doc . Tokens () {
fmt . Println ( tok . Text , tok . Tag )
// @jdkato NN
// , ,
// go VB
// to TO
// http://example.com NN
// thanks NNS
// :) SYM
// . .
}
}pragmatic_segmenterの開発者によって作成された黄金律によると、 proseは利用可能な最も正確な文セグメーターの1つが含まれています。
| 名前 | 言語 | ライセンス | GRS(英語) | GRS(その他) | スピード† |
|---|---|---|---|---|---|
| 実用的なセグメントター | ルビー | mit | 98.08%(51/52) | 100.00% | 3.84 s |
| 散文 | 行く | mit | 75.00%(39/52) | n/a | 0.96秒 |
| tactfultokenizer | ルビー | GNU GPLV3 | 65.38%(34/52) | 48.57% | 46.32秒 |
| opennlp | Java | APLV2 | 59.62%(31/52) | 45.71% | 1.27 s |
| スタンフォード・コレンプ | Java | GNU GPLV3 | 59.62%(31/52) | 31.43% | 0.92秒 |
| スプリッタ | Python | APLV2 | 55.77%(29/52) | 37.14% | n/a |
| パンク | Python | APLV2 | 46.15%(24/52) | 48.57% | 1.79 s |
| SRX英語 | ルビー | GNU GPLV3 | 30.77%(16/52) | 28.57% | 6.19 s |
| Scapel | ルビー | GNU GPLV3 | 28.85%(15/52) | 20.00% | 0.13秒 |
†元のテストは、MacBook Pro 3.7 GHz Quad-Core Intel Xeon E5を使用して10.9.5を使用して実行されましたが、
proseはMacBook Pro 2.9 GHz Intel Core i7を使用して10.13.3を使用してタイミングを合わせました。
package main
import (
"fmt"
"strings"
"github.com/jdkato/prose/v2"
)
func main () {
// Create a new document with the default configuration:
doc , _ := prose . NewDocument ( strings . Join ([] string {
"I can see Mt. Fuji from here." ,
"St. Michael's Church is on 5th st. near the light." }, " " ))
// Iterate over the doc's sentences:
sents := doc . Sentences ()
fmt . Println ( len ( sents )) // 2
for _ , sent := range sents {
fmt . Println ( sent . Text )
// I can see Mt. Fuji from here.
// St. Michael's Church is on 5th st. near the light.
}
}prose 、TextBlobの「高速で正確な」POSタガーに基づくタガーが含まれています。以下は、TreeBankコーパス上の同じタガーのNLTKの実装とのパフォーマンスの比較です。
| 図書館 | 正確さ | 5ラン平均(SEC) |
|---|---|---|
| nltk | 0.893 | 7.224 |
prose | 0.961 | 2.538 |
(詳細については、 scripts/test_model.pyを参照してください。)
サポートされているPOSタグの完全なリストを以下に示します。
| タグ | 説明 |
|---|---|
( | 左丸いブラケット |
) | ラウンドブラケット |
, | コンマ |
: | 結腸 |
. | 期間 |
'' | クロージング引用マーク |
`` | オープニングクォートマーク |
# | 番号サイン |
$ | 通貨 |
CC | 接続詞、調整 |
CD | 枢機Number |
DT | 決定者 |
EX | そこに実存します |
FW | 外国語 |
IN | 接続詞、下位または前置詞 |
JJ | 形容詞 |
JJR | 形容詞、比較 |
JJS | 形容詞、最上級 |
LS | アイテムマーカーをリストします |
MD | 動詞、モーダル補助 |
NN | 名詞、特異または質量 |
NNP | 名詞、適切なシングル |
NNPS | 名詞、適切な複数 |
NNS | 名詞、複数 |
PDT | PredEterminer |
POS | 所有エンディング |
PRP | 代名詞、個人 |
PRP$ | 代名詞、所有 |
RB | 副詞 |
RBR | 副詞、比較 |
RBS | 副詞、最上級 |
RP | 副詞、粒子 |
SYM | シンボル |
TO | インフィニティバル |
UH | 間投詞 |
VB | 動詞、ベースフォーム |
VBD | 動詞、過去形 |
VBG | 動詞、動詞、または現在分詞 |
VBN | 動詞、過去分詞 |
VBP | 動詞、非3人の単数形が存在します |
VBZ | 動詞、3人目の単数形 |
WDT | wh-determiner |
WP | wh-pronoun、個人 |
WP$ | wh-pronoun、所有 |
WRB | wh-adverb |
prose v2.0.0には、デフォルトで人( PERSON )と地理的/政治的実体( GPE )を識別できるV1.0.0のチャンクパッケージの大幅な改良バージョンが含まれています。
package main
import (
"github.com/jdkato/prose/v2"
)
func main () {
doc , _ := prose . NewDocument ( "Lebron James plays basketball in Los Angeles." )
for _ , ent := range doc . Entities () {
fmt . Println ( ent . Text , ent . Label )
// Lebron James PERSON
// Los Angeles GPE
}
}ただし、この機能をより便利にするために、特定のユースケースのために独自のモデルをトレーニングすることを簡単にしました。 Prodigy + prose : Go for a Tutorialの根本的に効率的なマシンティーチングを参照してください。