Allennlp 安装和使用问题

  1. 安装指令

    pip install allennlp
    pip install allennlp-models
    
  2. coreference resolution的应用

    from allennlp.predictors.predictor import Predictor
    # path can be url or local path (pre-downloaded file)
    predictor = Predictor.from_path("https://storage.googleapis.com/allennlp-public-models/coref-spanbert-large-2021.03.10.tar.gz")
    text = "Eva and Martha didn't want their friend Jenny to feel lonely so they invited her to the party."
    prediction = predictor.predict(document=text)  # get prediction
    print(prediction['clusters'])  # list of clusters (the indices of spaCy tokens) 
    # Result: [[[0, 2], [6, 6], [13, 13]], [[6, 8], [15, 15]]]
    print(predictor.coref_resolved(text))  # resolved text
    # Result: "Eva and Martha didn't want Eva and Martha's friend Jenny to feel lonely so Eva and Martha invited their friend Jenny to the party."
    

    其他相关问题:
    (1)allennlp + wordnet + zipfile.BadZipFile error
    (2)离线安装nltk_data

  3. spacy安装和使用问题(tokenizer)

    pip install spacy
    
    import spacy
    nlp = spacy.load('en_core_web_sm')  # load the model
    text = "Eva and Martha didn't want their friend Jenny to feel lonely so they invited her to the party."
    doc = nlp(text)  # get the spaCy Doc (composed of Tokens)
    print(list(doc)) # tokens
    

    加载en_core_web_sm模型可能会出现SSL error的问题,可以到官方release下载和当前spacy版本对应的模型,然后利用pip进行安装:

    pip show spacy # show the version of spacy
    pip install en_core_web_sm-x.x.x.tar.gz # install the model without proxy - method 1
    python -m spacy download en_core_web_sm # install the model with proxy - method 2
    

    其他相关问题:
    (1)解决neuralcoref和spacy版本兼容性问题

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值