SinaLab / ArabicNER

Arabic nested named entity recognition
MIT License
32 stars 17 forks source link

How to load the model uploaded to HF using transformers? #9

Open AMR-KELEG opened 5 months ago

AMR-KELEG commented 5 months ago

Hi,

Thanks for your efforts developing the model. I am trying to load the NER model, but I am getting strange results as an output. Do you have any thoughts for why that's the case?

NER_model_name = "SinaLab/ArabicWojood-FlatNER" tokenizer = AutoTokenizer.from_pretrained(NER_model_name) model = AutoModelForTokenClassification.from_pretrained(NER_model_name)

ner_pipeline = pipeline("ner", model=model, tokenizer=tokenizer)

def get_ne(text): output = ner_pipeline(text) return {"text": text, "entities": output}

get_ne("أنا اسمي محمد")


* Output:

{'text': 'أنا اسمي محمد', 'entities': [{'entity': 'B-FAC', 'score': 0.111766666, 'index': 1, 'word': 'انا', 'start': 0, 'end': 3}, {'entity': 'B-FAC', 'score': 0.08029653, 'index': 2, 'word': 'اسمي', 'start': 4, 'end': 8}, {'entity': 'B-FAC', 'score': 0.072174296, 'index': 3, 'word': 'محمد', 'start': 9, 'end': 13}]}