Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically calculate perplexity metrics for model supportability #1008

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

ayissi-msft
Copy link
Contributor

This PR aims to enhance our model validation process by automatically calculating the perplexity metrics if the model has the corresponding dataset. This will allow us to generate a strong report on the model's supportability, providing valuable insights into its performance and reliability.

targets = np.roll(input_ids, -1, axis=1)

# Use LogSoftMax here
log_probs = torch.nn.functional.log_softmax(torch.tensor(logits), dim=1).numpy()

Choose a reason for hiding this comment

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

1

probably -1

log_probs = torch.nn.functional.log_softmax(torch.tensor(logits), dim=1).numpy()

batch_size, seq_length = targets.shape
target_log_probs = log_probs[np.arange(batch_size)[:, None], np.arange(seq_length), targets]

Choose a reason for hiding this comment

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

target_log_probs = log_probs[np.arange(batch_size)[:, None], np.arange(seq_length), targets]

this is the critical part

total_log_probs = 0
total_token_count = 0

for batch in dataset:

Choose a reason for hiding this comment

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

batch in dataset

concatenate all batches


logits = generator.compute_logits("logits")

targets = np.roll(input_ids, -1, axis=1)

Choose a reason for hiding this comment

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

np.roll(input_ids, -1, axis=1)

what does it do?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants