Skip to content

Fix #164: meta tokenization in block dataset building - #177

Merged
zhujiem merged 1 commit into
mainfrom
fix_164_meta_tokenization
Aug 22, 2026
Merged

zhujiem merged 1 commit into
mainfrom
fix_164_meta_tokenization

Conversation

@zhujiem

@zhujiem zhujiem commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

What this PR does / why we need it

Fixes two bugs in meta-type feature tokenization reported in #164:

Bug 1: encode_meta crashes on first call

AttributeError: 'dict' object has no attribute 'most_common'
encode_meta passes a plain dict to build_vocab(), which calls .most_common() — a Counter method not available on dict.

Fix: Wrap with Counter(word_counts) before passing to build_vocab().

Bug 2: Inconsistent token-to-ID mapping across blocks

update_vocab allocates new-word IDs based on __OOV__ value, which is the last index after frequency-sorted vocabulary. This causes new-word IDs to collide with or overlap existing IDs when blocks are processed independently.

Fix: Allocate new-word IDs from max(vocab.values()) + 1 (the true next available ID), and sort new words alphabetically to guarantee deterministic, reproducible vocab ordering.

How was this patch tested?

3 regression tests added in tests/unit_tests/preprocess/test_tokenizer.py:

  • test_encode_meta_builds_vocab_on_first_call — verifies no crash, correct vocab structure
  • test_encode_meta_new_words_get_contiguous_ids — verifies cross-block ID consistency and determinism
  • test_encode_meta_new_words_added_to_vocab — verifies incremental vocab update behavior

All tests pass under Python 3.12 / pandas 3.0.5.

3 passed in 5.61s

Closes #164

- encode_meta: wrap word_counts in Counter() before passing to build_vocab()
  to avoid AttributeError ('dict' object has no attribute 'most_common')
- update_vocab: allocate new-word IDs from max(vocab.values())+1 (not
  based on __OOV__) so IDs stay contiguous across blocks; sort new words
  for deterministic, reproducible vocab ordering
- add 3 regression tests in tests/unit_tests/preprocess/test_tokenizer.py

Closes #164
@zhujiem
zhujiem merged commit 897d779 into main Aug 22, 2026
@zhujiem
zhujiem deleted the fix_164_meta_tokenization branch August 22, 2026 01:29
@linyuhui

linyuhui commented Aug 22, 2026 via email

Copy link
Copy Markdown

zhujiem pushed a commit that referenced this pull request Aug 22, 2026
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.

Lazy Tokenization of Meta Type Features Causes Inconsistent Encoding in Block Dataset Building

2 participants