Skip to content

Select valid BERT QA answer spans (#684)#1852

Open
craymichael wants to merge 1 commit into
meta-pytorch:masterfrom
craymichael:fix/684-bert-qa-valid-span
Open

Select valid BERT QA answer spans (#684)#1852
craymichael wants to merge 1 commit into
meta-pytorch:masterfrom
craymichael:fix/684-bert-qa-valid-span

Conversation

@craymichael

Copy link
Copy Markdown
Contributor

Fixes #684.

Issue: #684
Issue summary: The BERT SQuAD tutorials selected the start and end tokens independently. If the highest-scoring end token came before the highest-scoring start token, the printed answer span was empty.

Context:
In extractive question answering, a span is the contiguous slice of input tokens used as the answer. The start token is the first token in that slice, and the end token is the last token. A valid answer must satisfy end_idx >= start_idx.

Summary:

  • Select the best valid answer span by scoring every start/end token pair and masking pairs where the end token precedes the start token.
  • Apply the same span selection to both BERT SQuAD tutorial notebooks.
  • Add a notebook regression test for invalid independent argmax spans.

Test Plan:

  • venv/uv/bin/python -m pytest -q tests/test_tutorial_regressions.py
  • Pyre: not applicable; notebook-only behavior change covered by regression test.

Issue: meta-pytorch#684
Issue summary: The BERT SQuAD tutorials selected the start and end tokens independently. If the highest-scoring end token came before the highest-scoring start token, the printed answer span was empty.

Context:
In extractive question answering, a span is the contiguous slice of input tokens used as the answer. The start token is the first token in that slice, and the end token is the last token. A valid answer must satisfy end_idx >= start_idx.

Summary:
- Select the best valid answer span by scoring every start/end token pair and masking pairs where the end token precedes the start token.
- Apply the same span selection to both BERT SQuAD tutorial notebooks.
- Add a notebook regression test for invalid independent argmax spans.

Test Plan:
- venv/uv/bin/python -m pytest -q tests/test_tutorial_regressions.py
- Pyre: not applicable; notebook-only behavior change covered by regression test.
@meta-cla meta-cla Bot added the cla signed label May 22, 2026
@meta-codesync

meta-codesync Bot commented May 22, 2026

Copy link
Copy Markdown
Contributor

@craymichael has imported this pull request. If you are a Meta employee, you can view this in D106053849.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BERT Question Answering tutorials - prediction output script bug

1 participant