asahi417 commited on
Commit
6c8a3a5
1 Parent(s): e57caae

Update readme.py

Browse files
Files changed (1) hide show
  1. readme.py +126 -0
readme.py CHANGED
@@ -0,0 +1,126 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from typing import Dict
3
+
4
+
5
+ def get_readme(model_name: str,
6
+ metric: Dict,
7
+ metric_span: Dict,
8
+ config: Dict):
9
+ language_model = config['model']
10
+ dataset = None
11
+ dataset_alias = "custom"
12
+ if config["dataset"] is not None:
13
+ dataset = sorted([i for i in config["dataset"]])
14
+ dataset_alias = ','.join(dataset)
15
+ config_text = "\n".join([f" - {k}: {v}" for k, v in config.items()])
16
+ ci_micro = '\n'.join([f' - {k}%: {v}' for k, v in metric["micro/f1_ci"].items()])
17
+ ci_macro = '\n'.join([f' - {k}%: {v}' for k, v in metric["micro/f1_ci"].items()])
18
+ per_entity_metric = '\n'.join([f'- {k}: {v["f1"]}' for k, v in metric['per_entity_metric'].items()])
19
+ if dataset is None:
20
+ dataset_link = 'custom'
21
+ else:
22
+ dataset = [dataset] if type(dataset) is str else dataset
23
+ dataset_link = ','.join([f"[{d}](https://huggingface.co/datasets/{d})" for d in dataset])
24
+ return f"""---
25
+ datasets:
26
+ - {dataset_alias}
27
+ metrics:
28
+ - f1
29
+ - precision
30
+ - recall
31
+ model-index:
32
+ - name: {model_name}
33
+ results:
34
+ - task:
35
+ name: Token Classification
36
+ type: token-classification
37
+ dataset:
38
+ name: {dataset_alias}
39
+ type: {dataset_alias}
40
+ args: {dataset_alias}
41
+ metrics:
42
+ - name: F1
43
+ type: f1
44
+ value: {metric['micro/f1']}
45
+ - name: Precision
46
+ type: precision
47
+ value: {metric['micro/precision']}
48
+ - name: Recall
49
+ type: recall
50
+ value: {metric['micro/recall']}
51
+ - name: F1 (macro)
52
+ type: f1_macro
53
+ value: {metric['macro/f1']}
54
+ - name: Precision (macro)
55
+ type: precision_macro
56
+ value: {metric['macro/precision']}
57
+ - name: Recall (macro)
58
+ type: recall_macro
59
+ value: {metric['macro/recall']}
60
+ - name: F1 (entity span)
61
+ type: f1_entity_span
62
+ value: {metric_span['micro/f1']}
63
+ - name: Precision (entity span)
64
+ type: precision_entity_span
65
+ value: {metric_span['micro/precision']}
66
+ - name: Recall (entity span)
67
+ type: recall_entity_span
68
+ value: {metric_span['micro/recall']}
69
+
70
+ pipeline_tag: token-classification
71
+ widget:
72
+ - text: "Jacob Collier is a Grammy awarded artist from England."
73
+ example_title: "NER Example 1"
74
+ ---
75
+ # {model_name}
76
+
77
+ This model is a fine-tuned version of [{language_model}](https://huggingface.co/{language_model}) on the
78
+ {dataset_link} dataset.
79
+ Model fine-tuning is done via [T-NER](https://github.com/asahi417/tner)'s hyper-parameter search (see the repository
80
+ for more detail). It achieves the following results on the test set:
81
+ - F1 (micro): {metric['micro/f1']}
82
+ - Precision (micro): {metric['micro/precision']}
83
+ - Recall (micro): {metric['micro/recall']}
84
+ - F1 (macro): {metric['macro/f1']}
85
+ - Precision (macro): {metric['macro/precision']}
86
+ - Recall (macro): {metric['macro/recall']}
87
+
88
+ The per-entity breakdown of the F1 score on the test set are below:
89
+ {per_entity_metric}
90
+
91
+ For F1 scores, the confidence interval is obtained by bootstrap as below:
92
+ - F1 (micro):
93
+ {ci_micro}
94
+ - F1 (macro):
95
+ {ci_macro}
96
+
97
+ Full evaluation can be found at [metric file of NER](https://huggingface.co/{model_name}/raw/main/eval/metric.json)
98
+ and [metric file of entity span](https://huggingface.co/{model_name}/raw/main/eval/metric_span.json).
99
+
100
+ ### Usage
101
+ This model can be used through the [tner library](https://github.com/asahi417/tner). Install the library via pip
102
+ ```shell
103
+ pip install tner
104
+ ```
105
+ and activate model as below.
106
+ ```python
107
+ from tner import TransformersNER
108
+ model = TransformersNER("{model_name}")
109
+ model.predict(["Jacob Collier is a Grammy awarded English artist from London"])
110
+ ```
111
+ It can be used via transformers library but it is not recommended as CRF layer is not supported at the moment.
112
+
113
+ ### Training hyperparameters
114
+
115
+ The following hyperparameters were used during training:
116
+ {config_text}
117
+
118
+ The full configuration can be found at [fine-tuning parameter file](https://huggingface.co/{model_name}/raw/main/trainer_config.json).
119
+
120
+ ### Reference
121
+ If you use any resource from T-NER, please consider to cite our [paper](https://aclanthology.org/2021.eacl-demos.7/).
122
+
123
+ ```
124
+ {bib}
125
+ ```
126
+ """