spaCy ile İleri Düzey NLP
Ines Montani
spaCy core developer
nlp.pipe metodunu kullanınDoc nesneleri üretirnlp çağırmaktan çok daha hızlıdırKÖTÜ:
docs = [nlp(text) for text in LOTS_OF_TEXTS]
İYİ:
docs = list(nlp.pipe(LOTS_OF_TEXTS))
nlp.pipe üzerinde as_tuples=True ayarlamak, (text, context) ikilileri geçirmenizi sağlar(doc, context) ikilileri üretirdoc ile meta verileri ilişkilendirmek için yararlıdırdata = [ ('This is a text', {'id': 1, 'page_number': 15}), ('And another text', {'id': 2, 'page_number': 16}), ]for doc, context in nlp.pipe(data, as_tuples=True): print(doc.text, context['page_number'])
This is a text 15
And another text 16
from spacy.tokens import Doc Doc.set_extension('id', default=None) Doc.set_extension('page_number', default=None)data = [ ('This is a text', {'id': 1, 'page_number': 15}), ('And another text', {'id': 2, 'page_number': 16}), ] for doc, context in nlp.pipe(data, as_tuples=True): doc._.id = context['id'] doc._.page_number = context['page_number']

Doc nesnesine dönüştürmek için nlp.make_doc kullanınKÖTÜ:
doc = nlp("Hello world")
İYİ:
doc = nlp.make_doc("Hello world!")
nlp.disable_pipes kullanın# Etiketleyici ve ayrıştırıcıyı devre dışı bırak
with nlp.disable_pipes('tagger', 'parser'):
# Metni işle ve varlıkları yazdır
doc = nlp(text)
print(doc.ents)
with bloğundan sonra bunları geri yüklerspaCy ile İleri Düzey NLP