# Arabic NER Model for AQMAR dataset
Training was conducted over 86 epochs, using a linear decaying learning rate of 2e-05, starting from 0.3 and a batch size of 48 with fastText and Flair forward and backward embeddings.


## Original Dataset:
- [AQMAR](http://www.cs.cmu.edu/~ark/ArabicNER/)

## Results:
- F1-score (micro) 0.9323
- F1-score (macro) 0.9272

|      | True Posititves  | False Positives | False Negatives | Precision | Recall | class-F1 |
|------|-----|----|----|---------|--------|----------|
| LOC  | 164 | 7  | 13 | 0.9591  | 0.9266 | 0.9425   |
| MISC | 398 | 22 | 37 |  0.9476 | 0.9149 | 0.9310   |
| ORG  | 65  | 6  | 9  | 0.9155  | 0.8784 | 0.8966   |
| PER  | 199 | 13 | 13 | 0.9387  | 0.9387 | 0.9387   |

---

# Usage
```python
from flair.data import Sentence
from flair.models import SequenceTagger
import pyarabic.araby as araby
from icecream import ic

arTagger = SequenceTagger.load('megantosh/flair-arabic-MSA-aqmar')

sentence = Sentence('George Washington went to Washington .')
arSentence = Sentence('عمرو عادلي أستاذ للاقتصاد السياسي المساعد في الجامعة الأمريكية  بالقاهرة .')


# predict NER tags
tagger.predict(sentence)
arTagger.predict(arSentence)

# print sentence with predicted tags
ic(sentence.to_tagged_string)
ic(arSentence.to_tagged_string)

```

# Example
see an example from a [similar NER model in Flair](https://huggingface.co/megantosh/flair-arabic-multi-ner)

# Model Configuration
```python
  (embeddings): StackedEmbeddings(
    (list_embedding_0): WordEmbeddings('ar')
    (list_embedding_1): FlairEmbeddings(
      (lm): LanguageModel(
        (drop): Dropout(p=0.1, inplace=False)
        (encoder): Embedding(7125, 100)
        (rnn): LSTM(100, 2048)
        (decoder): Linear(in_features=2048, out_features=7125, bias=True)
      )
    )
    (list_embedding_2): FlairEmbeddings(
      (lm): LanguageModel(
        (drop): Dropout(p=0.1, inplace=False)
        (encoder): Embedding(7125, 100)
        (rnn): LSTM(100, 2048)
        (decoder): Linear(in_features=2048, out_features=7125, bias=True)
      )
    )
  )
  (word_dropout): WordDropout(p=0.05)
  (locked_dropout): LockedDropout(p=0.5)
  (embedding2nn): Linear(in_features=4396, out_features=4396, bias=True)
  (rnn): LSTM(4396, 256, batch_first=True, bidirectional=True)
  (linear): Linear(in_features=512, out_features=14, bias=True)
  (beta): 1.0
  (weights): None
  (weight_tensor) None
)"
2021-03-31 22:19:50,654 ----------------------------------------------------------------------------------------------------
2021-03-31 22:19:50,654 Corpus: "Corpus: 3025 train + 336 dev + 373 test sentences"
2021-03-31 22:19:50,654 ----------------------------------------------------------------------------------------------------
2021-03-31 22:19:50,654 Parameters:
2021-03-31 22:19:50,654  - learning_rate: "0.3"
2021-03-31 22:19:50,654  - mini_batch_size: "48"
2021-03-31 22:19:50,654  - patience: "3"
2021-03-31 22:19:50,654  - anneal_factor: "0.5"
2021-03-31 22:19:50,654  - max_epochs: "150"
2021-03-31 22:19:50,654  - shuffle: "True"
2021-03-31 22:19:50,654  - train_with_dev: "False"
2021-03-31 22:19:50,654  - batch_growth_annealing: "False"
2021-03-31 22:19:50,655 ------------------------------------
 ```
Due to the right-to-left in left-to-right context, some formatting errors might occur. and your code might appear like [this](https://ibb.co/ky20Lnq), (link accessed on 2020-10-27) 
 
 # Citation
*if you use this model, please consider citing [this work](https://www.researchgate.net/publication/358956953_Sequence_Labeling_Architectures_in_Diglossia_-_a_case_study_of_Arabic_and_its_dialects):*
```latex
@unpublished{MMHU21
author = "M. Megahed",
title = "Sequence Labeling Architectures in Diglossia",
year = {2021},
doi = "10.13140/RG.2.2.34961.10084"
url = {https://www.researchgate.net/publication/358956953_Sequence_Labeling_Architectures_in_Diglossia_-_a_case_study_of_Arabic_and_its_dialects}
}
```
{"language": "ar", "license": "apache-2.0", "tags": ["flair", "Text Classification", "token-classification", "sequence-tagger-model"], "datasets": ["AQMAR", "ANERcorp"], "metrics": ["f1"], "thumbnail": "https://www.informatik.hu-berlin.de/en/forschung-en/gebiete/ml-en/resolveuid/a6f82e0d7fa446a59c902cac4cafa9cb/@@images/image/preview", "widget": [{"text": "\u0627\u062e\u062a\u0627\u0631\u0647\u0627 \u062e\u064a\u0631\u064a \u0628\u0634\u0627\u0631\u0629 \u0643\u0645\u0645\u062b\u0644\u0629\u060c \u062f\u0648\u0646 \u0633\u0627\u0628\u0642\u0629 \u0645\u0639\u0631\u0641\u0629 \u0623\u0648 \u062a\u062c\u0631\u0628\u0629 \u062a\u0645\u062b\u064a\u0644\u064a\u0629\u060c \u0644\u062a\u0642\u0641 \u0628\u062c\u0627\u0646\u0628 \u0641\u0627\u062a\u0646 \u062d\u0645\u0627\u0645\u0629 \u0641\u064a \u0641\u064a\u0644\u0645 \u00ab\u064a\u0648\u0645 \u0645\u0631 \u0648\u064a\u0648\u0645 \u062d\u0644\u0648\u00bb (1988) \u0648\u0647\u064a \u0645\u0627 \u0632\u0627\u0644\u062a \u0634\u0627\u0628\u0629 \u0644\u0645 \u062a\u062a\u062e\u0637\u064e \u0639\u0627\u0645\u0647\u0627 \u0627\u0644\u062b\u0627\u0646\u064a"}]}
flair pytorch Text Classification token-classification sequence-tagger-model ar dataset:AQMAR dataset:ANERcorp license:apache-2.0 region:us
TAGS
#flair #pytorch #Text Classification #token-classification #sequence-tagger-model #ar #dataset-AQMAR #dataset-ANERcorp #license-apache-2.0 #region-us 

Arabic NER Model for AQMAR dataset
==================================


Training was conducted over 86 epochs, using a linear decaying learning rate of 2e-05, starting from 0.3 and a batch size of 48 with fastText and Flair forward and backward embeddings.


Original Dataset:
-----------------


* AQMAR


Results:
--------


* F1-score (micro) 0.9323
* F1-score (macro) 0.9272





---


Usage
=====


Example
=======


see an example from a similar NER model in Flair


Model Configuration
===================


Due to the right-to-left in left-to-right context, some formatting errors might occur. and your code might appear like this, (link accessed on 2020-10-27)


*if you use this model, please consider citing this work:*



TAGS
#flair #pytorch #Text Classification #token-classification #sequence-tagger-model #ar #dataset-AQMAR #dataset-ANERcorp #license-apache-2.0 #region-us 

passage: TAGS
#flair #pytorch #Text Classification #token-classification #sequence-tagger-model #ar #dataset-AQMAR #dataset-ANERcorp #license-apache-2.0 #region-us 
