xiaohongshu
xiaohongshu
count-dataset-tokens
This skill provides guidance for counting tokens in datasets using specific tokenizers. It should be used when tasks involve tokenizing dataset content, filtering data by domain or category, and aggregating token counts. Common triggers include requests to count tokens in HuggingFace datasets, fi...
Full skill instructions
This skill guides the process of counting tokens in datasets, typically from HuggingFace Hub or similar sources. These tasks involve loading datasets, filtering by specific criteria (domains, categories, splits), tokenizing text fields, and computing aggregate statistics.
Before writing any code, thoroughly examine the dataset documentation and structure:
Read the README/dataset card completely - Look for:
Explore the actual data - Write exploratory code to:
Document findings before proceeding - Note:
When task wording is ambiguous, especially regarding filter criteria:
Use exact terminology from the dataset - If the task asks for "science" tokens but the dataset has "biology", "chemistry", "physics" domains:
Handle missing categories correctly:
Distinguish between:
Load the correct tokenizer:
Write robust counting code:
# Example structure
from transformers import AutoTokenizer
from datasets import load_dataset
# Load tokenizer
tokenizer = AutoTokenizer.from_pretrained("tokenizer-name")
# Load dataset (use streaming for large datasets)
dataset = load_dataset("dataset-name", split="train")
# Filter by exact criteria
filtered = dataset.filter(lambda x: x["domain"] == "exact_value")
# Count tokens with null/empty handling
total_tokens = 0
for item in filtered:
text = item.get("text_field")
if text: # Handle None and empty strings
tokens = tokenizer.encode(text)
total_tokens += len(tokens)
Handle edge cases:
Validate filter results:
Sanity check token counts:
Document assumptions:
Problem: Assuming "science" means biology + chemistry + physics without documentation support. Solution: Always use exact filter values from the dataset. When exact matches fail, report the discrepancy rather than reinterpreting.
Problem: Writing filtering code before understanding available field values. Solution: Always run exploratory analysis first:
# Check unique values before filtering
print(dataset.unique("domain")) # or equivalent
Problem: Missing domain definitions or field specifications in the README. Solution: Read the entire dataset card, including any linked documentation. Look for schema definitions, data dictionaries, or field value enumerations.
Problem: Filter returns zero results but code continues without warning. Solution: Always check and report filter result counts:
filtered = dataset.filter(condition)
print(f"Filtered count: {len(filtered)}")
if len(filtered) == 0:
print("WARNING: No records match filter criteria")
Problem: Tokenizing None or empty strings causes errors or incorrect counts. Solution: Always validate text content before tokenizing:
if text and isinstance(text, str) and len(text.strip()) > 0:
tokens = tokenizer.encode(text)
Problem: Proceeding with reinterpreted criteria without expressing uncertainty. Solution: When making interpretation decisions, document them clearly and flag the uncertainty in results.
Before finalizing results, verify:
xiaohongshu
technical spec
product ux expert
database patterns
Conduct multi-agent task orchestration and workflow coordination.
Initialize project with Conductor artifacts (product definition,
Expert in web animations, transitions, and motion design using Framer Motion and CSS
Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...
PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.
Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...
Display project status, active tracks, and next actions
Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience