marefa-ner / README.md
bakrianoo's picture
Fix output logs
9fdcb45
metadata
language: ar
datasets:
  - Marefa-NER

Tebyan تبيـان

Marefa Arabic Named Entity Recognition Model

نموذج المعرفة لتصنيف أجزاء النص


Version: 1.2

Last Update: 22-05-2021

Model description

Marefa-NER is a Large Arabic Named Entity Recognition (NER) model built on a completely new dataset and targets to extract up to 9 different types of entities

Person, Location, Organization, Nationality, Job, Product, Event, Time, Art-Work

نموذج المعرفة لتصنيف أجزاء النص. نموذج جديد كليا من حيث البيانات المستخدمة في تدريب النموذج. كذلك يستهدف النموذج تصنيف حتى 9 أنواع مختلفة من أجزاء النص

شخص - مكان - منظمة - جنسية - وظيفة - منتج - حدث - توقيت - عمل إبداعي

How to use كيف تستخدم النموذج

You can test the model quickly by checking this Colab notebook


Install the following Python packages

$ pip3 install simpletransformers==0.61.5 nltk==3.5 protobuf==3.15.3 torch==1.7.1

If you are using Google Colab, please restart your runtime after installing the packages.


from simpletransformers.ner import NERModel, NERArgs
import logging
import re

import nltk
nltk.download('punkt')
from nltk.tokenize import word_tokenize

# disable INFO Logs
transformers_logger = logging.getLogger("transformers")
simpletransformers_logger = logging.getLogger("simpletransformers")
simpletransformers_ner_logger = logging.getLogger("simpletransformers.ner")
transformers_logger.setLevel(logging.WARNING)
simpletransformers_logger.setLevel(logging.WARNING)
simpletransformers_ner_logger.setLevel(logging.WARNING)

# Load the Model
custom_labels = ["O", "B-job", "I-job", "B-nationality", "B-person", "I-person", "B-location",
                 "B-time", "I-time", "B-event", "I-event", "B-organization", "I-organization",
                 "I-location", "I-nationality", "B-product", "I-product", "B-artwork", "I-artwork"]

model_args = NERArgs()
model_args.labels_list=custom_labels

ner_model = NERModel(
     "xlmroberta", "marefa-nlp/marefa-ner",
     args=model_args,
     use_cuda=True # set to False to use CPU
)

# Model Inference
samples = [
    "تلقى تعليمه في الكتاب ثم انضم الى الأزهر عام 1873م. تعلم على يد السيد جمال الدين الأفغاني والشيخ محمد عبده",
    "بعد عودته إلى القاهرة، التحق نجيب الريحاني فرقة جورج أبيض، الذي كان قد ضمَّ - قُبيل ذلك - فرقته إلى فرقة سلامة حجازي . و منها ذاع صيته",
    "امبارح اتفرجت على مباراة مانشستر يونايتد مع ريال مدريد في غياب الدون كرستيانو رونالدو",
    "Government extends flight ban from India, Pakistan until June 21"
]

# Preprocess
samples = [ " ".join(word_tokenize(sample.strip())) for sample in samples if sample.strip() != "" ]

# Predict
predictions, raw_outputs = ner_model.predict(samples)

# Group the Predicted Entities
entities = []
for pred in predictions:
  grouped_entities = []
  for rec in pred:

    token = list(rec.keys())[0]
    label = rec[token]

    if label == "O":
      continue
    
    if "B-" in label:
      grouped_entities.append({"token": token, "label": label.replace("B-","")})
    elif "I-" in label and len(grouped_entities) > 0:
      grouped_entities[-1]["token"] += f" {token}"
  
  entities.append(grouped_entities)
  
# Print the model outputs
for sample, results in zip(samples, entities):
  print(sample)
  for res in results:
    print("\t", res["token"], "=>", res["label"])
  print("==================")
  
###
# تلقى تعليمه في الكتاب ثم انضم الى الأزهر عام 1873م . تعلم على يد السيد جمال الدين الأفغاني والشيخ محمد عبده
#  الأزهر => organization
#  عام 1873م => time
#  جمال الدين الأفغاني => person
#  محمد عبده => person
# ==================
# بعد عودته إلى القاهرة، التحق نجيب الريحاني فرقة جورج أبيض، الذي كان قد ضمَّ - قُبيل ذلك - فرقته إلى فرقة سلامة حجازي . و منها ذاع صيته
#  القاهرة، => location
#  نجيب الريحاني => person
#  فرقة جورج أبيض، => organization
#  فرقة سلامة حجازي => organization
# ==================
# امبارح اتفرجت على مباراة مانشستر يونايتد مع ريال مدريد في غياب الدون كرستيانو رونالدو
#  مانشستر يونايتد => organization
#  ريال مدريد => organization
#  كرستيانو رونالدو => person
# ==================
# Government extends flight ban from India , Pakistan until June 21
#  India => location
#  Pakistan => location
#  June 21 => time
# ==================
###

Fine-Tuning

Check this notebook to fine-tune the NER model

Acknowledgment شكر و تقدير

قام بإعداد البيانات التي تم تدريب النموذج عليها, مجموعة من المتطوعين الذين قضوا ساعات يقومون بتنقيح البيانات و مراجعتها

  • على سيد عبد الحفيظ - إشراف
  • نرمين محمد عطيه
  • صلاح خيرالله
  • احمد علي عبدربه
  • عمر بن عبد العزيز سليمان
  • محمد ابراهيم الجمال
  • عبدالرحمن سلامه خلف
  • إبراهيم كمال محمد سليمان
  • حسن مصطفى حسن
  • أحمد فتحي سيد
  • عثمان مندو
  • عارف الشريف
  • أميرة محمد محمود
  • حسن سعيد حسن
  • عبد العزيز علي البغدادي
  • واثق عبدالملك الشويطر
  • عمرو رمضان عقل الحفناوي
  • حسام الدين أحمد على
  • أسامه أحمد محمد محمد
  • حاتم محمد المفتي
  • عبد الله دردير
  • أدهم البغدادي
  • أحمد صبري
  • عبدالوهاب محمد محمد
  • أحمد محمد عوض