Skip to content
Snippets Groups Projects
Commit babe4307 authored by kreuzer's avatar kreuzer
Browse files

Aktualisieren models.py

parent d4c8ca3d
No related branches found
No related tags found
No related merge requests found
......@@ -4,6 +4,8 @@ from torch import nn
import numpy as np
import utils #
import sys
import traceback
class SummarisationModel(nn.Module):
......@@ -120,23 +122,29 @@ class ActorOnlySummarisationModel(SummarisationModel):
self.optimizer.zero_grad()
for datapoint in batch:
# documents with empty content!
if len(datapoint.raw_document) == 0 or len(datapoint.raw_summary) == 0:
print("Warning! This datapoint has an empty document or an empty summary")
continue
_, probs = self.__call__(datapoint.document)
try: # Prevent breakdown for inapt datapoints
# documents with empty content!
if len(datapoint.raw_document) == 0 or len(datapoint.raw_summary) == 0:
print("Warning! This datapoint has an empty document or an empty summary")
continue
o = datapoint.p_searchspace @ torch.log(probs) + datapoint.n_searchspace @ torch.log(1 - probs)
_, probs = self.__call__(datapoint.document)
idx_sample = torch.argmax(o)
o = datapoint.p_searchspace @ torch.log(probs) + datapoint.n_searchspace @ torch.log(1 - probs)
loss = - datapoint.top_rouge[idx_sample] * o[idx_sample]
idx_sample = torch.argmax(o)
loss.backward()
loss = - datapoint.top_rouge[idx_sample] * o[idx_sample]
epoch_loss += loss.item()
epoch_rouge += datapoint.top_rouge[idx_sample]
loss.backward()
epoch_loss += loss.item()
epoch_rouge += datapoint.top_rouge[idx_sample]
except Exception as e:
traceback.print_exception(*sys.exc_info())
continue
self.optimizer.step()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment