Allennlp 安装和使用问题

Allennlp 安装和使用问题,第1张

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版本兼容性问题

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5657733.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存