Initialize
Browse files- README.md +90 -0
- config.json +70 -0
- pytorch_model.bin +3 -0
- special_tokens_map.json +7 -0
- tf_model.h5 +3 -0
- tokenizer.json +0 -0
- tokenizer_config.json +13 -0
- vocab.txt +0 -0
README.md
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language: fa
|
| 3 |
+
---
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
# BertNER
|
| 7 |
+
|
| 8 |
+
This model fine-tuned for the Named Entity Recognition (NER) task on a mixed NER dataset collected from [ARMAN](https://github.com/HaniehP/PersianNER), [PEYMA](http://nsurl.org/2019-2/tasks/task-7-named-entity-recognition-ner-for-farsi/), and [WikiANN](https://elisa-ie.github.io/wikiann/) that covered ten types of entities:
|
| 9 |
+
|
| 10 |
+
- Date (DAT)
|
| 11 |
+
- Event (EVE)
|
| 12 |
+
- Facility (FAC)
|
| 13 |
+
- Location (LOC)
|
| 14 |
+
- Money (MON)
|
| 15 |
+
- Organization (ORG)
|
| 16 |
+
- Percent (PCT)
|
| 17 |
+
- Person (PER)
|
| 18 |
+
- Product (PRO)
|
| 19 |
+
- Time (TIM)
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
## Dataset Information
|
| 23 |
+
|
| 24 |
+
| | Records | B-DAT | B-EVE | B-FAC | B-LOC | B-MON | B-ORG | B-PCT | B-PER | B-PRO | B-TIM | I-DAT | I-EVE | I-FAC | I-LOC | I-MON | I-ORG | I-PCT | I-PER | I-PRO | I-TIM |
|
| 25 |
+
|:------|----------:|--------:|--------:|--------:|--------:|--------:|--------:|--------:|--------:|--------:|--------:|--------:|--------:|--------:|--------:|--------:|--------:|--------:|--------:|--------:|--------:|
|
| 26 |
+
| Train | 29133 | 1423 | 1487 | 1400 | 13919 | 417 | 15926 | 355 | 12347 | 1855 | 150 | 1947 | 5018 | 2421 | 4118 | 1059 | 19579 | 573 | 7699 | 1914 | 332 |
|
| 27 |
+
| Valid | 5142 | 267 | 253 | 250 | 2362 | 100 | 2651 | 64 | 2173 | 317 | 19 | 373 | 799 | 387 | 717 | 270 | 3260 | 101 | 1382 | 303 | 35 |
|
| 28 |
+
| Test | 6049 | 407 | 256 | 248 | 2886 | 98 | 3216 | 94 | 2646 | 318 | 43 | 568 | 888 | 408 | 858 | 263 | 3967 | 141 | 1707 | 296 | 78 |
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
## Evaluation
|
| 32 |
+
|
| 33 |
+
The following tables summarize the scores obtained by model overall and per each class.
|
| 34 |
+
|
| 35 |
+
**Overall**
|
| 36 |
+
|
| 37 |
+
| Model | accuracy | precision | recall | f1 |
|
| 38 |
+
|:----------:|:--------:|:---------:|:--------:|:--------:|
|
| 39 |
+
| Bert | 0.995086 | 0.953454 | 0.961113 | 0.957268 |
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
**Per entities**
|
| 43 |
+
|
| 44 |
+
| | number | precision | recall | f1 |
|
| 45 |
+
|:---: |:------: |:---------: |:--------: |:--------: |
|
| 46 |
+
| DAT | 407 | 0.860636 | 0.864865 | 0.862745 |
|
| 47 |
+
| EVE | 256 | 0.969582 | 0.996094 | 0.982659 |
|
| 48 |
+
| FAC | 248 | 0.976190 | 0.991935 | 0.984000 |
|
| 49 |
+
| LOC | 2884 | 0.970232 | 0.971914 | 0.971072 |
|
| 50 |
+
| MON | 98 | 0.905263 | 0.877551 | 0.891192 |
|
| 51 |
+
| ORG | 3216 | 0.939125 | 0.954602 | 0.946800 |
|
| 52 |
+
| PCT | 94 | 1.000000 | 0.968085 | 0.983784 |
|
| 53 |
+
| PER | 2645 | 0.965244 | 0.965974 | 0.965608 |
|
| 54 |
+
| PRO | 318 | 0.981481 | 1.000000 | 0.990654 |
|
| 55 |
+
| TIM | 43 | 0.692308 | 0.837209 | 0.757895 |
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
## How To Use
|
| 59 |
+
You use this model with Transformers pipeline for NER.
|
| 60 |
+
|
| 61 |
+
### Installing requirements
|
| 62 |
+
|
| 63 |
+
```bash
|
| 64 |
+
pip install transformers
|
| 65 |
+
```
|
| 66 |
+
|
| 67 |
+
### How to predict using pipeline
|
| 68 |
+
|
| 69 |
+
```python
|
| 70 |
+
from transformers import AutoTokenizer
|
| 71 |
+
from transformers import AutoModelForTokenClassification # for pytorch
|
| 72 |
+
from transformers import TFAutoModelForTokenClassification # for tensorflow
|
| 73 |
+
from transformers import pipeline
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
model_name_or_path = "HooshvareLab/bert-fa-zwnj-base-ner"
|
| 77 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name_or_path)
|
| 78 |
+
model = AutoModelForTokenClassification.from_pretrained(model_name_or_path) # Pytorch
|
| 79 |
+
# model = TFAutoModelForTokenClassification.from_pretrained(model_name_or_path) # Tensorflow
|
| 80 |
+
|
| 81 |
+
nlp = pipeline("ner", model=model, tokenizer=tokenizer)
|
| 82 |
+
example = "در سال ۲۰۱۳ درگذشت و آندرتیکر و کین برای او مراسم یادبود گرفتند."
|
| 83 |
+
|
| 84 |
+
ner_results = nlp(example)
|
| 85 |
+
print(ner_results)
|
| 86 |
+
```
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
## Questions?
|
| 90 |
+
Post a Github issue on the [ParsNER Issues](https://github.com/hooshvare/parsner/issues) repo.
|
config.json
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architectures": [
|
| 3 |
+
"BertForTokenClassification"
|
| 4 |
+
],
|
| 5 |
+
"attention_probs_dropout_prob": 0.1,
|
| 6 |
+
"finetuning_task": "ner",
|
| 7 |
+
"gradient_checkpointing": false,
|
| 8 |
+
"hidden_act": "gelu",
|
| 9 |
+
"hidden_dropout_prob": 0.1,
|
| 10 |
+
"hidden_size": 768,
|
| 11 |
+
"id2label": {
|
| 12 |
+
"0": "O",
|
| 13 |
+
"1": "B-DAT",
|
| 14 |
+
"2": "B-EVE",
|
| 15 |
+
"3": "B-FAC",
|
| 16 |
+
"4": "B-LOC",
|
| 17 |
+
"5": "B-MON",
|
| 18 |
+
"6": "B-ORG",
|
| 19 |
+
"7": "B-PCT",
|
| 20 |
+
"8": "B-PER",
|
| 21 |
+
"9": "B-PRO",
|
| 22 |
+
"10": "B-TIM",
|
| 23 |
+
"11": "I-DAT",
|
| 24 |
+
"12": "I-EVE",
|
| 25 |
+
"13": "I-FAC",
|
| 26 |
+
"14": "I-LOC",
|
| 27 |
+
"15": "I-MON",
|
| 28 |
+
"16": "I-ORG",
|
| 29 |
+
"17": "I-PCT",
|
| 30 |
+
"18": "I-PER",
|
| 31 |
+
"19": "I-PRO",
|
| 32 |
+
"20": "I-TIM"
|
| 33 |
+
},
|
| 34 |
+
"initializer_range": 0.02,
|
| 35 |
+
"intermediate_size": 3072,
|
| 36 |
+
"label2id": {
|
| 37 |
+
"B-DAT": 1,
|
| 38 |
+
"B-EVE": 2,
|
| 39 |
+
"B-FAC": 3,
|
| 40 |
+
"B-LOC": 4,
|
| 41 |
+
"B-MON": 5,
|
| 42 |
+
"B-ORG": 6,
|
| 43 |
+
"B-PCT": 7,
|
| 44 |
+
"B-PER": 8,
|
| 45 |
+
"B-PRO": 9,
|
| 46 |
+
"B-TIM": 10,
|
| 47 |
+
"I-DAT": 11,
|
| 48 |
+
"I-EVE": 12,
|
| 49 |
+
"I-FAC": 13,
|
| 50 |
+
"I-LOC": 14,
|
| 51 |
+
"I-MON": 15,
|
| 52 |
+
"I-ORG": 16,
|
| 53 |
+
"I-PCT": 17,
|
| 54 |
+
"I-PER": 18,
|
| 55 |
+
"I-PRO": 19,
|
| 56 |
+
"I-TIM": 20,
|
| 57 |
+
"O": 0
|
| 58 |
+
},
|
| 59 |
+
"layer_norm_eps": 1e-12,
|
| 60 |
+
"max_position_embeddings": 512,
|
| 61 |
+
"model_type": "bert",
|
| 62 |
+
"num_attention_heads": 12,
|
| 63 |
+
"num_hidden_layers": 12,
|
| 64 |
+
"pad_token_id": 0,
|
| 65 |
+
"position_embedding_type": "absolute",
|
| 66 |
+
"transformers_version": "4.5.0.dev0",
|
| 67 |
+
"type_vocab_size": 2,
|
| 68 |
+
"use_cache": true,
|
| 69 |
+
"vocab_size": 42000
|
| 70 |
+
}
|
pytorch_model.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:0060567e2193d40844f08ffa1b5e73bdfa3e74257aaccc616ffcb1e5442d323c
|
| 3 |
+
size 470980151
|
special_tokens_map.json
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"unk_token": "[UNK]",
|
| 3 |
+
"sep_token": "[SEP]",
|
| 4 |
+
"pad_token": "[PAD]",
|
| 5 |
+
"cls_token": "[CLS]",
|
| 6 |
+
"mask_token": "[MASK]"
|
| 7 |
+
}
|
tf_model.h5
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d9e8f8d228fef2eec9702a355c35daa90c0d7d2b8eef00439c92bbef29d2e13e
|
| 3 |
+
size 471159904
|
tokenizer.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
tokenizer_config.json
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"do_lower_case": false,
|
| 3 |
+
"unk_token": "[UNK]",
|
| 4 |
+
"sep_token": "[SEP]",
|
| 5 |
+
"pad_token": "[PAD]",
|
| 6 |
+
"cls_token": "[CLS]",
|
| 7 |
+
"mask_token": "[MASK]",
|
| 8 |
+
"tokenize_chinese_chars": true,
|
| 9 |
+
"strip_accents": false,
|
| 10 |
+
"model_max_length": 512,
|
| 11 |
+
"special_tokens_map_file": null,
|
| 12 |
+
"name_or_path": "HooshvareLab/bert-fa-zwnj-base"
|
| 13 |
+
}
|
vocab.txt
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|