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.
Returns: List of NER labels. Return type: list
ofstr
-
predict
(sentences, batch_size=32)¶ Predict the named entity labels of a list of sentences.
Parameters: Returns: The predicted named entity labels for the given sentences.
Return type:
-
predict_sentence
(sentence)¶ Predict the named entity labels of a single sentence.
Parameters: sentence ( list
ofstr
) – The input sentence.Returns: The predicted named entity labels for the given sentence. Return type: list
ofstr
-
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:
-
static
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)))