Spikex adalah kumpulan pipa yang siap dicolokkan dalam pipa spacy. Ini bertujuan untuk membantu dalam membangun alat ekstraksi pengetahuan dengan upaya yang hampir nol.
Wikigraf tidak pernah begitu cepat kilat:
Doc berdasarkan nama atribut dan pola frasa khusus. Contohnya adalah nounphrasex dan verbphrasex , yang masing -masing mengekstraksi frasa kata benda dan frasa kata kerjaBeberapa persyaratan diwarisi dari Spacy:
Beberapa dependensi menggunakan Cython dan perlu diinstal sebelum Spikex:
pip install cythonIngatlah bahwa lingkungan virtual selalu direkomendasikan, untuk menghindari memodifikasi status sistem.
Pada titik ini, memasang Spikex via PIP adalah perintah satu baris:
pip install spikexPipa Spikex bekerja dengan Spacy, maka model yang perlu dipasang. Ikuti instruksi resmi di sini. Spacy 3.0 baru didukung!
WikiGraph dibangun mulai dari beberapa komponen utama Wikipedia: halaman , kategori dan hubungan di antara mereka.
Membuat WikiGraph dapat memakan waktu, tergantung pada seberapa besar tempat pembuangan wikipedia. Untuk alasan ini, kami menyediakan wikigraf yang siap digunakan:
| Tanggal | Wikigraf | Lang | Ukuran (terkompresi) | Ukuran (memori) | |
|---|---|---|---|---|---|
| 2021-05-20 | enwiki_core | En | 1.3GB | 8GB | |
| 2021-05-20 | SimpleWiki_Core | En | 20MB | 130MB | |
| 2021-05-20 | itwiki_core | DIA | 208MB | 1.2GB | |
| Lebih banyak datang ... |
Spikex menyediakan perintah untuk pintasan mengunduh dan menginstal WikiGraph (Linux atau macOS, Windows belum didukung):
spikex download-wikigraph simplewiki_core WikiGraph dapat dibuat dari baris perintah, menentukan wikipedia mana yang harus diambil dan ke mana harus menyimpannya:
spikex create-wikigraph
< YOUR-OUTPUT-PATH >
--wiki < WIKI-NAME, default: en >
--version < DUMP-VERSION, default: latest >
--dumps-path < DUMPS-BACKUP-PATH > Maka itu perlu dikemas dan diinstal:
spikex package-wikigraph
< WIKIGRAPH-RAW-PATH >
< YOUR-OUTPUT-PATH >Ikuti instruksi di akhir proses pengemasan dan instal paket distribusi di lingkungan virtual Anda. Sekarang Anda siap menggunakan wikigraf Anda sesuai keinginan:
from spikex . wikigraph import load as wg_load
wg = wg_load ( "enwiki_core" )
page = "Natural_language_processing"
categories = wg . get_categories ( page , distance = 1 )
for category in categories :
print ( category )
> >> Category : Speech_recognition
> >> Category : Artificial_intelligence
> >> Category : Natural_language_processing
> >> Category : Computational_linguisticsPencocokan identik dengan yang Spacy, tetapi lebih cepat dalam hal menangani banyak pola sekaligus (urutan ribuan), jadi ikuti instruksi penggunaan resmi di sini.
Contoh sepele:
from spikex . matcher import Matcher
from spacy import load as spacy_load
nlp = spacy_load ( "en_core_web_sm" )
matcher = Matcher ( nlp . vocab )
matcher . add ( "TEST" , [[{ "LOWER" : "nlp" }]])
doc = nlp ( "I love NLP" )
for _ , s , e in matcher ( doc ):
print ( doc [ s : e ])
> >> NLP Pipa WikiPageX menggunakan WikiGraph untuk menemukan potongan dalam teks yang cocok dengan judul halaman Wikipedia.
from spacy import load as spacy_load
from spikex . wikigraph import load as wg_load
from spikex . pipes import WikiPageX
nlp = spacy_load ( "en_core_web_sm" )
doc = nlp ( "An apple a day keeps the doctor away" )
wg = wg_load ( "simplewiki_core" )
wpx = WikiPageX ( wg )
doc = wpx ( doc )
for span in doc . _ . wiki_spans :
print ( span . _ . wiki_pages )
> >> [ 'An' ]
> >> [ 'Apple' , 'Apple_(disambiguation)' , 'Apple_(company)' , 'Apple_(tree)' ]
> >> [ 'A' , 'A_(musical_note)' , 'A_(New_York_City_Subway_service)' , 'A_(disambiguation)' , 'A_(Cyrillic)' )]
> >> [ 'Day' ]
> >> [ 'The_Doctor' , 'The_Doctor_(Doctor_Who)' , 'The_Doctor_(Star_Trek)' , 'The_Doctor_(disambiguation)' ]
> >> [ 'The' ]
> >> [ 'Doctor_(Doctor_Who)' , 'Doctor_(Star_Trek)' , 'Doctor' , 'Doctor_(title)' , 'Doctor_(disambiguation)' ] Pipa ClusterX mengambil potongan kata benda dalam teks dan kelompok mereka menggunakan algoritma mapper bola radial.
from spacy import load as spacy_load
from spikex . pipes import ClusterX
nlp = spacy_load ( "en_core_web_sm" )
doc = nlp ( "Grab this juicy orange and watch a dog chasing a cat." )
clusterx = ClusterX ( min_score = 0.65 )
doc = clusterx ( doc )
for cluster in doc . _ . cluster_chunks :
print ( cluster )
> >> [ this juicy orange ]
> >> [ a cat , a dog ]Pipa ABBRX menemukan singkatan dan akronim dalam teks, menghubungkan bentuk pendek dan panjang bersama -sama:
from spacy import load as spacy_load
from spikex . pipes import AbbrX
nlp = spacy_load ( "en_core_web_sm" )
doc = nlp ( "a little snippet with an abbreviation (abbr)" )
abbrx = AbbrX ( nlp . vocab )
doc = abbrx ( doc )
for abbr in doc . _ . abbrs :
print ( abbr , "->" , abbr . _ . long_form )
> >> abbr - > abbreviation Pipa LabelX cocok dengan dan label pola dalam teks, menyelesaikan tumpang tindih, singkatan dan akronim.
from spacy import load as spacy_load
from spikex . pipes import LabelX
nlp = spacy_load ( "en_core_web_sm" )
doc = nlp ( "looking for a computer system engineer" )
patterns = [
[{ "LOWER" : "computer" }, { "LOWER" : "system" }],
[{ "LOWER" : "system" }, { "LOWER" : "engineer" }],
]
labelx = LabelX ( nlp . vocab , [( "TEST" , patterns )], validate = True , only_longest = True )
doc = labelx ( doc )
for labeling in doc . _ . labelings :
print ( labeling , f"[ { labeling . label_ } ]" )
> >> computer system engineer [ TEST ] Pipa PhraseX membuat ekstensi garis bawah Doc khusus yang memenuhi dengan kecocokan dari pola frasa.
from spacy import load as spacy_load
from spikex . pipes import PhraseX
nlp = spacy_load ( "en_core_web_sm" )
doc = nlp ( "I have Melrose and McIntosh apples, or Williams pears" )
patterns = [
[{ "LOWER" : "mcintosh" }],
[{ "LOWER" : "melrose" }],
]
phrasex = PhraseX ( nlp . vocab , "apples" , patterns )
doc = phrasex ( doc )
for apple in doc . _ . apples :
print ( apple )
> >> Melrose
> >> McIntoshPipa SentX membagi kalimat dalam teks. Ini memodifikasi atribut token ' is_sent_start , jadi wajib menambahkannya sebelum pipa parser di pipa spacy:
from spacy import load as spacy_load
from spikex . pipes import SentX
from spikex . defaults import spacy_version
if spacy_version >= 3 :
from spacy . language import Language
@ Language . factory ( "sentx" )
def create_sentx ( nlp , name ):
return SentX ()
nlp = spacy_load ( "en_core_web_sm" )
sentx_pipe = SentX () if spacy_version < 3 else "sentx"
nlp . add_pipe ( sentx_pipe , before = "parser" )
doc = nlp ( "A little sentence. Followed by another one." )
for sent in doc . sents :
print ( sent )
> >> A little sentence .
> >> Followed by another one .Jangan ragu untuk berkontribusi dan bersenang -senang!