Skip to content

fix: handle dict word_list in TextArenaEnv.ta_to_hf()#1214

Open
tashapais wants to merge 1 commit intoPrimeIntellect-ai:mainfrom
tashapais:fix/textarena-dict-word-list
Open

fix: handle dict word_list in TextArenaEnv.ta_to_hf()#1214
tashapais wants to merge 1 commit intoPrimeIntellect-ai:mainfrom
tashapais:fix/textarena-dict-word-list

Conversation

@tashapais
Copy link
Copy Markdown

@tashapais tashapais commented Apr 20, 2026

Summary

  • TextArenaEnv.ta_to_hf() called random.choice(words) assuming word_list is a sequence, but games like TwentyQuestions-v0 expose a categorized dict instead, causing a KeyError on integer indices.
  • Fix flattens dict values into a list before sampling, matching how the official Wordle environment on the Hub works.

Test plan

  • Instantiate TextArenaEnv(game="TwentyQuestions-v0") and confirm no KeyError on init
  • Confirm existing Wordle-v0 behavior is unchanged (list word_list path unchanged)

Closes #1074


Note

Low Risk
Low risk: small defensive change isolated to dataset generation logic, only altering how word_list is normalized before random.choice.

Overview
Fixes TextArenaEnv.ta_to_hf() to handle TextArena games where word_list is a dict (e.g., categorized words) by flattening dict values into a list before sampling.

This prevents sampling/index errors while keeping existing behavior unchanged when word_list is already a sequence.

Reviewed by Cursor Bugbot for commit a5e7075. Bugbot is set up for automated code reviews on this repo. Configure here.

Games like TwentyQuestions-v0 expose a categorized word_list dict
instead of a flat sequence, causing random.choice() to KeyError on
integer indices. Flatten dict values into a list before sampling.

Fixes PrimeIntellect-ai#1074

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@tashapais
Copy link
Copy Markdown
Author

Fixes #1074. The one-line change flattens dict values before sampling, so any TextArena game that uses categorized word lists (TwentyQuestions-v0, etc.) will initialize correctly. @Kannav02 you mentioned wanting to open a PR for this -- happy to hand it off if you'd prefer.

@tashapais
Copy link
Copy Markdown
Author

@willccbb @mikasenghaas ready for review when you get a chance.

@Kannav02
Copy link
Copy Markdown

Fixes #1074. The one-line change flattens dict values before sampling, so any TextArena game that uses categorized word lists (TwentyQuestions-v0, etc.) will initialize correctly. @Kannav02 you mentioned wanting to open a PR for this -- happy to hand it off if you'd prefer.

Its fine, as long as the env gets fixed and works, thanks!

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.

TextArenaEnv.ta_to_hf() crashes when word_list is a dict

2 participants