Skip to content

Commit

Permalink
Update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Feb 7, 2024
1 parent 9be6591 commit ae8841c
Showing 1 changed file with 36 additions and 18 deletions.
54 changes: 36 additions & 18 deletions docs/models.html
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,16 @@ <h1 class="title">Module <code>mimir.models</code></h1>
target_ids = input_ids.clone()
target_ids[:, :-trg_len] = -100

outputs = self.model(input_ids, labels=target_ids)
logits = outputs.logits
logits = self.model(input_ids, labels=target_ids).logits.cpu()
shift_logits = logits[..., :-1, :].contiguous()
probabilities = torch.nn.functional.log_softmax(shift_logits, dim=-1)
shift_labels = target_ids[..., 1:].contiguous()
shift_labels = target_ids[..., 1:].cpu().contiguous()
labels_processed = shift_labels[0]

del input_ids
del target_ids


for i, token_id in enumerate(labels_processed):
if token_id != -100:
probability = probabilities[0, i, token_id].item()
Expand Down Expand Up @@ -365,7 +368,7 @@ <h1 class="title">Module <code>mimir.models</code></h1>
attention_mask = tokenized.attention_mask
assert attention_mask.size() == label_batch.size()

needs_sliding = label_batch.size(1) &gt; self.max_length
needs_sliding = label_batch.size(1) &gt; self.max_length // 2
if not needs_sliding:
label_batch = label_batch.to(self.device)
attention_mask = attention_mask.to(self.device)
Expand All @@ -387,8 +390,8 @@ <h1 class="title">Module <code>mimir.models</code></h1>
target_ids[:, :-trg_len] = -100
# target_ids[attention_mask == 0] = -100

outputs = self.model(input_ids, labels=target_ids, attention_mask=mask)
logits = outputs.logits
logits = self.model(input_ids, labels=target_ids, attention_mask=mask).logits.cpu()
target_ids = target_ids.cpu()
shift_logits = logits[..., :-1, :].contiguous()
probabilities = torch.nn.functional.log_softmax(shift_logits, dim=-1)
shift_labels = target_ids[..., 1:].contiguous()
Expand All @@ -398,6 +401,9 @@ <h1 class="title">Module <code>mimir.models</code></h1>
if token_id != -100 and token_id != self.tokenizer.pad_token_id:
probability = probabilities[i, j, token_id].item()
all_prob[i].append(probability)

del input_ids
del mask

# average over each sample to get losses
batch_losses = [-np.mean(all_prob[idx]) for idx in range(label_batch.size(0))]
Expand Down Expand Up @@ -818,7 +824,7 @@ <h3>Inherited members</h3>
attention_mask = tokenized.attention_mask
assert attention_mask.size() == label_batch.size()

needs_sliding = label_batch.size(1) &gt; self.max_length
needs_sliding = label_batch.size(1) &gt; self.max_length // 2
if not needs_sliding:
label_batch = label_batch.to(self.device)
attention_mask = attention_mask.to(self.device)
Expand All @@ -840,8 +846,8 @@ <h3>Inherited members</h3>
target_ids[:, :-trg_len] = -100
# target_ids[attention_mask == 0] = -100

outputs = self.model(input_ids, labels=target_ids, attention_mask=mask)
logits = outputs.logits
logits = self.model(input_ids, labels=target_ids, attention_mask=mask).logits.cpu()
target_ids = target_ids.cpu()
shift_logits = logits[..., :-1, :].contiguous()
probabilities = torch.nn.functional.log_softmax(shift_logits, dim=-1)
shift_labels = target_ids[..., 1:].contiguous()
Expand All @@ -851,6 +857,9 @@ <h3>Inherited members</h3>
if token_id != -100 and token_id != self.tokenizer.pad_token_id:
probability = probabilities[i, j, token_id].item()
all_prob[i].append(probability)

del input_ids
del mask

# average over each sample to get losses
batch_losses = [-np.mean(all_prob[idx]) for idx in range(label_batch.size(0))]
Expand Down Expand Up @@ -1047,7 +1056,7 @@ <h3>Methods</h3>
attention_mask = tokenized.attention_mask
assert attention_mask.size() == label_batch.size()

needs_sliding = label_batch.size(1) &gt; self.max_length
needs_sliding = label_batch.size(1) &gt; self.max_length // 2
if not needs_sliding:
label_batch = label_batch.to(self.device)
attention_mask = attention_mask.to(self.device)
Expand All @@ -1069,8 +1078,8 @@ <h3>Methods</h3>
target_ids[:, :-trg_len] = -100
# target_ids[attention_mask == 0] = -100

outputs = self.model(input_ids, labels=target_ids, attention_mask=mask)
logits = outputs.logits
logits = self.model(input_ids, labels=target_ids, attention_mask=mask).logits.cpu()
target_ids = target_ids.cpu()
shift_logits = logits[..., :-1, :].contiguous()
probabilities = torch.nn.functional.log_softmax(shift_logits, dim=-1)
shift_labels = target_ids[..., 1:].contiguous()
Expand All @@ -1080,6 +1089,9 @@ <h3>Methods</h3>
if token_id != -100 and token_id != self.tokenizer.pad_token_id:
probability = probabilities[i, j, token_id].item()
all_prob[i].append(probability)

del input_ids
del mask

# average over each sample to get losses
batch_losses = [-np.mean(all_prob[idx]) for idx in range(label_batch.size(0))]
Expand Down Expand Up @@ -1391,13 +1403,16 @@ <h3>Inherited members</h3>
target_ids = input_ids.clone()
target_ids[:, :-trg_len] = -100

outputs = self.model(input_ids, labels=target_ids)
logits = outputs.logits
logits = self.model(input_ids, labels=target_ids).logits.cpu()
shift_logits = logits[..., :-1, :].contiguous()
probabilities = torch.nn.functional.log_softmax(shift_logits, dim=-1)
shift_labels = target_ids[..., 1:].contiguous()
shift_labels = target_ids[..., 1:].cpu().contiguous()
labels_processed = shift_labels[0]

del input_ids
del target_ids


for i, token_id in enumerate(labels_processed):
if token_id != -100:
probability = probabilities[0, i, token_id].item()
Expand Down Expand Up @@ -1601,13 +1616,16 @@ <h3>Methods</h3>
target_ids = input_ids.clone()
target_ids[:, :-trg_len] = -100

outputs = self.model(input_ids, labels=target_ids)
logits = outputs.logits
logits = self.model(input_ids, labels=target_ids).logits.cpu()
shift_logits = logits[..., :-1, :].contiguous()
probabilities = torch.nn.functional.log_softmax(shift_logits, dim=-1)
shift_labels = target_ids[..., 1:].contiguous()
shift_labels = target_ids[..., 1:].cpu().contiguous()
labels_processed = shift_labels[0]

del input_ids
del target_ids


for i, token_id in enumerate(labels_processed):
if token_id != -100:
probability = probabilities[0, i, token_id].item()
Expand Down

0 comments on commit ae8841c

Please sign in to comment.