Feature Extraction
Transformers
Safetensors
English
bert
text-classification
icd10
healthcare
medical
custom_code
text-embeddings-inference
Instructions to use UMCU/ICD10_classifier_base_English with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use UMCU/ICD10_classifier_base_English with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("feature-extraction", model="UMCU/ICD10_classifier_base_English", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForSequenceClassification tokenizer = AutoTokenizer.from_pretrained("UMCU/ICD10_classifier_base_English", trust_remote_code=True) model = AutoModelForSequenceClassification.from_pretrained("UMCU/ICD10_classifier_base_English", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
Update README.md
Browse files
README.md
CHANGED
|
@@ -71,6 +71,35 @@ with torch.no_grad():
|
|
| 71 |
|
| 72 |
```
|
| 73 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
|
| 75 |
|
| 76 |
The macro f1 score is 0.73. We suggest to use it primarily for feature extraction or for use as an *explainable* embedder.
|
|
|
|
| 71 |
|
| 72 |
```
|
| 73 |
|
| 74 |
+
An approach could be
|
| 75 |
+
|
| 76 |
+
```python
|
| 77 |
+
|
| 78 |
+
def get_feature_vector(text):
|
| 79 |
+
inputs = tokenizer(
|
| 80 |
+
text,
|
| 81 |
+
return_tensors="pt",
|
| 82 |
+
truncation=True,
|
| 83 |
+
)
|
| 84 |
+
|
| 85 |
+
with torch.no_grad():
|
| 86 |
+
features = model(**inputs).logits
|
| 87 |
+
|
| 88 |
+
return features.flatten()
|
| 89 |
+
|
| 90 |
+
def reform(features, how='softmax'):
|
| 91 |
+
if how == 'softmax':
|
| 92 |
+
return torch.nn.functional.softmax(features)
|
| 93 |
+
elif how = 'gumbel':
|
| 94 |
+
return torch.nn.functional.gumbel_softmax(features)
|
| 95 |
+
elif how = 'normalize':
|
| 96 |
+
return torch.nn.functional.normalize(features.reshape(1,-1))
|
| 97 |
+
|
| 98 |
+
feature_vector = reform(get_feature_vector(text))
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
```
|
| 102 |
+
|
| 103 |
|
| 104 |
|
| 105 |
The macro f1 score is 0.73. We suggest to use it primarily for feature extraction or for use as an *explainable* embedder.
|