camel_tools.ner
This module contains the CAMeL Tools Named Entity Recognition component.
Classes
- class camel_tools.ner.NERecognizer(model_path, use_gpu=True)
CAMeL Tools NER component.
- Parameters:
- static labels()
Get the list of NER labels returned by predictions.
- predict(sentences, batch_size=32)
Predict the named entity labels of a list of sentences.
- predict_sentence(sentence)
Predict the named entity labels of a single sentence.
- static pretrained(model_name=None, use_gpu=True)
Load a pre-trained model provided with camel_tools.
- Parameters:
- Returns:
Instance with loaded pre-trained model.
- Return type:
Examples
Below is an example of how to load and use the default pre-trained model.
from camel_tools.ner import NERecognizer
ner = NERecognizer.pretrained()
# Predict the labels of a single sentence.
# The sentence must be pretokenized by whitespace and punctuation.
sentence = 'إمارة أبوظبي هي إحدى إمارات دولة الإمارات العربية المتحدة السبع .'.split()
labels = ner.predict_sentence(sentence)
# Print the list of token-label pairs
print(list(zip(sentence, labels)))