Upload folder using huggingface_hub
Browse files- README.md +14 -0
- focus_area_model.py +16 -0
README.md
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: Medquad Classify
|
| 3 |
+
emoji: 🏆
|
| 4 |
+
colorFrom: gray
|
| 5 |
+
colorTo: green
|
| 6 |
+
sdk: gradio
|
| 7 |
+
sdk_version: 5.27.0
|
| 8 |
+
app_file: app.py
|
| 9 |
+
pinned: false
|
| 10 |
+
license: mit
|
| 11 |
+
short_description: Classifying medical questions into 2000+ focus areas
|
| 12 |
+
---
|
| 13 |
+
|
| 14 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
focus_area_model.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import torch, torch.nn as nn
|
| 3 |
+
from transformers import AutoModel
|
| 4 |
+
|
| 5 |
+
class LabelEmbCls(nn.Module):
|
| 6 |
+
def __init__(self, base, lbl_emb):
|
| 7 |
+
super().__init__()
|
| 8 |
+
self.bert = base
|
| 9 |
+
self.lbl_E = nn.Parameter(lbl_emb, requires_grad=False)
|
| 10 |
+
self.tau = nn.Parameter(torch.tensor(1.))
|
| 11 |
+
def forward(self, input_ids, attention_mask, token_type_ids=None):
|
| 12 |
+
cls = self.bert(input_ids=input_ids,
|
| 13 |
+
attention_mask=attention_mask,
|
| 14 |
+
token_type_ids=token_type_ids
|
| 15 |
+
).last_hidden_state[:,0]
|
| 16 |
+
return torch.matmul(cls, self.lbl_E.T) / self.tau
|