安装sudachi-core的坑

最新在使用spacy调用日语的模型做一些工作,正常情况直接执行下述代码就可以

python -m spacy download ja_core_news_sm 

但是一般会出现下载超时的坑,这是因为除了下载模型,还会下载日语字典之类的文件,如果当前的环境不支持翻墙,则会下载很慢导致报错。

解决问题方法有两种:

1、如果有梯子,则配置全局梯子,这样应该是可以

2、如果是服务器上面梯子不好配置,或者没有梯子的情况,就需要先安装sudachi-core包

直接pip安装sudachi-core仍然会报错的,所以我们需要把源码包下载下来手动安装

使用如下下载命令下载SudachiDict-core

wget "https://pypi.tuna.tsinghua.edu.cn/packages/73/0d/d82b31652781c9ae33ec81871fcc469de5147a7964c94f8caa2bb824d111/SudachiDict-core-20210802.tar.gz" --no-check-certificate

然后下载对应版本的字典(http://sudachi.s3-website-ap-northeast-1.amazonaws.com/sudachidict/sudachi-dictionary-20210802-core.zip

之后就可以解压SudachiDict-core的代码,根据下面的代码,将字典解压放到相应的目录

ZIP_URL = "http://sudachi.s3-website-ap-northeast-1.amazonaws.com/sudachidict/"\
          "sudachi-dictionary-{}-{}.zip".format(DICT_VERSION, DICT_EDITION)
ZIP_NAME = urlparse(ZIP_URL).path.split("/")[-1]
UNZIP_NAME = "sudachi-dictionary-{}".format(DICT_VERSION)
PKG_DIR = "sudachidict_{}".format(DICT_EDITION)
RESOURCE_DIR = os.path.join(PKG_DIR, "resources")
BINARY_NAME = "system_{}.dic".format(DICT_EDITION)

logger = getLogger(__name__)

# Download and place the dictionary file
if not os.path.exists(RESOURCE_DIR):
    logger.warning("Downloading the Sudachi dictionary (It may take a while) ...")
    _, _msg = urlretrieve(ZIP_URL, ZIP_NAME)
    with ZipFile(ZIP_NAME) as z:
        z.extractall()
    os.rename(UNZIP_NAME, RESOURCE_DIR)
    os.rename(os.path.join(RESOURCE_DIR, BINARY_NAME),
              os.path.join(RESOURCE_DIR, "system.dic"))
    os.remove(ZIP_NAME)
    logger.warning("... downloaded and placed the dictionary at `{}`.".format(RESOURCE_DIR))

然后,重新压缩SudachiDict-core为SudachiDict-core-20210802.tar.gz

然后使用pip install SudachiDict-core-20210802.tar.gz 就可以安装完成SudanchiDict-core

为了加速ja的模型包安装,也可以先下载预先下载好模型包,然后直接使用pip install ja_core_news_sm-3.1.0.tar.gz,就可以顺利完成了。

ja模型包地址(https://github.com/explosion/spacy-models/releases/download/ja_core_news_sm-3.1.0/ja_core_news_sm-3.1.0.tar.gz

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值