Úvod
Objekt nlp
# Import the English language class from spacy.lang.en
from spacy.lang.en import English
# Create the nlp object
nlp = English()
- obsahuje
pipeliny
pro zpracování
- obsahuje pravidla pro tokenizaci pro daný jazyk
Objekt dokumentu
# Created by processing a string of text with the nlp object
doc = nlp("Hello world!")
# Iterate over tokens in a Doc
for token in doc:
print(token.text)
Objekt tokenu
doc = nlp("Hello world!")
# Index into the Doc to get a single Token
token = doc[1]
# Get the token text via the .text attribute
print(token.text)
Objekt spanu
doc = nlp("Hello world!")
# A slice from the Doc is a Span object
span = doc[1:3]
# Get the span text via the .text attribute
print(span.text)
Lexikální atributy
doc = nlp("It costs $5.")
print("Index: ", [token.i for token in doc])
print("Text: ", [token.text for token in doc])
print("is_alpha:", [token.is_alpha for token in doc])
print("is_punct:", [token.is_punct for token in doc])
print("like_num:", [token.like_num for token in doc])
Statistické modely
- umožňují odhadnout lingvistické atributy v kontextu textu
- větné členy (Part-of-speech tags)
- slovní druhy (Syntactic dependencies)
- typy entity (Named entities)
- jsou trénovány na označeném textu
- mohou být zdokonalovány při více příkladech
Balíčky s modely
- Binary weights
- Vocabulary
- Meta information (language, pipeline)
$ python -m spacy download en_core_web_sm
- stažení natrénovaného modelu
import spacy
nlp = spacy.load("en_core_web_sm")
Zdroje
- https://course.spacy.io/en/chapter1
-