Skip to content

Add Monte Carlo sampling mode to SaliencyEngine#4

Merged
amrit110 merged 1 commit into
mainfrom
feat/sampling-mode
Jun 5, 2026
Merged

Add Monte Carlo sampling mode to SaliencyEngine#4
amrit110 merged 1 commit into
mainfrom
feat/sampling-mode

Conversation

@amrit110
Copy link
Copy Markdown
Member

@amrit110 amrit110 commented Jun 5, 2026

Summary

  • Adds n_samples and sample_temperature parameters to SaliencyEngine
  • When n_samples > 1, switches from logprob-drop scoring to Monte Carlo sampling: each masked context is run n_samples times at sample_temperature and importance = P(original | full) − P(original | masked)
  • Produces a genuine probability distribution (e.g. 0.0, 0.2, 0.4, 0.6, 0.8, 1.0 with n_samples=5) instead of near-binary scores when the model is highly confident at temperature=0
  • Demo updated to a loan review scenario with n_samples=5, showing a real spread across credit score, employment, loan amount, and income segments

Test plan

  • 52 tests pass (uv run pytest tests/)
  • 11 new tests cover sampling mode, probability calculations, call counts, and edge cases
  • Run examples/demo_saliency.py to verify distribution output

n_samples>1 switches from logprob-drop scoring to sampling:
each masked context is run n_samples times at sample_temperature
and importance = P(original | full) - P(original | masked).

Produces a genuine probability distribution instead of near-binary
scores when the model is confident at temperature=0.

- 11 new tests covering sampling mode, call counts, and edge cases
- Demo updated to use n_samples=5 with a loan review scenario
@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 5, 2026

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

Thanks for integrating Codecov - We've got you covered ☂️

@amrit110 amrit110 merged commit f8761d4 into main Jun 5, 2026
7 checks passed
@amrit110 amrit110 deleted the feat/sampling-mode branch June 5, 2026 12:36
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.

1 participant