文本链接移除
更新时间:2026-05-18
文本链接移除
简介
文本链接移除算子,从文本中识别并删除超链接(HTTP/HTTPS URL),用于清洗训练数据中的噪声链接。
功能描述
- 使用正则表达式识别文本中的 HTTP/HTTPS URL
- 将 URL 替换为空字符串或空格
- 空文本或 None 返回 None
算子参数
输入
| 输入 | 含义 |
|---|---|
| texts | 文本字符串数组 |
输出
| 输出 | 含义 |
|---|---|
| cleaned_text | 移除链接后的文本(large_string),空文本返回 None |
参数
无
调用示例
Plain Text
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.remove_links import RemoveLinks
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 samples = {
19 "text": [
20 "Visit https://example.com for more info.",
21 "Check http://foo.bar/path?q=1 and https://baz.com",
22 "No links here.",
23 ]
24 }
25 ds = daft.from_pydict(samples)
26 ds = ds.with_column(
27 "cleaned_text",
28 aihc_udf(
29 RemoveLinks,
30 num_cpus=1,
31 concurrency=4,
32 batch_size=1024,
33 )(col("text")),
34 )
35 ds.show()
评价此篇文章
