8000 Minor fixes to help evaluate ELMo port. by brendan-ai2 · Pull Request #2172 · allenai/allennlp · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on Dec 16, 2022. It is now read-only.

Minor fixes to help evaluate ELMo port. #2172

Merged
merged 3 commits into from
Dec 12, 2018

Conversation

brendan-ai2
Copy link
Contributor

@brendan-ai2
Copy link
Contributor Author

A tiny one. Please take a look!

loss = output_dict["loss"].item()
metrics["loss"] = loss
cumulative_loss += loss

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the consistency a real worry? I think you could make this a tiny bit simpler, something like

loss_count = 0
total_loss = 0.0

# ...

loss = model(**batch).get("loss")

# ...

if loss is not None:
    metrics["loss"] = loss.item()
    total_loss += loss.item()
    loss_count += 1

# ...

if loss_count > 0:
    final_metrics["loss"] = total_loss / loss_count

I feel like that's cleaner, what do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, your code definitely reads cleaner. I switched to that, but at the end I raise if loss_count > 0 and batch_count != loss_count. I agree that it's mostly paranoia, but it would be a really nasty silent error.

Hopefully that's sufficiently clean! Let me know.

@brendan-ai2
Copy link
Contributor Author

Thanks!

@brendan-ai2 brendan-ai2 merged commit a89aeba into allenai:master Dec 12, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0