Komponen kompleks
Pada latihan ini, Anda akan menulis sebuah komponen kustom yang menggunakan PhraseMatcher untuk menemukan nama hewan dalam dokumen dan menambahkan span yang cocok ke doc.ents.
Sebuah PhraseMatcher dengan pola hewan sudah dibuat sebagai variabel matcher. Model bahasa Inggris kecil tersedia sebagai variabel nlp. Objek Span sudah diimpor untuk Anda.
Latihan ini adalah bagian dari kursus
NLP Lanjutan dengan spaCy
Latihan interaktif praktis
Cobalah latihan ini dengan menyelesaikan kode contoh berikut.
# Define the custom component
def animal_component(doc):
# Apply the matcher to the doc
matches = ____
# Create a Span for each match and assign the label 'ANIMAL'
spans = [Span(____, ____, ___, label=____)
for match_id, start, end in matches]
# Overwrite the doc.ents with the matched spans
doc.ents = spans
return doc