The primary supported task for this model is named entity recognition (NER) in Arabic. However, it can also be used to explore the zero-shot cross-lingual capabilities of multilingual models, allowing for NER in various languages.
-
Arabic Named Entity Recognition: BERT-base_NER-ar can be used to extract named entities (such as names of people, locations, and organizations) from Arabic text. This is valuable for information retrieval, text summarization, and content analysis in Arabic language applications.
-
Multilingual NER: The model's multilingual capabilities enable it to perform NER in other languages supported by the "wikiann" dataset, making it versatile for cross-lingual NER tasks.
-
Language Limitation: While the model supports multiple languages, it may not perform equally well in all of them. Performance could vary depending on the quality and quantity of training data available for specific languages.
-
Fine-Tuning Data: The model's performance is dependent on the quality and representativeness of the fine-tuning data (the "wikiann" dataset in this case). If the dataset is limited or biased, it may affect the model's performance.
1from transformers import AutoModelForTokenClassification, AutoTokenizer
2import torch
3# Load the fine-tuned model
4model = AutoModelForTokenClassification.from_pretrained("ayoubkirouane/BERT-base_NER-ar")
5tokenizer = AutoTokenizer.from_pretrained("ayoubkirouane/BERT-base_NER-ar")
6
7# Tokenize your input text
8text = "عاصمة فلسطين هي القدس الشريف."
9tokens = tokenizer.tokenize(tokenizer.decode(tokenizer.encode(text)))
10
11# Convert tokens to input IDs
12input_ids = tokenizer.convert_tokens_to_ids(tokens)
13
14# Perform NER inference
15with torch.no_grad():
16 outputs = model(torch.tensor([input_ids]))
17
18# Get the predicted labels for each token
19predicted_labels = outputs[0].argmax(dim=2).cpu().numpy()[0]
20
21# Map label IDs to human-readable labels
22predicted_labels = [model.config.id2label[label_id] for label_id in predicted_labels]
23
24# Print the tokenized text and its associated labels
25for token, label in zip(tokens, predicted_labels):
26 print(f"Token: {token}, Label: {label}")
27