dreeam¶
knowledge_graph.news.dreeam
DREEAM (Ma et al., 2023), adapted from https://github.com/YoumiMa/dreeam (MIT).
Uses supervised relation and sentence-evidence losses.
DocREModel
¶
Bases: Module
Source code in src/knowledge_graph/news/dreeam.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 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 70 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 135 136 137 138 139 140 141 | |
config = config
instance-attribute
¶
model = model
instance-attribute
¶
hidden_size = config.hidden_size
instance-attribute
¶
offset = 1 if config.transformer_type in ('bert', 'roberta') else 0
instance-attribute
¶
loss_fnt = ATLoss()
instance-attribute
¶
loss_fnt_evi = nn.KLDivLoss(reduction='batchmean')
instance-attribute
¶
head_extractor = nn.Linear(self.hidden_size * 2, emb_size)
instance-attribute
¶
tail_extractor = nn.Linear(self.hidden_size * 2, emb_size)
instance-attribute
¶
bilinear = nn.Linear(emb_size * block_size, config.num_labels)
instance-attribute
¶
emb_size = emb_size
instance-attribute
¶
block_size = block_size
instance-attribute
¶
num_labels = num_labels
instance-attribute
¶
encode(input_ids, attention_mask, long_input_encoder=None)
¶
Token states and attention from the supplied encoder or the default chunk encoder.
Source code in src/knowledge_graph/news/dreeam.py
35 36 37 38 | |
get_hrt(sequence_output, attention, entity_pos, hts)
¶
Pool head, tail, and context representations; retain token attention for evidence scoring.
Source code in src/knowledge_graph/news/dreeam.py
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 70 71 72 73 | |
forward_rel(hs, ts, rs)
¶
Classify entity pairs with grouped bilinear interactions.
Source code in src/knowledge_graph/news/dreeam.py
75 76 77 78 79 80 81 82 83 84 85 86 87 | |
forward_evi(doc_attn, sent_pos, batch_rel)
¶
Sum token attention into a sentence-evidence distribution for each entity pair.
Source code in src/knowledge_graph/news/dreeam.py
89 90 91 92 93 94 95 96 97 98 | |
forward(input_ids=None, attention_mask=None, labels=None, entity_pos=None, hts=None, sent_pos=None, sent_labels=None, long_input_encoder=None)
¶
Source code in src/knowledge_graph/news/dreeam.py
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 135 136 137 138 139 140 141 | |