.vscode | ||
data | ||
resource | ||
trained | ||
.gitignore | ||
al_ner.py | ||
check_tokenizer.py | ||
classifier.py | ||
data_helper.py | ||
do_ner_for_110_sections.py | ||
do_ner_reg.py | ||
do_ner_task.py | ||
evaluate_model.py | ||
farsi_tokenizers_result.txt | ||
farsi_tokenizers.txt | ||
find_law.py | ||
findlaw.log | ||
flair_fine_tune.py | ||
flair_linker.py | ||
founded_law_1.txt | ||
founded_law_2.txt | ||
founded_law_3.txt | ||
founded_law.txt | ||
funcs.py | ||
functions.py | ||
general_functions.py | ||
getdata.py | ||
inf2.py | ||
inference.py | ||
mail.py | ||
ner_proccess.py | ||
ner_reg_errors.txt | ||
ner_reg_errors2.txt | ||
normalizer.py | ||
peyma_dataset_14030427.log | ||
README.md | ||
rel_update_0413.log | ||
relation_update.py | ||
relation.py | ||
services.py | ||
similarity.py | ||
sp_ner.py | ||
test_inf.py | ||
test.py | ||
tokenizer.py | ||
train_2.py | ||
train.py | ||
training.json |
NER (Named Entity Recognition)
Requirements
pip install flair
Download Models
download models and place in data folder https://drive.google.com/file/d/1mBW3zA8sd1zDo7KOiUCXmG64h8eJc_ip/view
Getting started
python flair_ner_inference_.py
for train:
python flair_ner_train.py
Documentation
Flair is:
-
A powerful NLP library. Flair allows you to apply our state-of-the-art natural language processing (NLP) models to your text, such as named entity recognition (NER), sentiment analysis, part-of-speech tagging (PoS), special support for biomedical data, sense disambiguation and classification, with support for a rapidly growing number of languages.
-
A text embedding library. Flair has simple interfaces that allow you to use and combine different word and document embeddings, including our proposed Flair embeddings and various transformers.
-
A PyTorch NLP framework. Our framework builds directly on PyTorch, making it easy to train your own models and experiment with new approaches using Flair embeddings and classes.
Quick Start Flair
Requirements and Installation
In your favorite virtual environment, simply do:
pip install flair
Flair requires Python 3.7+.
Example 1: Tag Entities in Text
Let's run named entity recognition (NER) over an example sentence. All you need to do is make a Sentence
, load
a pre-trained model and use it to predict tags for the sentence:
from flair.data import Sentence
from flair.nn import Classifier
# make a sentence
sentence = Sentence('I love Berlin .')
# load the NER tagger
tagger = Classifier.load('ner')
# run NER over sentence
tagger.predict(sentence)
# print the sentence with all annotations
print(sentence)
This should print:
Sentence: "I love Berlin ." → ["Berlin"/LOC]
This means that "Berlin" was tagged as a location entity in this sentence.
- to learn more about NER tagging in Flair, check out our NER tutorial!
Example 2: Detect Sentiment
Let's run sentiment analysis over an example sentence to determine whether it is POSITIVE or NEGATIVE. Same code as above, just a different model:
from flair.data import Sentence
from flair.nn import Classifier
# make a sentence
sentence = Sentence('I love Berlin .')
# load the NER tagger
tagger = Classifier.load('sentiment')
# run NER over sentence
tagger.predict(sentence)
# print the sentence with all annotations
print(sentence)
This should print:
Sentence[4]: "I love Berlin ." → POSITIVE (0.9983)
This means that the sentence "I love Berlin" was tagged as having POSITIVE sentiment.
- to learn more about sentiment analysis in Flair, check out our sentiment analysis tutorial!
Tutorials
On our new 🔥 Flair documentation page you will find many tutorials to get you started!
In particular:
- Tutorial 1: Basic tagging → how to tag your text
- Tutorial 2: Training models → how to train your own state-of-the-art NLP models
- Tutorial 3: Embeddings → how to produce embeddings for words and documents
There is also a dedicated landing page for our biomedical NER and datasets with installation instructions and tutorials.