Skip to content

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

Merged
wannaphong merged 1 commit into
PyThaiNLP:devfrom
phoneee:fix/thai2rom-teacher-forcing
Jul 29, 2026
Merged

fix: remove unconditional overwrite that disables teacher forcing in Seq2Seq#1380
wannaphong merged 1 commit into
PyThaiNLP:devfrom
phoneee:fix/thai2rom-teacher-forcing

Conversation

@phoneee

@phoneee phoneee commented Mar 29, 2026

Copy link
Copy Markdown
Contributor

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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()

Copilot AI Mar 29, 2026

Copy link

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
@github-actions

github-actions Bot commented May 1, 2026

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions Bot added the stale label May 1, 2026
@wannaphong
wannaphong merged commit fd089d9 into PyThaiNLP:dev Jul 29, 2026
31 checks passed
@github-project-automation github-project-automation Bot moved this from In progress to Done in PyThaiNLP Jul 29, 2026
wannaphong added a commit that referenced this pull request Jul 29, 2026
wannaphong added a commit that referenced this pull request Jul 29, 2026
### Fixed

- Change loop limit from 20 to dec_maxlen #1464
- fix: remove duplicate .replace mid-tone in _clean_ipa #1409
- Fix: CodeQL ReDoS vulnerability in ULMFiT replace_url #1400
- fix: remove unconditional overwrite that disables teacher forcing in Seq2Seq #1380
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug bugs in the library stale

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

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

4 participants