Text Classification
Transformers
PyTorch
TensorFlow
TensorBoard
Arabic
English
bert
BERT
Text Classification
relation
text-embeddings-inference
Run this model with HF Jobs
Run ychenNLP/arabic-relation-extraction on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs to fine-tune https://huggingface.co/ychenNLP/arabic-relation-extraction. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/ychenNLP/arabic-relation-extraction on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Instructions to use ychenNLP/arabic-relation-extraction with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use ychenNLP/arabic-relation-extraction with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="ychenNLP/arabic-relation-extraction")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForSequenceClassification tokenizer = AutoTokenizer.from_pretrained("ychenNLP/arabic-relation-extraction") model = AutoModelForSequenceClassification.from_pretrained("ychenNLP/arabic-relation-extraction", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Merge branch 'main' of https://huggingface.co/ychenNLP/arabic-relation-extraction into main
Browse files11 unmodified lines121314151617171819202122232425262324252627282938 unmodified lines68697071717273742 unmodified lines777879808081828384858687888990919293949596979899100101868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312411 unmodified lines# Arabic Relation Extraction Model- [Github repo](https://github.com/edchengg/GigaBERT)- Relation Extraction model based on [GigaBERTv4](https://huggingface.co/lanwuwei/GigaBERT-v4-Arabic-and-English).- Model detail: mark two entities in the sentence with special markers (e.g., ```XXXX <PER> entity1 </PER> XXXXXXX <ORG> entity2 </ORG> XXXXX```). Then we use the BERT [CLS] representation to make a prediction.- ACE2005 Training data: Arabic- [Relation tags](https://www.ldc.upenn.edu/sites/www.ldc.upenn.edu/files/arabic-relations-guidelines-v6.5.pdf) including: Physical, Part-whole, Personal-Social, ORG-Affiliation, Agent-Artifact, Gen-Affiliation
## Hyperparameters- learning_rate=2e-5- num_train_epochs=10- weight_decay=0.01
## ACE2005 Evaluation results (F1)| Language | Arabic | |:----:|:-----------:|| | 89.4 |## ACE2005 Evaluation results (F1) - using gold entities| Language | Arabic | English ||:----:|:-----------:|:-----------:|| | 72.6 | 72.1|
## How to useWorkflow of a relation extraction model:38 unmodified lines re_input.append({"re_input": new_re_input, "arg1": ent_1, "arg2": ent_2, "input": inputs}) return re_input def post_process_re_output(re_output, re_input, ner_output):def post_process_re_output(re_output, text_input, ner_output): final_output = [] for idx, out in enumerate(re_output): if out["label"] != 'O':2 unmodified lines tmp.pop('re_input', None) final_output.append(tmp)
template = {"input": re_input["input"], template = {"input": text_input, "entity": ner_output, "relation": final_output}
return template
>>> input = "Hugging face is a French company in New york.">>> output = ner_pip(input) # inference NER tags
>>> re_input = process_ner_output(output, input) # prepare a pair of entity and predict relation type
>>> re_output = []>>> for idx in range(len(re_input)):>>> tmp_re_output = re_pip(re_input[idx]["re_input"]) # for each pair of entity, predict relation>>> re_output.append(tmp_re_output)
>>> re_ner_output = post_process_re_output(re_output) # post process NER and relation predictions>>> print("Sentence: ",re_ner_output["input"])>>> print("Entity: ", re_ner_output["entity"])>>> print("Relation: ", re_ner_output["relation"])text_input = 'قال وزير العدل التركي بكير بوزداغ إن أنقرة تريد 12 مشتبهاً بهم من فنلندا و 21 من السويد'ner_output = ner_pip(text_input) # inference NER tags
re_input = process_ner_output(ner_output, text_input) # prepare a pair of entity and predict relation type
re_output = []for idx in range(len(re_input)): tmp_re_output = re_pip(re_input[idx]["re_input"]) # for each pair of entity, predict relation re_output.append(tmp_re_output[0])
re_ner_output = post_process_re_output(re_output, text_input, ner_output) # post process NER and relation predictionsprint("Sentence: ",re_ner_output["input"])print('====Entity====')for ent in re_ner_output["entity"]: print('{}--{}'.format(ent["word"], ent["entity_group"]))print('====Relation====')for rel in re_ner_output["relation"]: print('{}--{}:{}'.format(rel['arg1']['word'], rel['arg2']['word'], rel['relation_type']['label']))
Sentence: قال وزير العدل التركي بكير بوزداغ إن أنقرة تريد 12 مشتبهاً بهم من فنلندا و 21 من السويد====Entity====وزير--PERالعدل--ORGالتركي--GPEبكير بوزداغ--PERانقرة--GPEمشتبها بهم--PERفنلندا--GPE21--PERالسويد--GPE====Relation====وزير--العدل:ORG-AFFمشتبها بهم--فنلندا:PHYS21--السويد:PHYS```
### BibTeX entry and citation infoREADME.md+43-23