You need to enable JavaScript to run this app.
AI 数据湖服务

AI 数据湖服务

复制全文
文本质量评估
英文文本质量评分
复制全文
英文文本质量评分

算子介绍

描述

英文文本质量评分算子 - 基于FastText的文本质量评估

核心功能

  • 质量评分:使用FastText模型对英文文本质量进行评分,偏好于科学知识,只支持CPU环境。
  • 批量处理:支持批量处理文本,提高处理效率

评分标准

  • 0: 低质量 (Low)
  • 1: 中等质量 (Mid)
  • 2: 高质量 (High)
  • 最终得分为0-2之间的浮点数,分数越高表示质量越好
  • 一般来讲,分数超过0.5,则表示文本质量较好。

Daft 调用

算子参数

输入

输入列名

说明

texts

包含待处理文本的列,元素类型为字符串。

输出

包含文本质量分数的列,元素类型为float64。

参数

如参数没有默认值,则为必填参数

参数名称

类型

默认值

描述

model_path

str

/opt/las/models

模型文件所在的基础路径 默认值:"/opt/las/models"

model_name

str

llm-data-textbook-quality-fasttext-classifier-v2/model_quantized.bin

模型文件名 默认值:"llm-data-textbook-quality-fasttext-classifier-v2/model_quantized.bin"

调用示例

下面的代码展示了如何使用 daft 运行算子基于FastText模型对英文文本质量进行评分。

from __future__ import annotations

import os

import daft
from daft import col
from daft.las.functions.text.en_text_quality_scorer import EnTextQualityScorer
from daft.las.functions.udf import las_udf

if __name__ == "__main__":

    if os.getenv("DAFT_RUNNER", "native") == "ray":
        import logging

        import ray

        def configure_logging():
            logging.basicConfig(
                level=logging.INFO,
                format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
                datefmt="%Y-%m-%d %H:%M:%S.%s".format(),
            )
            logging.getLogger("tracing.span").setLevel(logging.WARNING)
            logging.getLogger("daft_io.stats").setLevel(logging.WARNING)
            logging.getLogger("DaftStatisticsManager").setLevel(logging.WARNING)
            logging.getLogger("DaftFlotillaScheduler").setLevel(logging.WARNING)
            logging.getLogger("DaftFlotillaDispatcher").setLevel(logging.WARNING)

        ray.init(dashboard_host="0.0.0.0", runtime_env={"worker_process_setup_hook": configure_logging})
        daft.context.set_runner_ray()
    daft.set_execution_config(actor_udf_ready_timeout=600)
    daft.set_execution_config(min_cpu_per_task=0)

    samples = {"text": ["This is a well-written scientific article about quantum physics.", None]}
    batch_size = 4
    model_path = os.getenv("MODEL_PATH", "/opt/las/models")
    model_name = "llm-data-textbook-quality-fasttext-classifier-v2/model_quantized.bin"

    ds = daft.from_pydict(samples)
    ds = ds.with_column(
        "quality_score",
        las_udf(
            EnTextQualityScorer,
            construct_args={
                "batch_size": batch_size,
                "model_path": model_path,
                "model_name": model_name,
            },
            num_gpus=0,
            batch_size=1,
            concurrency=1,
        )(col("text")),
    )

    ds.show()
    # ╭──────────────────────────────────────────────────────────────────────────┬─────────────────────╮
    # │ text                                                                     ┆ quality_score       │
    # │ ---                                                                      ┆ ---                 │
    # │ Utf8                                                                     ┆ Float64             │
    # ╞══════════════════════════════════════════════════════════════════════════╪═════════════════════╡
    # │ This is a well-written scientific article about quantum physics.         ┆ 0.6918241381645203  │
    # ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
    # │ None                                                                     ┆ None                │
    # ╰──────────────────────────────────────────────────────────────────────────┴─────────────────────╯
最近更新时间:2026.01.08 19:14:22
这个页面对您有帮助吗?
有用
有用
无用
无用