Skip to content

Commit

Permalink
Update main.py
Browse files Browse the repository at this point in the history
removing f1 calculation in training
  • Loading branch information
Coopercoppers authored Oct 13, 2021
1 parent 5b1776d commit eb3be20
Showing 1 changed file with 0 additions and 22 deletions.
22 changes: 0 additions & 22 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,6 @@ def set_seed(seed):
for epoch in range(args.epoch):
steps, train_loss = 0, 0

total_triple_num = [0, 0, 0]
total_entity_num = [0, 0, 0]

if args.eval_metric == "macro":
total_triple_num = total_triple_num * len(rel2idx)
total_entity_num = total_entity_num * len(ner2idx)

model.train()
for data in tqdm(train_batch):

Expand All @@ -209,27 +202,12 @@ def set_seed(seed):
torch.nn.utils.clip_grad_norm_(parameters=model.parameters(), max_norm=args.clip)
optimizer.step()

entity_num = metric.count_ner_num(ner_pred, ner_label)
triple_num = metric.count_num(ner_pred, ner_label, re_pred, re_label)

for i in range(len(entity_num)):
total_entity_num[i] += entity_num[i]
for i in range(len(triple_num)):
total_triple_num[i] += triple_num[i]


if steps % args.steps == 0:
logger.info("Epoch: {}, step: {} / {}, loss = {:.4f}".format
(epoch, steps, len(train_batch), train_loss / steps))


triple_result = f1(total_triple_num)
entity_result = f1(total_entity_num)

logger.info("------ Training Set Results ------")
logger.info("loss : {:.4f}".format(train_loss / steps))
logger.info("entity: p={:.4f}, r={:.4f}, f={:.4f}".format(entity_result["p"], entity_result["r"], entity_result["f"]))
logger.info("triple: p={:.4f}, r={:.4f}, f={:.4f}".format(triple_result["p"], triple_result["r"], triple_result["f"]))

if args.do_eval:
model.eval()
Expand Down

0 comments on commit eb3be20

Please sign in to comment.