Flair 由 Zalando Research 開發及開源,是基於 Pytorch 的 NLP 框架。簡單易懂、操作方便。
-一個強大的NLP庫。Flair允許用戶將最先進的自然語言處理模型應用於文本。
例如命名實體識別(NER),詞性標註(PoS),意義消歧和分類。
-多語言支持。
-一個文本embedding庫。Flair提供簡單的接口,來使用集成不同單詞與文檔,如Flair embeddings, BERT embeddings and ELMo embeddings.
-一個pytorch的NLP框架。Flair直接構建在pytorch之上,訓練你自己的模型會很容易。
目前的版本是0.4.5。
依賴:PyTorch 1.1+ ,Python 3.6+
安裝:pip install flair
使用樣例:
如下是運行NER。
from flair.data import Sentence
from flair.models import SequenceTagger
# make a sentence
sentence = Sentence('I love Berlin .')
# load the NER tagger
tagger = SequenceTagger.load('ner')
# run NER over sentence
tagger.predict(sentence)
print(sentence)
print('The following NER tags are found:')
# iterate over entities and print
for entity in sentence.get_spans('ner'):
print(entity)
打印輸出的內容是:
Sentence: "I love Berlin ." - 4 Tokens
The following NER tags are found:
LOC-span [3]: "Berlin"
閱讀更多 AI踐行者 的文章