@@ -292,6 +292,105 @@ python scripts/statics.py data/sample_dataset.jsonl --output data/analyzed_datas
292292✅ 成功写入 1,827 条数据
293293```
294294
295+ ### 语言分类工具
296+
297+ WebMainBench 提供了语言分类工具 ` scripts/language_classify.py ` ,用于为数据集中的文本内容自动添加符合 ISO 639-1 标准的语言标签。
298+
299+ #### 主要特性
300+
301+ - ** 多种检测方式** :支持基于规则的快速检测和基于LLM的高精度检测
302+ - ** ISO 639-1 标准** :返回标准的两字母语言代码(如 en, zh, es)
303+ - ** 广泛语言支持** :支持80+种主要语言的检测
304+ - ** 批量处理** :高效处理大规模数据集
305+ - ** 智能回退** :多字段检测,自动处理缺失数据
306+
307+ #### 使用方法
308+
309+ ``` bash
310+ # 基于规则的快速检测(推荐用于大规模数据)
311+ python scripts/language_classify.py data/input.jsonl --output data/output.jsonl
312+
313+ # 使用LLM进行高精度检测
314+ python scripts/language_classify.py data/input.jsonl --output data/output.jsonl \
315+ --use-llm --api-key YOUR_OPENAI_API_KEY
316+
317+ # 自定义批处理大小
318+ python scripts/language_classify.py data/input.jsonl --output data/output.jsonl \
319+ --batch-size 50
320+ ```
321+
322+ #### Prompt设计建议
323+
324+ 如果你使用LLM进行语言检测,工具内置了优化的prompt模板:
325+
326+ ** 核心设计原则:**
327+ 1 . ** 明确输出格式** :只返回ISO 639-1两字母代码
328+ 2 . ** 处理边界情况** :空文本、多语言文本、符号等
329+ 3 . ** 语言映射规则** :中文统一返回"zh",未支持语言返回最接近的
330+ 4 . ** 文本截断** :只分析前2000字符,提高效率
331+
332+ ** 示例Prompt结构:**
333+ ```
334+ Please identify the primary language of the following text and return ONLY the ISO 639-1 two-letter language code.
335+
336+ SUPPORTED LANGUAGES: en (English), zh (Chinese), es (Spanish), ...
337+
338+ RULES:
339+ 1. Return ONLY the two-letter code
340+ 2. For mixed languages, return the DOMINANT language
341+ 3. Empty text defaults to "en"
342+ 4. Chinese variants all return "zh"
343+
344+ TEXT TO ANALYZE: [your text here]
345+
346+ LANGUAGE CODE:
347+ ```
348+
349+ #### 输出结果
350+
351+ 工具会在数据的 ` meta.language ` 字段中添加语言标签:
352+
353+ ``` json
354+ {
355+ "convert_main_content" : " Hello, this is sample content." ,
356+ "meta" : {
357+ "language" : " en"
358+ }
359+ }
360+ ```
361+
362+ #### 运行示例
363+
364+ ``` bash
365+ # 处理示例
366+ python scripts/language_classify.py data/sample.jsonl --output data/sample_with_lang.jsonl
367+
368+ # 输出:
369+ 🔄 开始处理语言分类...
370+ 📄 输入文件: data/sample.jsonl
371+ 📄 输出文件: data/sample_with_lang.jsonl
372+ 🧠 检测方法: 基于规则
373+ 📊 已处理 100 条数据...
374+ 📊 已处理 200 条数据...
375+
376+ ✅ 处理完成!
377+ 📊 总计处理: 1,000 条数据
378+ 📊 语言分布:
379+ en (English): 650 (65.0%)
380+ zh (Chinese): 200 (20.0%)
381+ es (Spanish): 80 (8.0%)
382+ fr (French): 40 (4.0%)
383+ de (German): 30 (3.0%)
384+ ```
385+
386+ #### 支持的语言
387+
388+ 工具支持80+种主要语言,包括:
389+ - ** 欧洲语言** :英语(en)、西班牙语(es)、法语(fr)、德语(de)、意大利语(it)等
390+ - ** 亚洲语言** :中文(zh)、日语(ja)、韩语(ko)、泰语(th)、越南语(vi)等
391+ - ** 其他语言** :阿拉伯语(ar)、俄语(ru)、葡萄牙语(pt)、印地语(hi)等
392+
393+ 完整列表请运行:` python examples/language_classify_demo.py `
295394
296395## 项目架构
297396
0 commit comments