Spaces:
Sleeping
Sleeping
Download src/model.py from DucLai/Vietnamese_NER: direct link, hf CLI and curl.
- Browser
- Download file 538 Bytes
-
https://huggingface.co/spaces/DucLai/Vietnamese_NER/resolve/main/src/model.py
- Command line
-
hf download hf://spaces/DucLai/Vietnamese_NER/src/model.py
-
curl -L -o model.py https://huggingface.co/spaces/DucLai/Vietnamese_NER/resolve/main/src/model.py
538 Bytes
| from torchcrf import CRF | |
| import torch.nn as nn | |
| class CRF_Tagger(nn.Module): | |
| def __init__(self, input_dim, num_tags): | |
| super().__init__() | |
| self.embed2tag = nn.Linear(input_dim, num_tags) | |
| self.crf = CRF(num_tags, batch_first=True) | |
| def forward(self, x, labels, mask): | |
| emissions = self.embed2tag(x) | |
| return -self.crf(emissions, labels, mask=mask, reduction="mean") | |
| def decode(self, x, mask=None): | |
| emissions = self.embed2tag(x) | |
| return self.crf.decode(emissions, mask) |