:py:mod:`medcat.utils.relation_extraction.llama.model` ====================================================== .. py:module:: medcat.utils.relation_extraction.llama.model Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: medcat.utils.relation_extraction.llama.model.LlamaModel_RelationExtraction medcat.utils.relation_extraction.llama.model.LlamaPooler .. py:class:: LlamaModel_RelationExtraction(pretrained_model_name_or_path, relcat_config, model_config) Bases: :py:obj:`medcat.utils.relation_extraction.models.BaseModel_RelationExtraction` LlamaModel class for RelCAT .. py:attribute:: name :value: 'llamamodel_relcat' .. py:attribute:: log .. py:method:: __init__(pretrained_model_name_or_path, relcat_config, model_config) Class to hold the Llama model + model_config :param pretrained_model_name_or_path: path to load the model from, this can be a HF model i.e: "bert-base-uncased", if left empty, it is normally assumed that a model is loaded from 'model.dat' using the RelCAT.load() method. So if you are initializing/training a model from scratch be sure to base it on some model. :type pretrained_model_name_or_path: str :param relcat_config: relcat config. :type relcat_config: ConfigRelCAT :param model_config: HF bert config for model. :type model_config: Union[BaseConfig_RelationExtraction | LlamaConfig_RelationExtraction] .. py:method:: output2logits(pooled_output, sequence_output, input_ids, e1_e2_start) :param pooled_output: embedding of the CLS token :type pooled_output: torch.Tensor :param sequence_output: hidden states/embeddings for each token in the input text :type sequence_output: torch.Tensor :param input_ids: input token ids. :type input_ids: torch.Tensor :param e1_e2_start: annotation tags token position :type e1_e2_start: torch.Tensor :Returns: **torch.Tensor** -- classification probabilities for each token. .. py:method:: forward(input_ids = None, attention_mask = None, token_type_ids = None, position_ids = None, head_mask = None, encoder_hidden_states = None, encoder_attention_mask = None, Q = None, e1_e2_start = None, pooled_output = None) Forward pass for the model :param input_ids: input token ids. Defaults to None. :type input_ids: torch.Tensor :param attention_mask: attention mask for the input ids. Defaults to None. :type attention_mask: torch.Tensor :param token_type_ids: token type ids for the input ids. Defaults to None. :type token_type_ids: torch.Tensor :param position_ids: The position IDs. Defaults to None. :type position_ids: Any :param head_mask: The head mask. Defaults to None. :type head_mask: Any :param encoder_hidden_states: Encoder hidden states. Defaults to None. :type encoder_hidden_states: Any :param encoder_attention_mask: Encoder attention mask. Defaults to None. :type encoder_attention_mask: Any :param Q: Q. Defaults to None. :type Q: Any :param e1_e2_start: start and end indices for the entities in the input ids. Defaults to None. :type e1_e2_start: Any :param pooled_output: The pooled output. Defaults to None. :type pooled_output: Any :Returns: **Optional[Tuple[torch.Tensor, torch.Tensor]]** -- logits for the relation classification task. .. py:method:: load(pretrained_model_name_or_path, relcat_config, model_config, **kwargs) :classmethod: Load the model from the given path :param pretrained_model_name_or_path: path to load the model from. :type pretrained_model_name_or_path: str :param relcat_config: relcat config. :type relcat_config: ConfigRelCAT :param model_config: The model-specific config. :type model_config: BaseConfig_RelationExtraction :returns: **BaseModel_RelationExtraction** -- The loaded model. .. py:class:: LlamaPooler(hidden_size) Bases: :py:obj:`torch.nn.Module` An attempt to copy the BERT pooling technique for an increase in performance. :param nn: . :type nn: nn.Module .. py:method:: __init__(hidden_size) Initialises the pooler with a linear layer of size: self.model_config.hidden_size x self.model_config.hidden_size :param hidden_size: size of tensor :type hidden_size: int .. py:method:: forward(hidden_states)