การประมวลผลภาษาธรรมชาติด้วย spaCy
Azadeh Mobasher
Principal Data Scientist
{"I": 1, "got": 2, ...}
| ประโยค | I | got | covid | coronavirus |
|---|---|---|---|---|
| I got covid | 1 | 2 | 3 | |
| I got coronavirus | 1 | 2 | 4 |
มีหลายแนวทางในการสร้าง word vectors:
ตัวอย่าง word vector:
en_core_web_md มีเวกเตอร์ขนาด 300 มิติสำหรับคำ 20,000 คำ
import spacy
nlp = spacy.load("en_core_web_md")
print(nlp.meta["vectors"])
>>> {'width': 300, 'vectors': 20000, 'keys': 514157,
'name': 'en_vectors', 'mode': 'default'}
nlp.vocab: เข้าถึงคลังคำศัพท์ (คลาส Vocab)nlp.vocab.strings: เข้าถึง ID ของคำในคลังคำศัพท์import spacy
nlp = spacy.load("en_core_web_md")
like_id = nlp.vocab.strings["like"]
print(like_id)
>>> 18194338103975822726
.vocab.vectors: เข้าถึง word vectors ของโมเดลหรือของคำ โดยใช้ ID ที่ตรงกันprint(nlp.vocab.vectors[like_id])
>>> array([-2.3334e+00, -1.3695e+00, -1.1330e+00, -6.8461e-01, ...])
การประมวลผลภาษาธรรมชาติด้วย spaCy