美文网首页
spacy包的学习笔记

spacy包的学习笔记

作者: jiarf | 来源:发表于2021-01-05 09:05 被阅读0次

    主要是为了在一段文字中找到自己想要的名词和之间的依存关系 。
    教程:https://blog.csdn.net/YWP_2016/article/details/102851532?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromBaidu-4.control&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromBaidu-4.control
    用的jupyter进行的实验:

    #spacy安装
    !pip install spacy
    import spacy
    from spacy.lang.en import English
    text = "Keratinocyte replicative senescence has an important role in time-related changes of epidermis. Previous studies demonstrated that miRNAs play key roles in inhibiting proliferation and in the acquisition of the keratinocyte senescent phenotype as well as in individual ageing. Kruppel-like factor 4 is a transcription factor with dual functions in keratinocytes, being a stemness factor and a pro-differentiation factor. Interestingly, in skin squamous cell carcinomas KLF4 expression is strongly down-regulated or absent. While KLF4 involvement in senescence and ageing has not been investigated yet. Here, we show that Klf4 protein decreases during keratinocyte replicative senescence and during physiological skin aging, while its mRNA level does not change. We demonstrated that the senescence-associated miR-34a regulates post-transcriptionally Klf4 expression. KLF4 silencing is sufficient to induce a senescent phenotype in primary keratinocytes and ectopic miR-34a over-expression phenocopies this result. Our findings identify a novel regulatory loop between miR-34a and KLF4 during keratinocytes replicative senescence. This regulatory loop, beside aging, may play a role in age-related pathologies."
    nlp = spacy.load('en_core_web_sm')#让Spacy使用英语模型,将模型存储到变量nlp;注:anaconda中可以使用spacy.load('en')但pycharm中无法使用,故修改
    

    但是此时有警告,是因为我之前下载的en_core_web_sm的版本号太低导致

    E:\software\anaconda\lib\site-packages\spacy\util.py:275: UserWarning: [W031] Model 'en_core_web_sm' (2.2.0) requires spaCy v2.2 and is incompatible with the current spaCy version (2.3.4). This may lead to unexpected results or runtime errors. To resolve this, download a newer compatible model or retrain your custom model with the current spaCy version. For more details and available updates, run: python -m spacy validate
      warnings.warn(warn_msg)
    

    所有下来想办法能不能更新en_core_web_sm的版本号
    https://blog.csdn.net/hjzgj263446/article/details/103527952
    这篇教程里有2.2的最起码比我的2高一点,先试试。
    en_core_web_sm-2.2.5:网盘下载 提取码:jnmw
    但是如何将这个包代替掉之前那个呢?
    等等又找到一个更新的教程,不需要之前那个2.2.5的了,这里有2.3的,而且还挺新的:https://blog.csdn.net/kunAUGUST/article/details/106841865
    只需要重新安装一下就行

    image.png
    pip --default-timeout=10000 install https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-2.3.0/en_core_web_sm-2.3.0.tar.gz
    

    时间还是挺长的。

    image.png
    报错了。。。
    查到有的人说需要冲洗你训练一下model,
    According to the spaCy 2.3 release notes, models need to be retrained on the new version.
    image.png
    但是还需要看看安装的model是不是最新的,

    但是最新的就是上面那个2.3了,所以还是看看怎么能解决ConnectionResetError: [WinError 10054] 远程主机强迫关闭了一个现有的连接。这个问题,分析:出现这种原因代表远程过于频繁,所以远程怀疑是恶意攻击

    我觉得肯是因为pip --dault-1000这个太大了,可能是为了下载速度,造成 了太快,把这个删掉试试。pip install https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-2.3.0/en_core_web_sm-2.3.0.tar.gz

    重新

    好了接下来老板说要去服务器上去做,所以在服务器上搭建一个jupyter,教程在这里,https://zhuanlan.zhihu.com/p/44405596,只是有一个root改掉和最后一个改成False 就可以运行了,但是需要conda重新建一个环境,把软件都装在这个环境里面。
    conda env list用这个命令来查看已有环境。

    Anaconda创建环境:https://blog.csdn.net/h_o_w_e/article/details/77370456
    创建python=3.6版本的环境,取名叫py36
    conda create -n py36 python=3.6
    删除环境(不要乱删啊啊啊)
    conda remove -n py36 --all
    激活环境
    //下面这个py36是个环境名
    conda activate py36 (conda4之前的版本是:source activate py36 )

    退出环境
    conda deactivate (conda4之前的版本是:source deactivate )

    如上所示,我们创建一个jupyter的环境:conda create -n jupyter_notebook jupyter notebook=6.0.3是因为查看了jupyter notebook的版本号

    jupyter notebook --version
    6.0.3
    
    image.png
    那么如何在建设好的环境中安装软件了(也就是说如何在conda指定的环境中安装软件)教程在这里https://www.cnblogs.com/andingding-blog/p/10254522.html,这个是本地的安装,那么服务器上的教程是这个:https://zhuanlan.zhihu.com/p/94744929默认的安装的软件是在base里面,服务器创建jupyter的环境语句,(新的教程在这里https://www.cnblogs.com/hgl0417/p/8204221.html

    创建jupyter环境

    conda create -n jupyter_notebook python=3.6 ipykernel
    

    报错了:

    image.png
    解决:https://cloud.tencent.com/developer/article/1572996
    说是默认的镜像太慢了,换一个镜像,并且把默认的删掉。
    3.1.首先执行如下几条命令更换清华镜像源
    
        conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
    
        conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
    
        conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
    
        conda config --set show_channel_urls yes
    

    更改镜像源配置文件

    在用户根目录(home/username)下找到.condarc文件,打开并并编辑,删除其中的default配置行。
    .重新创建虚拟环境,


    image.png

    好像反而更糟糕了。
    改来改去:发现是condrac那个文件里的default不能有,还有就是出错的那个网站的https要改成http,三个镜像都要改,改一个是不行的


    image.png

    一定要是http而不能为https!

    image.png
    终于创建好了
    image.png
    #
    # To activate this environment, use
    #
    #     $ conda activate jupyter_notebook
    #
    # To deactivate an active environment, use
    #
    #     $ conda deactivate
    
    

    将环境变量写到jupyter中

    将环境写入notebook的kernel中
    python -m ipykernel install --user --name 环境名称 --display-name "环境名称"

    (jupyter_notebook) 11:58:53 jiarongf@172.16.10.223:/data1/jiarongf/Knowledge_Graph/learn
    $
    python -m ipykernel install --user --name jupyter_notebook --display-name jupyter_notebook
    Installed kernelspec jupyter_notebook in /home/jiarongf/.local/share/jupyter/kernels/jupyter_notebook
    

    打开jupyter

    jupyter notebook
    
    image.png

    相关文章

      网友评论

          本文标题:spacy包的学习笔记

          本文链接:https://www.haomeiwen.com/subject/aaumoktx.html