📌  相关文章
📜  en_core_web_sm - Python (1)

📅  最后修改于: 2023-12-03 15:14:52.456000             🧑  作者: Mango

Introduction to en_core_web_sm - Python

en_core_web_sm is a Python package that provides pre-trained models for natural language processing tasks such as text classification, named entity recognition, and dependency parsing. It is part of the spaCy library, which is a popular open-source tool for NLP.

Installation and Setup

To install en_core_web_sm, you can use pip:

pip install en_core_web_sm

After installation, you need to load the model in your Python script:

import spacy

nlp = spacy.load("en_core_web_sm")
Usage

Once loaded, you can use the pre-trained model to analyze text. For example, to do named entity recognition:

doc = nlp("Apple is looking at buying U.K. startup for $1 billion")
for ent in doc.ents:
    print(ent.text, ent.label_)

This will output:

Apple ORG
U.K. GPE
$1 billion MONEY

You can also use the model for text classification or dependency parsing:

doc = nlp("I want to buy a new laptop")
for token in doc:
    print(token.text, token.dep_, token.head.text, token.head.pos_)

This will output:

I nsubj want VERB
want ROOT want VERB
to aux buy VERB
buy xcomp want VERB
a det laptop NOUN
new amod laptop NOUN
laptop dobj buy VERB
Conclusion

en_core_web_sm is a useful Python package for NLP tasks that require pre-trained models. It is part of the spaCy library, which is a popular tool for NLP. By following the installation and usage instructions, you can analyze text using the pre-trained model and perform tasks such as named entity recognition and dependency parsing.