transformers-crf 0.3.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- transformers_crf-0.3.3/MANIFEST.in +4 -0
- transformers_crf-0.3.3/PKG-INFO +111 -0
- transformers_crf-0.3.3/README.md +82 -0
- transformers_crf-0.3.3/examples/run_ner_hf.py +1445 -0
- transformers_crf-0.3.3/requirements.txt +9 -0
- transformers_crf-0.3.3/setup.cfg +4 -0
- transformers_crf-0.3.3/setup.py +138 -0
- transformers_crf-0.3.3/tests/test_constrained_decoding.py +161 -0
- transformers_crf-0.3.3/tests/test_model_runtime.py +33 -0
- transformers_crf-0.3.3/tests/test_packaging.py +47 -0
- transformers_crf-0.3.3/tests/test_run_ner_conll_paths.py +76 -0
- transformers_crf-0.3.3/tests/test_run_ner_window_budget.py +136 -0
- transformers_crf-0.3.3/transformers_crf/__init__.py +20 -0
- transformers_crf-0.3.3/transformers_crf/bert_crf.py +856 -0
- transformers_crf-0.3.3/transformers_crf/bert_crf_modern.py +131 -0
- transformers_crf-0.3.3/transformers_crf/bert_crf_no_modern.py +937 -0
- transformers_crf-0.3.3/transformers_crf/constrained_decoding.py +387 -0
- transformers_crf-0.3.3/transformers_crf/crf.py +1008 -0
- transformers_crf-0.3.3/transformers_crf/data_collator.py +176 -0
- transformers_crf-0.3.3/transformers_crf/export_onnx.py +346 -0
- transformers_crf-0.3.3/transformers_crf/ort_model.py +296 -0
- transformers_crf-0.3.3/transformers_crf/tokenizer.py +177 -0
- transformers_crf-0.3.3/transformers_crf/trainer.py +289 -0
- transformers_crf-0.3.3/transformers_crf/transformer_embedder.py +193 -0
- transformers_crf-0.3.3/transformers_crf/util.py +285 -0
- transformers_crf-0.3.3/transformers_crf/version.py +1 -0
- transformers_crf-0.3.3/transformers_crf.egg-info/PKG-INFO +111 -0
- transformers_crf-0.3.3/transformers_crf.egg-info/SOURCES.txt +30 -0
- transformers_crf-0.3.3/transformers_crf.egg-info/dependency_links.txt +1 -0
- transformers_crf-0.3.3/transformers_crf.egg-info/requires.txt +9 -0
- transformers_crf-0.3.3/transformers_crf.egg-info/top_level.txt +1 -0
- transformers_crf-0.3.3/transformers_crf.egg-info/zip-safe +1 -0
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: transformers_crf
|
|
3
|
+
Version: 0.3.3
|
|
4
|
+
Summary: Transformers CRF: CRF Token Classification for Transformers
|
|
5
|
+
Home-page: https://bitbucket.org/avisourgente/transformers_crf
|
|
6
|
+
Author: Eduardo Garcia - Datalawyer
|
|
7
|
+
License: Apache License 2.0
|
|
8
|
+
Platform: any
|
|
9
|
+
Requires-Python: >=3.9.0
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
Requires-Dist: transformers==4.56.1
|
|
12
|
+
Requires-Dist: datasets>=1.8.0
|
|
13
|
+
Requires-Dist: onnx
|
|
14
|
+
Requires-Dist: onnxruntime
|
|
15
|
+
Requires-Dist: optimum
|
|
16
|
+
Requires-Dist: seqeval
|
|
17
|
+
Requires-Dist: evaluate
|
|
18
|
+
Requires-Dist: accelerate
|
|
19
|
+
Requires-Dist: wandb
|
|
20
|
+
Dynamic: author
|
|
21
|
+
Dynamic: description
|
|
22
|
+
Dynamic: description-content-type
|
|
23
|
+
Dynamic: home-page
|
|
24
|
+
Dynamic: license
|
|
25
|
+
Dynamic: platform
|
|
26
|
+
Dynamic: requires-dist
|
|
27
|
+
Dynamic: requires-python
|
|
28
|
+
Dynamic: summary
|
|
29
|
+
|
|
30
|
+
# Tranformers-CRF
|
|
31
|
+
|
|
32
|
+
For training BERT-CRF models with the huggingface Transformers libary
|
|
33
|
+
|
|
34
|
+
### Instalation
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
git clone https://bitbucket.org/avisourgente/transformers_crf.git
|
|
38
|
+
cd transformers_crf
|
|
39
|
+
pip install -e .
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Train example
|
|
43
|
+
|
|
44
|
+
Train script is in examples/run_ner.py
|
|
45
|
+
It follows the api of https://github.com/huggingface/transformers/blob/main/examples/pytorch/token-classification/run_ner.py
|
|
46
|
+
New args:
|
|
47
|
+
```
|
|
48
|
+
--learning_rate_ner LEARNING_RATE_NER
|
|
49
|
+
Custom initial learning rate for the CRF and Linear layers on AdamW. (default: None)
|
|
50
|
+
--weight_decay_ner WEIGHT_DECAY_NER
|
|
51
|
+
Custom weight decay for the CRF and Linear layers on AdamW. (default: None)
|
|
52
|
+
--use_crf
|
|
53
|
+
Will enable to use CRF layer. (default: False)
|
|
54
|
+
--no_constrain_crf
|
|
55
|
+
Set to not to constrain crf outputs to labeling scheme (default: False)
|
|
56
|
+
--break_docs_to_max_length [BREAK_DOCS_TO_MAX_LENGTH]
|
|
57
|
+
Whether to chunck docs into sentences with the max seq length of tokenizer. (default: False)
|
|
58
|
+
--convert_to_iobes [CONVERT_TO_IOBES]
|
|
59
|
+
Convert a IOB2 input to IOBES. (default: False)
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Example:
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
python run_ner.py \
|
|
66
|
+
--model_name_or_path neuralmind/bert-base-portuguese-cased \
|
|
67
|
+
--dataset_name eduagarcia/portuguese_benchmark \
|
|
68
|
+
--dataset_config_name harem-default \
|
|
69
|
+
--per_device_train_batch_size 16 \
|
|
70
|
+
--per_device_eval_batch_size 16 \
|
|
71
|
+
--num_train_epochs 15 \
|
|
72
|
+
--learning_rate 5e-5 \
|
|
73
|
+
--do_train \
|
|
74
|
+
--do_eval \
|
|
75
|
+
--do_predict \
|
|
76
|
+
--evaluation_strategy steps \
|
|
77
|
+
--eval_steps 500 \
|
|
78
|
+
--output_dir /workspace/models/test-transformers-crf \
|
|
79
|
+
--max_seq_length 128 \
|
|
80
|
+
--break_docs_to_max_length \
|
|
81
|
+
--overwrite_output_dir \
|
|
82
|
+
--learning_rate_ner 5e-3 \
|
|
83
|
+
--convert_to_iobes \
|
|
84
|
+
--use_crf
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
### Usage example
|
|
89
|
+
|
|
90
|
+
```python
|
|
91
|
+
import torch
|
|
92
|
+
from transformers_crf import CRFTokenizer, AutoModelForEmbedderCRFTokenClassification
|
|
93
|
+
|
|
94
|
+
model_path = "./model"
|
|
95
|
+
|
|
96
|
+
device = torch.device('cpu')
|
|
97
|
+
tokenizer = CRFTokenizer.from_pretrained(model_path)
|
|
98
|
+
model = AutoModelForEmbedderCRFTokenClassification.from_pretrained(model_path).to(device)
|
|
99
|
+
|
|
100
|
+
tokens = [["Esse", "é", "um", "exemplo"], ["Esse", "é", "um", "segundo", "exemplo"]]
|
|
101
|
+
batch = tokenizer(tokens, max_length=512).to(device)
|
|
102
|
+
output = model(**batch, reorder=True)
|
|
103
|
+
predicts_id = output.predicts.detach().cpu().numpy()
|
|
104
|
+
preds = [[model.config.id2label[p] for p in pred_seq][:len(token_seq)] for (pred_seq, token_seq) in zip(predicts_id, tokens)]
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Pip upload package ###
|
|
108
|
+
|
|
109
|
+
python setup.py bdist_wheel
|
|
110
|
+
|
|
111
|
+
python -m twine upload dist/*
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# Tranformers-CRF
|
|
2
|
+
|
|
3
|
+
For training BERT-CRF models with the huggingface Transformers libary
|
|
4
|
+
|
|
5
|
+
### Instalation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
git clone https://bitbucket.org/avisourgente/transformers_crf.git
|
|
9
|
+
cd transformers_crf
|
|
10
|
+
pip install -e .
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
### Train example
|
|
14
|
+
|
|
15
|
+
Train script is in examples/run_ner.py
|
|
16
|
+
It follows the api of https://github.com/huggingface/transformers/blob/main/examples/pytorch/token-classification/run_ner.py
|
|
17
|
+
New args:
|
|
18
|
+
```
|
|
19
|
+
--learning_rate_ner LEARNING_RATE_NER
|
|
20
|
+
Custom initial learning rate for the CRF and Linear layers on AdamW. (default: None)
|
|
21
|
+
--weight_decay_ner WEIGHT_DECAY_NER
|
|
22
|
+
Custom weight decay for the CRF and Linear layers on AdamW. (default: None)
|
|
23
|
+
--use_crf
|
|
24
|
+
Will enable to use CRF layer. (default: False)
|
|
25
|
+
--no_constrain_crf
|
|
26
|
+
Set to not to constrain crf outputs to labeling scheme (default: False)
|
|
27
|
+
--break_docs_to_max_length [BREAK_DOCS_TO_MAX_LENGTH]
|
|
28
|
+
Whether to chunck docs into sentences with the max seq length of tokenizer. (default: False)
|
|
29
|
+
--convert_to_iobes [CONVERT_TO_IOBES]
|
|
30
|
+
Convert a IOB2 input to IOBES. (default: False)
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Example:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
python run_ner.py \
|
|
37
|
+
--model_name_or_path neuralmind/bert-base-portuguese-cased \
|
|
38
|
+
--dataset_name eduagarcia/portuguese_benchmark \
|
|
39
|
+
--dataset_config_name harem-default \
|
|
40
|
+
--per_device_train_batch_size 16 \
|
|
41
|
+
--per_device_eval_batch_size 16 \
|
|
42
|
+
--num_train_epochs 15 \
|
|
43
|
+
--learning_rate 5e-5 \
|
|
44
|
+
--do_train \
|
|
45
|
+
--do_eval \
|
|
46
|
+
--do_predict \
|
|
47
|
+
--evaluation_strategy steps \
|
|
48
|
+
--eval_steps 500 \
|
|
49
|
+
--output_dir /workspace/models/test-transformers-crf \
|
|
50
|
+
--max_seq_length 128 \
|
|
51
|
+
--break_docs_to_max_length \
|
|
52
|
+
--overwrite_output_dir \
|
|
53
|
+
--learning_rate_ner 5e-3 \
|
|
54
|
+
--convert_to_iobes \
|
|
55
|
+
--use_crf
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
### Usage example
|
|
60
|
+
|
|
61
|
+
```python
|
|
62
|
+
import torch
|
|
63
|
+
from transformers_crf import CRFTokenizer, AutoModelForEmbedderCRFTokenClassification
|
|
64
|
+
|
|
65
|
+
model_path = "./model"
|
|
66
|
+
|
|
67
|
+
device = torch.device('cpu')
|
|
68
|
+
tokenizer = CRFTokenizer.from_pretrained(model_path)
|
|
69
|
+
model = AutoModelForEmbedderCRFTokenClassification.from_pretrained(model_path).to(device)
|
|
70
|
+
|
|
71
|
+
tokens = [["Esse", "é", "um", "exemplo"], ["Esse", "é", "um", "segundo", "exemplo"]]
|
|
72
|
+
batch = tokenizer(tokens, max_length=512).to(device)
|
|
73
|
+
output = model(**batch, reorder=True)
|
|
74
|
+
predicts_id = output.predicts.detach().cpu().numpy()
|
|
75
|
+
preds = [[model.config.id2label[p] for p in pred_seq][:len(token_seq)] for (pred_seq, token_seq) in zip(predicts_id, tokens)]
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Pip upload package ###
|
|
79
|
+
|
|
80
|
+
python setup.py bdist_wheel
|
|
81
|
+
|
|
82
|
+
python -m twine upload dist/*
|