medcat.components.addons.relation_extraction.llama.model
Classes:
-
LlamaPooler–An attempt to copy the BERT pooling technique for an increase in
-
RelExtrLlamaModel–LlamaModel class for RelCAT
Attributes:
-
logger–
LlamaPooler
LlamaPooler(hidden_size: int)
Bases: Module
An attempt to copy the BERT pooling technique for an increase in performance.
Initialises the pooler with a linear layer of size
self.model_config.hidden_size x self.model_config.hidden_size
Parameters:
-
(hidden_sizeint) –size of tensor
Methods:
-
forward–
Attributes:
-
activation– -
dense–
Source code in medcat-v2/medcat/components/addons/relation_extraction/llama/model.py
231 232 233 234 235 236 237 238 239 240 | |
activation
instance-attribute
activation = Tanh()
forward
forward(hidden_states: Tensor) -> Tensor
Source code in medcat-v2/medcat/components/addons/relation_extraction/llama/model.py
242 243 244 245 246 247 248 249 250 251 252 253 254 | |
RelExtrLlamaModel
RelExtrLlamaModel(pretrained_model_name_or_path: str, relcat_config: ConfigRelCAT, model_config: RelExtrLlamaConfig)
Bases: RelExtrBaseModel
LlamaModel class for RelCAT
Class to hold the Llama model + model_config
Parameters:
-
(pretrained_model_name_or_pathstr) –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.
-
(relcat_configConfigRelCAT) –relcat config.
-
(model_configUnion[RelExtrBaseConfig | RelExtrLlamaConfig]) –HF bert config for model.
Methods:
-
forward– -
load_specific– -
output2logits–Args:
Attributes:
-
drop_out– -
hf_model– -
llama_pooler– -
model_config– -
name– -
relcat_config–
Source code in medcat-v2/medcat/components/addons/relation_extraction/llama/model.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | |
drop_out
instance-attribute
drop_out = Dropout(dropout)
hf_model
instance-attribute
hf_model = LlamaModel(config=hf_model_config)
name
class-attribute
instance-attribute
name = 'llamamodel_relcat'
forward
forward(input_ids: Optional[Tensor] = None, attention_mask: Optional[Tensor] = None, token_type_ids: Optional[Tensor] = None, position_ids: Any = None, head_mask: Any = None, encoder_hidden_states: Any = None, encoder_attention_mask: Any = None, Q: Any = None, e1_e2_start: Any = None, pooled_output: Any = None) -> tuple[Tensor, Tensor]
Source code in medcat-v2/medcat/components/addons/relation_extraction/llama/model.py
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | |
load_specific
classmethod
load_specific(pretrained_model_name_or_path: str, relcat_config: ConfigRelCAT, model_config: RelExtrLlamaConfig, **kwargs) -> RelExtrLlamaModel
Source code in medcat-v2/medcat/components/addons/relation_extraction/llama/model.py
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 | |
output2logits
output2logits(pooled_output: Tensor, sequence_output: Tensor, input_ids: Tensor, e1_e2_start: Tensor) -> Tensor
Parameters:
-
(pooled_outputTensor) –embedding of the CLS token
-
(sequence_outputTensor) –hidden states/embeddings for each token in the input text
-
(input_idsTensor) –input token ids.
-
(e1_e2_startTensor) –annotation tags token position
Returns:
-
Tensor–torch.Tensor: classification probabilities for each token.
Source code in medcat-v2/medcat/components/addons/relation_extraction/llama/model.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | |