medcat.utils.meta_cat.models
Module Contents
Classes
Base class for all neural network modules. |
|
Base class for all neural network modules. |
Attributes
- medcat.utils.meta_cat.models.logger
- class medcat.utils.meta_cat.models.LSTM(embeddings, config)
Bases:
torch.nn.Module
Base class for all neural network modules.
Your models should also subclass this class.
Modules can also contain other Modules, allowing to nest them in a tree structure. You can assign the submodules as regular attributes:
import torch.nn as nn import torch.nn.functional as F class Model(nn.Module): def __init__(self): super().__init__() self.conv1 = nn.Conv2d(1, 20, 5) self.conv2 = nn.Conv2d(20, 20, 5) def forward(self, x): x = F.relu(self.conv1(x)) return F.relu(self.conv2(x))
Submodules assigned in this way will be registered, and will have their parameters converted too when you call
to()
, etc.Note
As per the example above, an
__init__()
call to the parent class must be made before assignment on the child.- Variables:
training (bool) – Boolean represents whether this module is in training or evaluation mode.
- Parameters:
embeddings (Optional[torch.Tensor]) –
config (medcat.meta_cat.ConfigMetaCAT) –
- __init__(embeddings, config)
Initializes internal Module state, shared by both nn.Module and ScriptModule.
- Parameters:
embeddings (Optional[torch.Tensor]) –
config (medcat.meta_cat.ConfigMetaCAT) –
- Return type:
None
- forward(input_ids, center_positions, attention_mask=None, ignore_cpos=False)
- Parameters:
input_ids (torch.LongTensor) –
center_positions (torch.Tensor) –
attention_mask (Optional[torch.FloatTensor]) –
ignore_cpos (bool) –
- Return type:
torch.Tensor
- class medcat.utils.meta_cat.models.BertForMetaAnnotation(config)
Bases:
torch.nn.Module
Base class for all neural network modules.
Your models should also subclass this class.
Modules can also contain other Modules, allowing to nest them in a tree structure. You can assign the submodules as regular attributes:
import torch.nn as nn import torch.nn.functional as F class Model(nn.Module): def __init__(self): super().__init__() self.conv1 = nn.Conv2d(1, 20, 5) self.conv2 = nn.Conv2d(20, 20, 5) def forward(self, x): x = F.relu(self.conv1(x)) return F.relu(self.conv2(x))
Submodules assigned in this way will be registered, and will have their parameters converted too when you call
to()
, etc.Note
As per the example above, an
__init__()
call to the parent class must be made before assignment on the child.- Variables:
training (bool) – Boolean represents whether this module is in training or evaluation mode.
- _keys_to_ignore_on_load_unexpected: List[str] = ['pooler']
- __init__(config)
Initializes internal Module state, shared by both nn.Module and ScriptModule.
- forward(input_ids=None, attention_mask=None, token_type_ids=None, position_ids=None, head_mask=None, inputs_embeds=None, labels=None, center_positions=[], ignore_cpos=None, output_attentions=None, output_hidden_states=None, return_dict=None)
- labels (
torch.LongTensor
of shape(batch_size, sequence_length)
, optional): Labels for computing the token classification loss. Indices should be in
[0, ..., config.num_labels - 1]
.
- Parameters:
input_ids (Optional[torch.LongTensor]) – The input IDs. Defaults to None.
attention_mask (Optional[torch.FloatTensor]) – The attention mask. Defaults to None.
token_type_ids (Optional[torch.LongTensor]) – Type IDs of the tokens. Defaults to None.
position_ids (Optional[torch.LongTensor]) – Position IDs. Defaults to None.
head_mask (Optional[torch.FloatTensor]) – Head mask. Defaults to None.
inputs_embeds (Optional[torch.FloatTensor]) – Input embeddings. Defaults to None.
labels (Optional[torch.LongTensor]) – Labels. Defaults to None.
center_positions (Optional[Any]) – Cennter positions. Defaults to None.
output_attentions (Optional[bool]) – Output attentions. Defaults to None.
ignore_cpos (Optional[bool]) – If center positions are to be ignored.
output_hidden_states (Optional[bool]) – Output hidden states. Defaults to None.
return_dict (Optional[bool]) – Whether to return a dict. Defaults to None.
- Returns:
TokenClassifierOutput – The token classifier output.
- labels (