How to use Python StandfordNLP Library
This article mainly explains "how to use the Python StandfordNLP library". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn how to use the Python StandfordNLP library.
Version featur
The new version of StandfordNLP includes the following features:
Pure python library, no configuration items, available directly after pip install
Have almost all the methods needed for natural language processing
Contains a pre-training model that supports 53 languages in 73 tree libraries
Seamless linkage with Stanford CoreNLP
Produced by Stanford NLP team, the quality is guaranteed
Install pip install stanfordnlp use > > import stanfordnlp > > stanfordnlp.download ('en') # this will download the English neural network model > nlp = stanfordnlp.Pipeline () # to get a default English language processing flow > doc = nlp ("Barack Obama was born in Hawaii. He was elected president in 2008. ") > doc.sentences [0] .print _ dependencies () ('Barack',' 4, 'nsubj:pass') (' Obama','1, 'flat') (' was','4, 'aux:pass') (' born','0, 'root') (' in','6, 'case') (' Hawaii','4, 'obl') ('.','4' Punct') Chinese demo > import stanfordnlp > stanfordnlp.download ('zh') # download Chinese Model > nlp = stanfordnlp.Pipeline (lang='zh') # Chinese language processing flow > doc = nlp. > doc.sentences [0] .print _ tokens () # print token Seaworth PROPN World NOUN Economic NOUN Economic NOUN is the annual AUX annual DET global NOUN politics PART business community NOUN sleeves NOUN gathering VERB in VERB together NOUN's annual NOUN event NOUN. . PUNCT > doc.sentences [0] .print _ dependencies () # print dependency analysis tree ('world', '4percent,' nmod') ('world', '4percent,' nmod') ('economy', '4percent,' nmod') ('economy', '16th,' nsubj') ('yes', '16th,' cop') ('every year', '10years,' nmod') ('global', '10') 'nmod') (' political','9', 'case:pref') (' business','10', 'nmod') (' sleeves,'11', 'nsubj') (' Ju','16', 'acl:relcl') (' in','11', 'mark') (' together','11', 'obj') (' of','11', 'mark:relcl') 'nmod') (' event', '0th,' root') ('. ,'16, 'punct') configuration of Pipeline
In StandfordNLP, Pipline configures how StandfordNLP handles data, such as Token,Lemma by default in English, participle, Token and so on in Chinese. The complete Pipline configuration is shown in the following figure:
Import stanfordnlpconfig = {'processors':' tokenize,mwt,pos,lemma,depparse', # configure the model needed to call the Pipline, lang': 'fr', # configure the target language processed by the Pipline # configure the model used in the configuration, and its model path, note The models here are all PyTorch # you can also train your own model 'tokenize_model_path':'. / fr_gsd_models/fr_gsd_tokenizer.pt','mwt_model_path':'. / fr_gsd_models/fr_gsd_mwt_expander.pt','pos_model_path':'. / fr_gsd_models/fr_gsd_tagger.pt' 'pos_pretrain_path':'. / fr_gsd_models/fr_gsd.pretrain.pt','lemma_model_path':'. / fr_gsd_models/fr_gsd_lemmatizer.pt','depparse_model_path':'. / fr_gsd_models/fr_gsd_parser.pt' 'depparse_pretrain_path':'. / fr_gsd_models/fr_gsd.pretrain.pt'} nlp = stanfordnlp.Pipeline (* * config) # initialize Piplinedoc = nlp ("Van Gogh grandit au sein d'une famille del 'ancienne bourgeoisie.") # apply Pipline to the sentence doc.sentences [0] .print _ tokens () # View the result Thank you for reading These are the contents of "how to use the Python StandfordNLP library". After the study of this article, I believe you have a deeper understanding of how to use the Python StandfordNLP library, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!