jwieting commited on
Commit
0728fa3
1 Parent(s): 4b4d8b5

Update modeling_sim.py

Browse files
Files changed (1) hide show
  1. modeling_sim.py +4 -5
modeling_sim.py CHANGED
@@ -11,8 +11,7 @@ class SimModel(MobileBertPreTrainedModel):
11
  self.post_init()
12
 
13
  def forward(self, input_ids, attention_mask, token_type_ids, return_dict):
14
- print(input_ids, attention_mask, token_type_ids)
15
- print(self.word_embeddings(input_ids).size())
16
- import pdb
17
- pdb.set_trace()
18
- return (self.word_embeddings(input_ids), None, None)
 
11
  self.post_init()
12
 
13
  def forward(self, input_ids, attention_mask, token_type_ids, return_dict):
14
+ embeddings = self.word_embeddings(input_ids)
15
+ masked_embeddings = embeddings * attention_mask[:, :, None]
16
+ mean_pooled_embeddings = masked_embeddings.sum(dim=1) / attention_mask[:, :, None].sum(dim=1)
17
+ return (embeddings, mean_pooled_embeddings, embeddings)