-
-
Save mohammedkhalilia/c807eb1ccb15416b187c32a362001665 to your computer and use it in GitHub Desktop.
eval_flat_arabic_ner.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"nbformat": 4, | |
"nbformat_minor": 0, | |
"metadata": { | |
"colab": { | |
"provenance": [], | |
"include_colab_link": true | |
}, | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3" | |
}, | |
"language_info": { | |
"name": "python" | |
} | |
}, | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "view-in-github", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"<a href=\"https://colab.research.google.com/gist/mohammedkhalilia/c807eb1ccb15416b187c32a362001665/eval_flat_arabic_ner.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"id": "nXd1N4ZUrUfF" | |
}, | |
"outputs": [], | |
"source": [ | |
"# Verify that you have the GPU recognized\n", | |
"!nvidia-smi" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"# Install dependencies\n", | |
"!pip uninstall torch torchtext torchvision torchvision torchdata torchaudio\n", | |
"!pip install torch==1.13.0\n", | |
"!pip install transformers==4.24.0\n", | |
"!pip install torchtext==0.14.0\n", | |
"!pip install torchvision==0.14.0\n", | |
"!pip install torchdata==0.5.1\n", | |
"!pip install seqeval==1.2.2" | |
], | |
"metadata": { | |
"id": "NtdhFLy9rbcn" | |
}, | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"# Remove existing package and clone again from Github\n", | |
"!rm -rf /content/ArabicNER\n", | |
"!git clone https://github.com/SinaLab/ArabicNER.git" | |
], | |
"metadata": { | |
"id": "OiXfr7IrrdlX" | |
}, | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"# Remove existing ArabicNER model and clone the model huggingface repo\n", | |
"!rm -rf /content/ArabicNER-Wojood\n", | |
"!git clone --branch flat https://huggingface.co/SinaLab/ArabicNER-Wojood" | |
], | |
"metadata": { | |
"id": "1KTEw6N6tDF6" | |
}, | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"# Add the ArabicNER package to the system path\n", | |
"import sys\n", | |
"import argparse\n", | |
"sys.path.append('/content/ArabicNER/')" | |
], | |
"metadata": { | |
"id": "1Ze4o3ONrfSu" | |
}, | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"# Import train function\n", | |
"from arabiner.bin.eval import main as eval" | |
], | |
"metadata": { | |
"id": "VpFoSBxXrhPW" | |
}, | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"# Setup the evaluation arguments\n", | |
"args_dict = {\n", | |
" # Output path to save logs, metrics and predictions\n", | |
" \"output_path\": \"/content/output/\",\n", | |
"\n", | |
" # train/test/validation data paths\n", | |
" # The data provided in the ArabicNER repo is a sample data\n", | |
" # data_paths takes a list of data paths in case you need to evaluate multiple datasets\n", | |
" \"data_paths\": [\"/content/ArabicNER/data/test.txt\"],\n", | |
"\n", | |
" # Path to the model, this corresponds to the \"output_path\" you specified\n", | |
" # during training the model\n", | |
" \"model_path\": \"/content/ArabicNER-Wojood/\",\n", | |
"\n", | |
" \"batch_size\": 8\n", | |
"}\n", | |
"\n", | |
"# Convert args dictionary to argparse namespace\n", | |
"args = argparse.Namespace()\n", | |
"args.__dict__ = args_dict" | |
], | |
"metadata": { | |
"id": "46sKrOD0rpwm" | |
}, | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"eval(args)" | |
], | |
"metadata": { | |
"id": "2WETBJhUsMF4" | |
}, | |
"execution_count": null, | |
"outputs": [] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment