如何使用spaCy编写代码并运行python文件? (使用Windows) [英] How write code and run python's files using spaCy? (using windows)

查看:151
本文介绍了如何使用spaCy编写代码并运行python文件? (使用Windows)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为spaCY实现一种新的模型语言. 我已经在Windows SO上安装了spaCy(使用官方网站的指南),但是我不知道在哪里以及如何编写和运行以后的文件. 帮帮我,谢谢.

I want to implement a new model language for spaCY. I have installed spaCy (using the guide of the official web site) on my Windows SO but I haven't understand where and how I could write and run my future files. Help me, Thanks.

推荐答案

我希望我能正确理解您的问题:如果您只想使用 spaCy,则只需创建一个Python文件并运行它.

I hope I understand your question correctly: If you only want to use spaCy, you can simply create a Python file, import spacy and run it.

但是,如果要将添加内容到spaCy源中(例如,添加尚不存在的新语言数据),则需要

However, if you want to add things to the spaCy source – for example to add new language data that doesn't yet exist – you need to compile spaCy from source. On Windows, this needs a little more preparation – but it's not that difficult:

  1. 安装 Visual C ++生成工具,其中包括您需要的编译器.
  2. 在GitHub上分叉并克隆 spaCy存储库.
  3. 导航到该目录并通过运行pip install -r requirements.txt安装spaCy的依赖项(其他软件包以及开发人员要求的Cython).
  4. 然后从同一目录运行python setup.py build_ext --inplace.这会将spaCy构建并编译到目录中.
  5. 确保将PYTHONPATH设置为新的spaCy目录.这一点很重要,因此Python知道您要执行此精确版本的spaCy ,而不是要在其他位置安装的其他版本.在Windows上,我通常使用以下命令:set PYTHONPATH=C:\path\to\spacy\directory.还有此线程,其中包含更多信息. (不过,我不是Windows专家-因此,如果有人读过本文并不同意,请随时在这里纠正我.)
  1. Install the Visual C++ Build Tools, which include the compiler you need.
  2. Fork and clone the spaCy repository on GitHub.
  3. Navigate to that directory and install spaCy's dependencies (other packages plus developer requirements like Cython) by running pip install -r requirements.txt.
  4. Then run python setup.py build_ext --inplace from the same directory. This will build and compile spaCy into the directory.
  5. Make sure your PYTHONPATH is set to the new spaCy directory. This is important so Python knows that you want to execute this exact version of spaCy, and not some other one you have installed somewhere else. On Windows, I normally use this command: set PYTHONPATH=C:\path\to\spacy\directory. There's also this thread with more info. (I'm no Windows expert, though – so if anyone reads this and disagrees, feel free to correct me here.)

您现在可以编辑源代码,添加文件并运行它们.如果要添加新语言,建议从开始向spacy/lang添加新目录并创建__init__.py.您可以在添加语言使用指南中找到有关其外观的更多信息.

You can now edit the source, add files and run them. If you want to add a new language, I'd recommend starting by adding a new directory to spacy/lang and creating an __init__.py. You can find more info on how this should look in the usage guide on adding languages.

要测试一切是否正常,请启动Python解释器,然后导入和初始化您的语言.例如,假设您已添加Icelandic.然后,您应该可以执行以下操作:

To test if everything works, start the Python interpreter and import and initialise your language. For example, let's assume you've added Icelandic. You should then be able to do this:

from spacy.lang.is import Icelandic
nlp = Icelandic()

这篇关于如何使用spaCy编写代码并运行python文件? (使用Windows)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆