脱字符
  
Caret是一个用于检查和清理大型LLM训练数据集的终端工具。它使用内存映射I/O处理JSONL、Parquet和CSV文件,包括近重复检测、令牌可视化、数据集linting和 主控程序 服务器。
快速开始
git clone https://github.com/rouapps/caret.git
cd caret && cargo build --release
caret data.jsonl # JSONL (memory-mapped)
caret data.parquet # Parquet (Arrow-native)
caret data.csv # CSV
caret hf://tatsu-lab/alpaca # Stream from HuggingFace (no download)
caret data.jsonl --mcp-port 3100 # Start MCP server alongside TUI运作原理
Caret内存通过以下方式映射文件 memmap2 并构建行边界的字节偏移索引。行访问是O(1)——操作系统页面缓存处理其余部分。数据永远不会复制到用户空间;直接在映射的区域中切叉。
对于远程HuggingFace数据集,Caret仅通过HTTP Range请求获取槌球页脚元数据,然后在滚动时按需加载行组。
特性
- 存储器映射 --任何大小的文件都可以立即打开,RSS几乎为零
- 接近重复检测 --硬件SimHash指纹识别
POPCNT,通过并行化rayon - HuggingFace Hub流媒体 --浏览远程数据集而不下载它们
- MCP服务器 --将数据集工具暴露给Claude Desktop、Cursor或任何MCP客户端
- 令牌X射线 --可视化标记化边界(Tiktoken、HuggingFace、GPT-2)
- 数据集linter --捕捉不平衡 `` 标签、无效JSON、缺少密钥
- 自动修正 --修复JSONL数据集中的常见格式问题
- 详图面板 --分屏打印的JSON视图
- 管道支持 --从stdin读取(
cat data.jsonl | caret -)
MCP服务器
Caret实施 模型上下文协议,公开这些工具:
| 工具 | 说明 |
|---|---|
search_dataset | 在数据集中搜索正则表达式 |
dataset_info | 行数、文件大小、格式元数据 |
get_lines | 随机访问任何线路范围 |
dedup_scan | SimHash使用统计数据进行数据删除 |
jump_to_line | 将TUI导航到特定行 |
toggle_view | 循环视图模式(文本/令牌X射线/树) |
show_detail | 显示/隐藏细节面板 |
caret data.jsonl --mcp-port 3100 # TUI + MCP server
caret data.jsonl --mcp-only # Headless (for CI/pipelines)TUI控制工具(jump_to_line, toggle_view, show_detail)允许AI助手在您观看时交互式地导航数据集——让Claude或Gemini“跳到第500行并显示令牌”,TUI会立即做出响应。
要与Claude Desktop一起使用,请添加到 claude_desktop_config.json:
{
"mcpServers": {
"caret": {
"command": "/path/to/caret",
"args": ["your_dataset.jsonl", "--mcp-only", "--mcp-port", "3100"]
}
}
}HuggingFace Hub流媒体
caret hf://allenai/c4 # Default split
caret hf://tatsu-lab/alpaca/train # Specific split
caret hf://allenai/c4/en/validation # Config + split关心问题a HEAD 请求获取文件大小,获取4字节的Parquet页脚长度,读取Thrift元数据(几KB),然后仅加载您滚动到的行组。第一页出现在第二页以下。
去重
caret data.jsonl --dedup # Scan and report
caret data.jsonl --dedup --dedup-export clean.jsonl # Export unique lines
caret data.jsonl --dedup --dedup-strategy exact # Exact match only
caret data.jsonl --dedup --dedup-threshold 5 # Aggressive fuzzy (0-10, default 3)按 D 在TUI中运行交互式去重扫描。重复项以突出显示 DUP 徽章。
该引擎分为两个阶段:并行指纹识别(工作人员直接从mmap读取,通过FNV-1a瓦片将哈希内容转换为64位SimHash),然后是索引构建(每个指纹通过 XOR + POPCNT).在一个紧凑的位掩码中跟踪重复项——10亿行大约需要125 MB。
键盘快捷键
| 关键 | 行动 |
|---|---|
j / Down | 向下移动 |
k / Up | 向上移动 |
g / G | 顶部/底部 |
Ctrl+d / Ctrl+u | 向下/向上翻页 |
Tab | 循环视图:文本/令牌X射线/树 |
Enter | 切换细节面板 |
D | 切换去重扫描 |
? | 帮助 |
q | 退出 |
使用参考
# Local files
caret data.jsonl # Auto-detect format
caret data.parquet # Parquet
caret data.csv # CSV
caret data.txt --format jsonl # Force format
# HuggingFace
caret hf://org/dataset # Default split (train)
caret hf://org/dataset/validation # Specific split
caret hf://org/dataset/config/split # Config + split
# MCP server
caret data.jsonl --mcp-port 3100 # TUI + MCP
caret data.jsonl --mcp-only # Headless
caret data.jsonl --mcp-only --mcp-port 8080 # Custom port
# Deduplication
caret data.jsonl --dedup # Scan and report
caret data.jsonl --dedup --dedup-export clean.jsonl # Export unique lines
caret data.jsonl --dedup --dedup-strategy exact # Exact match
caret data.jsonl --dedup --dedup-threshold 5 # Aggressive fuzzy
# Linting
caret data.jsonl --lint
caret data.jsonl --lint --required-keys "messages,prompt"
# Token visualization
caret data.jsonl -t # Tiktoken cl100k_base
caret data.jsonl -t --tiktoken-encoding p50k_base # Codex encoding
caret data.jsonl -t --tokenizer-type huggingface # Llama 3.1
caret data.jsonl --tokenizer-path ./my-tokenizer.json # Custom tokenizer
# Auto-fix
caret data.jsonl --fix # Creates data_fixed.jsonl
caret data.jsonl --fix -o output.jsonl # Custom output
caret data.jsonl --fix --fix-in-place # Overwrite original
# Pipeline
cat data.jsonl | caret -建筑
┌──────────────────────────────────────────────────────────────────┐
│ Caret TUI (Ratatui) │
├──────────┬──────────┬──────────────┬──────────┬─────────────────┤
│ Dataset │Tokenizer │ Linter │ Dedup │ MCP Server │
│ (mmap) │(Tiktoken)│(Regex+JSON) │(SimHash) │ (Axum/Tokio) │
├──────────┼──────────┴──────────────┴──────────┤─────────────────┤
│ HF Stream│ memmap2 · serde_json · rayon │ reqwest · axum │
│ (Range) │ │ tower · tracing │
└──────────┴─────────────────────────────────────┴─────────────────┘贡献
欢迎捐款。查看标记的问题 good first issue.
cargo run -- test_data.jsonl # Development
cargo test # Tests
cargo build --release # Optimized build
RUST_LOG=caret=debug cargo run -- test_data.jsonl # Debug logging需求
- 锈蚀1.75+
- 支持256色的终端
许可证
麻省理工学院——见 许可证.
