Skip to content

fix: remove unconditional overwrite that disables teacher forcing in Seq2Seq#1380

Open
phoneee wants to merge 1 commit intoPyThaiNLP:devfrom
phoneee:fix/thai2rom-teacher-forcing
Open

fix: remove unconditional overwrite that disables teacher forcing in Seq2Seq#1380
phoneee wants to merge 1 commit intoPyThaiNLP:devfrom
phoneee:fix/thai2rom-teacher-forcing

Conversation

@phoneee
Copy link
Copy Markdown
Contributor

@phoneee phoneee commented Mar 29, 2026

What do these changes do

Remove unconditional decoder_input = topi.detach() that overwrites the teacher forcing if-else block

Fixes #1390

  • Passed code styles and structures
  • Passed code linting checks and unit test

@sonarqubecloud
Copy link
Copy Markdown

@bact bact added this to PyThaiNLP Mar 29, 2026
@bact bact added the bug bugs in the library label Mar 29, 2026
@bact bact requested a review from Copilot March 29, 2026 16:26
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Removes dead-code behavior in the thai2rom Seq2Seq implementation where teacher forcing was unintentionally disabled by an unconditional overwrite, aligning runtime behavior with the intended training/inference logic (fixes #1390).

Changes:

  • Removed unconditional decoder_input = topi.detach() that overwrote the teacher-forcing branch in Seq2Seq.forward().

Comment on lines 418 to 424
# Non-cryptographic use, pseudo-random generator is acceptable here
teacher_force = random.random() < teacher_forcing_ratio # noqa: S311

if teacher_force and target_seq is not None:
decoder_input = target_seq[:, di].reshape(batch_size, 1)
else:
decoder_input = topi.detach()
Copy link

Copilot AI Mar 29, 2026

Choose a reason for hiding this comment

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

The teacher-forcing behavior was previously broken by an unconditional overwrite; this change restores it, but there isn’t a regression test ensuring teacher_forcing_ratio actually affects decoder_input selection. Please add a unit test that forces the teacher-forcing branch deterministically (e.g., by patching random.random) and asserts decoder_input comes from target_seq when enabled, so this doesn’t regress again.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Note that since thai2rom uses torch, it's tests are in "noauto" test group.

The noauto group will not be run on the CI. Have to run the tests locally.

@bact bact moved this to In progress in PyThaiNLP Mar 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug bugs in the library

Projects

Status: In progress

Development

Successfully merging this pull request may close these issues.

bug: Seq2Seq teacher forcing disabled by unconditional overwrite — intentional?

3 participants