File size: 2,490 Bytes
507916b
 
c6e079b
743820b
 
 
 
 
 
 
ed38a69
c6e079b
743820b
507916b
c6e079b
743820b
 
 
ed38a69
743820b
ed38a69
743820b
ed38a69
62b1636
 
 
ed38a69
743820b
ed38a69
743820b
ed38a69
62b1636
 
 
743820b
62b1636
 
ed38a69
743820b
ed38a69
62b1636
 
 
 
ed38a69
 
 
 
 
 
 
743820b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
---
license: mit
datasets:
  - kargaranamir/HengamCorpus
tags:
  - span-marker
  - token-classification
  - ner
  - named-entity-recognition
pipeline_tag: token-classification
inference: false
language:
  - fa
---


# Hengam: An Adversarially Trained Transformer for Persian Temporal Tagging

# Usage

You can use this model directly downloading the utils and requirements files and installing requirements:

```python
>>> ! wget https://huggingface.co/spaces/kargaranamir/Hengam/raw/main/utils.py
>>> ! wget https://huggingface.co/spaces/kargaranamir/Hengam/raw/main/requirements.txt
>>> ! pip install -r requirements.txt
```

and downloading the models HengamTransA.pth or HengamTransW.pth and building ner pipline:

```python
>>> import torch
>>> from huggingface_hub import hf_hub_download
>>> from utils import *

>>> # HengamTransW = hf_hub_download(repo_id="kargaranamir/Hengam", filename="HengamTransW.pth")
>>> HengamTransA = hf_hub_download(repo_id="kargaranamir/Hengam", filename="HengamTransA.pth")
```

```python
>>> # ner = NER(model_path=HengamTransW, tags=['B-TIM', 'I-TIM', 'B-DAT', 'I-DAT', 'O'])
>>> ner = NER(model_path=HengamTransA, tags=['B-TIM', 'I-TIM', 'B-DAT', 'I-DAT', 'O'])
>>> ner('.سلام من و دوستم ساعت ۸ صبح روز سه شنبه رفتیم دوشنبه بازار ')

[{'Text': 'ساعت', 'Tag': 'B-TIM', 'Start': 17, 'End': 21},
 {'Text': '۸', 'Tag': 'I-TIM', 'Start': 22, 'End': 23},
 {'Text': 'صبح', 'Tag': 'I-TIM', 'Start': 24, 'End': 27},
 {'Text': 'روز', 'Tag': 'I-TIM', 'Start': 28, 'End': 31},
 {'Text': 'سه', 'Tag': 'B-DAT', 'Start': 32, 'End': 34},
 {'Text': 'شنبه', 'Tag': 'I-DAT', 'Start': 35, 'End': 39}]
```


## Citation

If you use any part of this repository in your research, please cite it using the following BibTex entry.
```python
@inproceedings{mirzababaei-etal-2022-hengam,
	title        = {Hengam: An Adversarially Trained Transformer for {P}ersian Temporal Tagging},
	author       = {Mirzababaei, Sajad  and Kargaran, Amir Hossein  and Sch{\"u}tze, Hinrich  and Asgari, Ehsaneddin},
	year         = 2022,
	booktitle    = {Proceedings of the 2nd Conference of the Asia-Pacific Chapter of the Association for Computational Linguistics and the 12th International Joint Conference on Natural Language Processing},
	publisher    = {Association for Computational Linguistics},
	address      = {Online only},
	pages        = {1013--1024},
	url          = {https://aclanthology.org/2022.aacl-main.74}
}
```