feat(contextual): pipeline part 1 — config, frozen encoder, benchmark - #35
Draft
scheuclu wants to merge 1 commit into
Draft
feat(contextual): pipeline part 1 — config, frozen encoder, benchmark#35scheuclu wants to merge 1 commit into
scheuclu wants to merge 1 commit into
Conversation
…hmark First slice of the contextual word-drift pipeline (issue #34): upgrade from static Word2Vec/TWEC drift to *contextual* drift by running the historical corpus through a frozen transformer encoder. - config.py: CONTEXTUAL_* knobs (model, layer, pooling, window/batch sizes, min-count, centering, PCA-removal, stopwords, output dirs). Append-only; nothing existing is touched. - pipeline/contextual_model.py: ContextualEncoder wraps a frozen bert-base-uncased (bf16, SDPA, inference_mode) with its fast tokenizer. encode_windows() returns hidden states + attention mask + a word_ids tensor that maps every subword back to its source word (word_ids(), not "##"). Hidden width read from config.hidden_size (never hardcode 768). - scripts/contextual_benchmark.py: throughput probe over real 2018 windows (writes nothing). Sweeps batch size, prints words/sec and an hours-per-year ETA table. - pyproject: declare transformers (was installed but undeclared). Benchmark result on the GB10: batch=128 is the optimum at ~80k words/s (dynamic padding makes smaller batches more efficient; far from memory-bound at 1.26 GB). Full 12B-token run ETA ~1.7 days. CONTEXTUAL_BATCH_SIZE set to 128. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Contextual word-drift pipeline — Part 1/3: foundation + benchmark
First slice of the contextual word-drift pipeline (#34). Goal: upgrade WordDrift from static Word2Vec/TWEC drift (300-d, distributional) to contextual drift — run the historical corpus through a frozen transformer encoder and aggregate per-word contextual centroids per year, so we capture sense shifts Word2Vec can't (
zoomlens→video-call,delvebecoming LLM-ese). A frozen shared encoder puts every year in one coordinate system, so no Procrustes/TWEC compass is needed.This is a stacked PR series (each builds on the previous):
--smokeverified)What's here
config.pyCONTEXTUAL_*knobs (model, layer, pooling, window/batch, min-count, centering, PCA-removal, stopwords, output dirs). Append-only — nothing existing touched.pipeline/contextual_model.pyContextualEncoder: frozenbert-base-uncased(bf16, SDPA,inference_mode) + fast tokenizer.encode_windows()returns hidden states + attention mask + aword_idstensor mapping every subword → source word (usesword_ids(), not"##"-stripping). Width read fromconfig.hidden_size.scripts/contextual_benchmark.pypyproject.toml/uv.locktransformers(was installed but undeclared).Benchmark result (GB10)
batch=128 is the optimum at ~80k words/s. With dynamic padding, smaller batches waste less compute on padding; we're nowhere near memory-bound (1.26 GB of 128 GB).
CONTEXTUAL_BATCH_SIZEset to 128. Full 12 B-token run ETA ≈ 1.7 days (~3.5 h/year × 12).Verification
ContextualEncoderloads,hidden_dim=768, fast tokenizer confirmed.configimports cleanly; 116 stopwords loaded.🤖 Generated with Claude Code