词汇重复率计算
更新时间:2026-06-15
简介
词重复比例计算器 - 基于N-gram词组重复比例的文本特征提取
功能描述
- 词重复比例计算:精确统计文本中重复词组的比例
- 双语言支持:支持中文、英文的分词处理
- 灵活配置:支持不同长度的N-gram词组计算
- 文本质量评估
- 数据清洗和预处理
- 内容重复检测
- 基于空格分词:适用于英文等空格分隔的语言
- 基于模型分词:使用sentencepiece模型,中文须使用此模式
- 可配置N-gram长度:支持1-N个词的组合
- 智能过滤:自动过滤特殊字符,提高计算准确性
算子参数
输入
| 输入 | 含义 |
|---|---|
| texts | 待处理的文本列,要求元素类型为字符串 |
输出
| 输出 | 含义 |
|---|---|
| result | pa.Array: 词重复比例列,元素为浮点数,表示重复词组比例 |
参数
| 参数名称 | 类型 | 默认值 | 描述 |
|---|---|---|---|
| repetition | int | 5 | 词组长度 描述:用于拼接成词组的单词数量 默认值:5 |
| lang | str | 'zh' | 语种 描述:文本的语种,支持zh(中文)、en(英文) 默认值:"zh" |
| tokenization | bool | True | 是否使用分词器 描述:是否使用sentencepiece模型进行分词,中文须开启 默认值:True |
| model_path | str | '/opt/aihc/models' | 模型文件所在的路径 默认值:"/opt/aihc/models" |
| model_name | str | 'kenlm/wikipedia' | 模型名称 默认值:"kenlm/wikipedia" |
调用示例
Python
1from __future__ import annotations
2
3import os
4
5import daft
6from daft import col
7
8from daft.aihc.common.udf import aihc_udf
9from daft.aihc.functions.text.word_repetition_calculator import WordRepetitionCalculator
10
11if __name__ == "__main__":
12 if os.getenv("DAFT_RUNNER", "native") == "ray":
13 import ray
14 ray.init(dashboard_host="0.0.0.0", ignore_reinit_error=True)
15 daft.set_runner_ray()
16 daft.set_execution_config(actor_udf_ready_timeout=6000, min_cpu_per_task=0)
17
18 # TODO: 根据实际场景准备样本数据
19 samples = {"texts": [...]}
20 ds = daft.from_pydict(samples)
21 constructor_kwargs = {
22 "repetition": 5,
23 "lang": 'zh',
24 "tokenization": True,
25 "model_path": '/opt/aihc/models',
26 "model_name": 'kenlm/wikipedia',
27 }
28 ds = ds.with_column(
29 "result",
30 aihc_udf(
31 WordRepetitionCalculator,
32 construct_args=constructor_kwargs,
33 num_cpus=1,
34 concurrency=4,
35 batch_size=8,
36 )(col("texts")),
37 )
38 ds.show()
评价此篇文章
