medcat.utils.meta_cat.models
Module Contents
Classes
Base class for all neural network modules. |
|
An abstract class to handle weights initialization and a simple interface for downloading and loading pretrained |
- class medcat.utils.meta_cat.models.LSTM(embeddings, config)
Bases:
torch.nn.ModuleBase 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:
transformers.BertPreTrainedModelAn abstract class to handle weights initialization and a simple interface for downloading and loading pretrained models.
- Parameters:
config (transformers.BertConfig) –
- _keys_to_ignore_on_load_unexpected: List[str] = ['pooler']
- __init__(config)
Initializes internal Module state, shared by both nn.Module and ScriptModule.
- Parameters:
config (transformers.BertConfig) –
- Return type:
None
- forward(input_ids=None, attention_mask=None, token_type_ids=None, position_ids=None, head_mask=None, inputs_embeds=None, labels=None, center_positions=None, output_attentions=None, output_hidden_states=None, return_dict=None)
labels (
torch.LongTensorof 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]) –
attention_mask (Optional[torch.FloatTensor]) –
token_type_ids (Optional[torch.LongTensor]) –
position_ids (Optional[torch.LongTensor]) –
head_mask (Optional[torch.FloatTensor]) –
inputs_embeds (Optional[torch.FloatTensor]) –
labels (Optional[torch.LongTensor]) –
center_positions (Optional[Any]) –
output_attentions (Optional[bool]) –
output_hidden_states (Optional[bool]) –
return_dict (Optional[bool]) –
- Return type:
transformers.modeling_outputs.TokenClassifierOutput