Pemrosesan Bahasa Alami dengan spaCy
Azadeh Mobasher
Principal Data Scientist
import spacynlp = spacy.load("en_core_web_sm")doc = nlp("Here's my spaCy pipeline.")
spaCyspacy.load() untuk mengembalikan nlp, sebuah kelas LanguageLanguage adalah pipeline pemrosesan teksnlp() pada teks apa pun untuk mendapatkan kontainer Doc
spaCy menjalankan beberapa langkah pemrosesan menggunakan kelas Language:
spaCy:
| Name | Description |
|---|---|
Doc |
Kontainer untuk mengakses anotasi linguistik teks |
Span |
Potongan dari objek Doc |
Token |
Satu token, mis. kata, tanda baca, spasi, dll. |
spaCy selalu bergantung pada model yang dimuat dan kemampuannya.
| Component | Name | Description |
|---|---|---|
| Tokenizer | Tokenizer | Membagi teks menjadi token dan membuat objek Doc |
| Tagger | Tagger | Memberi tag part-of-speech |
| Lemmatizer | Lemmatizer | Mengurangi kata ke bentuk dasar |
| EntityRecognizer | NER | Mendeteksi dan memberi label entitas bernama |
Tiap komponen punya fitur unik untuk memproses teks
import spacy nlp = spacy.load("en_core_web_sm") doc = nlp("Tokenization splits a sentence into its tokens.")print([token.text for token in doc])
['Tokenization', 'splits', 'a', 'sentence', 'into', 'its', 'tokens', '.']
DependencyParserimport spacy nlp = spacy.load("en_core_web_sm") text = "We are learning NLP. This course introduces spaCy." doc = nlp(text)for sent in doc.sents: print(sent.text)
We are learning NLP.
This course introduces spaCy.
import spacy nlp = spacy.load("en_core_web_sm") doc = nlp("We are seeing her after one year.")print([(token.text, token.lemma_) for token in doc])
[('We', 'we'), ('are', 'be'), ('seeing', 'see'), ('her', 'she'),
('after', 'after'), ('one', 'one'), ('year', 'year'), ('.', '.')]
Pemrosesan Bahasa Alami dengan spaCy