![](/img/trans.png)
[英]How to group words of a string into different strings using pre-defined word groups in python?
[英]How to extract pre-defined key words from a sentence in Python?
考慮以下示例“所有人工智能課程的 10%”。 在這個例子中,我必須提取兩個預定義的類,比如人工智能和課程。 甚至程序也必須將 ANN、CNN、RNN、AI 等詞分類到人工智能類別中。 我使用 spacy 進行訓練,但我對結果印象不深,因為它沒有正確標記。 有沒有其他方法可以從 Python 中的句子中提取實體?
以下是我會嘗試的幾個選項。
1.使用Rasa進行自定義實體提取。
https://rasa.com/docs/rasa/nlu/entity-extraction/#custom-entities
https://github.com/allenai/scibert
https://github.com/dmis-lab/biobert
您可以使用 flashtext 來執行此操作。
from flashtext import KeywordProcessor
kp = KeywordProcessor()
# make a dictionary and create key , insert all keyword in one key (i.e CNN, ANN RNN will come under artificial Intelligence, whenever this value will appear it will extract key for you )
dict_= {'Artificial Intelligence': ['ANN','CNN','RNN','AI','Artificial Intelligence'],'courses' : ['courses']}
kp.add_keywords_from_dict(dict_)
# here Artificial Intelligence, ANN and CNN come under Artificial Intelligence key , that why it will extract the tag as Artificial Intelligence
kp.extract_keywords('10% of on all Artificial Intelligence, ANN, and CNN courses.')
#op
['Artificial Intelligence',
'Artificial Intelligence',
'Artificial Intelligence',
'courses']
有關更多信息,您可以關注 flashtext https 的文檔://readthedocs.org/projects/flashtext/downloads/pdf/latest/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.