简体   繁体   English

如何安装语言模型

[英]How to install a language model

I am exploring using NLP for some machine learning projects.我正在探索将 NLP 用于一些机器学习项目。 I normally code all of my projects using python through Anaconda using either Jupyter notebooks or PyCharm as my IDE.我通常使用 Jupyter notebooks 或 PyCharm 作为我的 IDE,通过 Anaconda 使用 python 对我的所有项目进行编码。

I would like to start using spacy and am planning on attending a workshop on it in the near future.我想开始使用 spacy,并计划在不久的将来参加一个关于它的研讨会。 Two recommendations were made that I do first.提出了两个建议,我先做了。 Install spacy and install the en_core_web_lg language model.安装 spacy 并安装en_core_web_lg语言模型。 I completed the first step, just by searching for the spacy package in Anaconda environments (the conventional way) and installed it.我完成了第一步,只需在 Anaconda 环境中搜索 spacy 包(常规方式)并安装它。 However, as far as installing the language model, I am less familiar with how to do this to get this on my computer since it is not a traditional package.但是,就安装语言模型而言,我不太熟悉如何在我的计算机上安装它,因为它不是传统的包。

The spacy installation website cites here: https://spacy.io/models/en#en_core_web_lg that this language model can be installed by using: spacy 安装网站在这里引用: https ://spacy.io/models/en#en_core_web_lg 可以使用以下方法安装该语言模型:

INSTALLATION

$ python -m spacy download en_core_web_lg

I am assuming that this is a command through terminal?我假设这是通过终端的命令? I am not very experienced using terminal but tried typing in the above command in one of the command lines and pressed enter and nothing happened.我使用终端不是很有经验,但尝试在其中一个命令行中输入上述命令并按 Enter 键,但没有任何反应。 Is this the correct way to install this model?这是安装此模型的正确方法吗? How should I install it?我应该如何安装它? Also, for pedagogical purposes, what exactly is happening when we install the model?此外,出于教学目的,当我们安装模型时到底发生了什么? It exists on our computer and then can be utilized for NLP in say a Jupyter notebook if called.它存在于我们的计算机上,然后可以在 Jupyter 笔记本中(如果被调用)用于 NLP。

Sorry if these questions seem fairly basic, I am still trying to learn these new techniques.抱歉,如果这些问题看起来相当基础,我仍在努力学习这些新技术。 Any help, references, or advice would be greatly appreciated.任何帮助、参考或建议将不胜感激。

Thanks.谢谢。

You should activate the environment you made and install spacy and then install the model. 您应该激活您创建的环境并安装spacy,然后安装模型。

conda create -n myenv
conda activate myenv
conda install -c conda-forge spacy
python -m spacy download en_core_web_lg

Then you will be able to load the language model. 然后,您将能够加载语言模型。 And, for the second question, you have a local installation of the downloaded model. 并且,对于第二个问题,您具有下载模型的本地安装。 You can use it in your scripts and your notebooks. 您可以在脚本和笔记本中使用它。

Make sure to activate your environment using virtualenv or conda and install spaCy as @Aris mentioned. 确保使用virtualenv或conda激活环境,并按@Aris所述安装spaCy。

To install spaCy 安装spaCy

pip install -U spacy

To install a specific model, run the following command with the model name (for example en_core_web_lg): 要安装特定模型,请使用模型名称运行以下命令(例如,en_core_web_lg):

python -m spacy download [model]

To load a model, use spacy.load() with the model name, a shortcut link or a path to the model data directory. 要加载模型,请使用spacy.load()和模型名称,快捷方式链接或模型数据目录的路径。

import spacy
nlp = spacy.load("en_core_web_sm")
doc = nlp(u"This is a sentence.")

You can also import a model directly via its full name and then call its load() method with no arguments. 您也可以直接通过其全名导入模型,然后不带任何参数调用其load()方法。 This should also work for older models in previous versions of spaCy. 这也适用于以前版本的spaCy中的旧型号。

import spacy
import en_core_web_lg

nlp = en_core_web_lg.load()
doc = nlp(u"This is a sentence.")

Adding to other answers,添加到其他答案,

You can also install the models using pip.您还可以使用 pip 安装模型。 This works on Python 3, but may also work on 2. You can get the wheel link to the models through github page and install using, for example这适用于 Python 3,但也适用于 2。您可以通过 github 页面获取模型的轮链接并安装使用,例如

pip install https://github.com/explosion/spacy-models/releases/download/de_core_news_lg-3.1.0/de_core_news_lg-3.1.0-py3-none-any.whl

Or you can directly add the wheel link to the requirements file.或者您可以直接将车轮链接添加到需求文件中。

https://github.com/explosion/spacy-models/releases https://github.com/explosion/spacy-models/releases

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM