edloginovad commited on
Commit
075a2a5
·
verified ·
1 Parent(s): 98bd4df

Update model card with detailed information

Browse files
Files changed (1) hide show
  1. README.md +42 -1
README.md CHANGED
@@ -37,7 +37,7 @@ It was fine-tuned from the [DedalusHealthCare/tinybert-mlm-de](https://huggingfa
37
 
38
  **Entities**: DISORDER_FINDING
39
 
40
- **Model Format**: PYTORCH
41
 
42
  **Please use `max` as aggregation strategy in the NER pipeline (see example below)**.
43
 
@@ -121,6 +121,47 @@ predicted_token_class_ids = predictions.argmax(-1)
121
  labels = [model.config.id2label[id.item()] for id in predicted_token_class_ids[0]]
122
  ```
123
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
124
  ## Model Architecture
125
 
126
  This model is based on the TinyBERT architecture with a token classification head for Named Entity Recognition.
 
37
 
38
  **Entities**: DISORDER_FINDING
39
 
40
+ **Model Format**: PYTORCH+ONNX
41
 
42
  **Please use `max` as aggregation strategy in the NER pipeline (see example below)**.
43
 
 
121
  labels = [model.config.id2label[id.item()] for id in predicted_token_class_ids[0]]
122
  ```
123
 
124
+ ### Using ONNX Runtime (Optimized Inference)
125
+
126
+ ```python
127
+ from optimum.onnxruntime import ORTModelForTokenClassification
128
+ from transformers import AutoTokenizer, pipeline
129
+ import torch
130
+
131
+ # Load ONNX model for faster inference
132
+ model_name = "DedalusHealthCare/tinybert-demo-de"
133
+ onnx_model = ORTModelForTokenClassification.from_pretrained(model_name)
134
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
135
+
136
+ # Create pipeline with ONNX model (recommended)
137
+ ner_pipeline = pipeline(
138
+ "ner",
139
+ model=onnx_model,
140
+ tokenizer=tokenizer,
141
+ aggregation_strategy="max"
142
+ )
143
+
144
+ # Example text
145
+ text = "Der Patient hat Diabetes und Bluthochdruck."
146
+ entities = ner_pipeline(text)
147
+ print(entities)
148
+
149
+ # Direct model usage
150
+ inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True)
151
+ with torch.no_grad():
152
+ outputs = onnx_model(**inputs)
153
+ predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)
154
+
155
+ predicted_token_class_ids = predictions.argmax(-1)
156
+ token_labels = [onnx_model.config.id2label[id.item()] for id in predicted_token_class_ids[0]]
157
+ ```
158
+
159
+ ### Performance Comparison
160
+
161
+ - **PyTorch**: Standard format, suitable for training and research
162
+ - **ONNX**: Optimized for inference, typically 2-4x faster than PyTorch
163
+ - **Recommendation**: Use ONNX for production inference, PyTorch for research
164
+
165
  ## Model Architecture
166
 
167
  This model is based on the TinyBERT architecture with a token classification head for Named Entity Recognition.