英文文本质量评分算子 - 基于FastText的文本质量评估
输入列名 | 说明 |
|---|---|
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 │ # ╰──────────────────────────────────────────────────────────────────────────┴─────────────────────╯