
# # Arabic text classification using deep learning (ArabicT5)

# # Our experiment 

  - The category mapping:
     category_mapping = {
      'Politics':1,
      'Finance':2,
      'Medical':3,
      'Sports':4,
      'Culture':5,
      'Tech':6,
      'Religion':7
     }
    
  - Training parameters
|                       |              |
| :-------------------: | :-----------:|
|  Training batch size  |     `8`      |
| Evaluation batch size |     `8`      |
|     Learning rate     |    `1e-4`    |
|    Max length input   |    `200`     |
|   Max length target   |     `3`      |
|     Number workers    |     `4`      |
|         Epoch         |     `2`      |
|                       |              |

  - Results
|                         |               |
| :---------------------: | :-----------: | 
|   Validation Loss       |   `0.0479`    |  
|        Accuracy         |   `96.49%`    | 
|          BLeU           |   `96.49%`    |

# # SANAD: Single-label Arabic News Articles Dataset for automatic text categorization
  
  - Paper
    [https://www.researchgate.net/publication/333605992_SANAD_Single-Label_Arabic_News_Articles_Dataset_for_Automatic_Text_Categorization]
  
  - Dataset
    [https://data.mendeley.com/datasets/57zpx667y9/2]

# # Arabic text classification using deep learning models

  - Paper
[https://www.sciencedirect.com/science/article/abs/pii/S0306457319303413]

  - Their experiment'
"Our experimental results showed that all models did very well on SANAD corpus with a minimum accuracy of 93.43%, achieved by CGRU, and top performance of 95.81%, achieved by HANGRU."
|         Model           |         Accuracy        | 
| :---------------------: | :---------------------: | 
|           CGRU          |          93.43%         |   
|          HANGRU         |          95.81%         | 

# # Example usage
```python
from transformers import T5ForConditionalGeneration, T5Tokenizer

model_name="Hezam/ArabicT5_Classification"
model = T5ForConditionalGeneration.from_pretrained(model_name)
tokenizer = T5Tokenizer.from_pretrained(model_name)

text = "الزين فيك القناه الاولي المغربيه الزين فيك القناه الاولي المغربيه اخبارنا المغربيه  متابعه تفاجا زوار موقع القناه الاولي المغربي"
tokens=tokenizer(text, max_length=200,
                    truncation=True,
                    padding="max_length",
                    return_tensors="pt"
                )

output= model.generate(tokens['input_ids'],
                       max_length=3,
                       length_penalty=10)

output = [tokenizer.decode(ids, skip_special_tokens=True,clean_up_tokenization_spaces=True)for ids in output]
output

```
```bash
['5']
```
{"language": ["ar"], "library_name": "transformers", "tags": ["t5", "Classification", "ArabicT5", "Text Classification"], "metrics": ["bleu", "accuracy"], "pipeline_tag": "text-classification", "widget": [{"example_title": "\u0627\u0644\u062f\u064a\u0646\u064a\n"}, {"text": "\u0627\u0644\u062d\u0645\u062f \u0644\u0644\u0647 \u0631\u0628 \u0627\u0644\u0639\u0627\u0644\u0645\u064a\u0646 \u0648\u0627\u0644\u0635\u0644\u0627\u0629 \u0648\u0627\u0644\u0633\u0644\u0627\u0645 \u0639\u0644\u0649 \u0633\u064a\u062f \u0627\u0644\u0645\u0631\u0633\u0644\u064a\u0646 \u0646\u0628\u064a\u0646\u0627 \u0645\u062d\u0645\u062f \u0648\u0622\u0644\u0647 \u0648\u0635\u062d\u0628\u0647 \u0623\u062c\u0645\u0639\u064a\u0646\u060c\u0648\u0628\u0639\u062f:\u0641\u0625\u0646\u0647 \u064a\u062c\u0628 \u0639\u0644\u0649 \u0627\u0644\u0639\u0628\u062f \u0623\u0646 \u064a\u062a\u062c\u0646\u0628 \u0627\u0644\u0630\u0646\u0648\u0628 \u0643\u0644\u0647\u0627 \u062f\u0642\u0647\u0627 \u0648\u062c\u0644\u0647\u0627 \u0635\u063a\u064a\u0631\u0647\u0627 \u0648\u0643\u0628\u064a\u0631\u0647\u0627 \u0648\u0623\u0646 \u064a\u062a\u0639\u0627\u0647\u062f \u0646\u0641\u0633\u0647 \u0628\u0627\u0644\u062a\u0648\u0628\u0629 \u0627\u0644\u0635\u0627\u062f\u0642\u0629 \u0648\u0627\u0644\u0625\u0646\u0627\u0628\u0629 \u0625\u0644\u0649 \u0631\u0628\u0647. \u0642\u0627\u0644 \u062a\u0639\u0627\u0644\u0649: (\u0648\u064e\u062a\u064f\u0648\u0628\u064f\u0648\u0627 \u0625\u0650\u0644\u064e\u0649 \u0627\u0644\u0644\u0651\u064e\u0647\u0650 \u062c\u064e\u0645\u0650\u064a\u0639\u064b\u0627 \u0623\u064e\u064a\u0651\u064f\u0647\u064e\u0627 \u0627\u0644\u0652\u0645\u064f\u0624\u0652\u0645\u0650\u0646\u064f\u0648\u0646\u064e \u0644\u064e\u0639\u064e\u0644\u0651\u064e\u0643\u064f\u0645\u0652 \u062a\u064f\u0641\u0652\u0644\u0650\u062d\u064f\u0648\u0646\u064e)\u0627\u0644\u0646\u0648\u0631 31."}]}
transformers pytorch t5 text2text-generation Classification ArabicT5 Text Classification text-classification ar autotrain_compatible endpoints_compatible text-generation-inference region:us