This module contains the CAMeL Tools Named Entity Recognition component.


class camel_tools.ner.NERecognizer(model_path)

CAMeL Tools NER component.

Parameters:model_path (str) – The path to the fine-tuned model.
static labels()

Get the list of NER labels returned by predictions.

Returns:List of NER labels.
Return type:list of str

Predict the named entity labels of a list of sentences.

  • sentences (list of list of str) – The input
  • sentences.

The predicted named entity labels for the given sentences.

Return type:

list of list of str


Predict the named entity labels of a single sentence.

Parameters:sentence (list of str) – The input sentence.
Returns:The predicted named entity labels for the given sentence.
Return type:list of str
static pretrained(model_name=None)

Load a pre-trained model provided with camel_tools.

Parameters:model_name (str, optional) – Name of pre-trained model to load. One model is available: ‘arabert’. If None, the default model (‘arabert’) will be loaded. Defaults to None.
Returns:Instance with loaded pre-trained model.
Return type:NERecognizer


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)))