You need to enable JavaScript to run this app.
Lake AI Service

Lake AI Service

Copy page
Download PDF
Text classification
Language identification for text
Copy page
Download PDF
Language identification for text

Operator introduction

Description

Language identification operator for text – provides multilingual identification capabilities based on the FastText model

Key features

  • Supports identification of 176 languages (based on the fasttext/lid.176 series models)
  • Optimized for batch inference, suitable for processing large-scale text data
  • Supports simultaneous output of language labels and confidence scores
  • Supports model files from local paths and TOS paths

Application scenarios

  • Multilingual text classification
  • Language filtering and selection
  • Multilingual dataset construction

Recommendations

  • It is recommended that the input text length be at least 10 characters to improve identification accuracy
  • At least 4GB of memory is required for batch inference with the model

Invoking Daft

Operator parameters

Input

Input column name

Note

texts

Original string column; element type must be string

Output

Struct column containing language labels and confidence scores
Each element contains the fields language and confidence

Parameters

If a parameter does not have a default value, it is required

Parameter name

Type

Default value

Description

model_path

str

/opt/las/models

Path where the model files are located. Default value: "/opt/las/models"

model_name

str

fasttext/lid.176.bin

Model file name; supports "fasttext/lid.176.bin" or "fasttext/lid.176.ftz"

batch_size

int

1000

Batch processing size; a larger batch_size can improve throughput but increases memory consumption

Examples

The following code demonstrates how to use Daft to identify the language of text using the operator.

from __future__ import annotations

import os

import daft
from daft import col
from daft.las.functions.text.language_recognition import LanguageRecognitionOperator
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.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 test content.",
            "This is a test content.这是一行测试内容。",
            "こんにちは",
            "안녕하세요",
        ]
    }

    ds = daft.from_pydict(samples)
    ds = ds.with_column(
        "language_result",
        las_udf(
            LanguageRecognitionOperator,
            construct_args={
                "model_path": os.getenv("MODEL_PATH", "/opt/las/models"),
                "model_name": "fasttext/lid.176.bin",
                "batch_size": 1000,
            },
        )(col("text")),
    )

    ds.show()
    # ╭──────────────────────────────────────┬─────────────────────────────────────────────╮
    # │ text                                 ┆ language_result                             │
    # │ ---                                  ┆ ---                                         │
    # │ Utf8                                 ┆ Struct[language: Utf8, confidence: Float64] │
    # ╞══════════════════════════════════════╪═════════════════════════════════════════════╡
    # │ 这是一行测试内容。                    ┆ {language: zh, confidence: 1.000048279762268} │
    # │ This is a test content. ┆ {language: en, confidence: 0.9209088683128357} │
    # │ This is a test content.这是一行测试… ┆ {language: zh, confidence: 0.6892356276512146} │
    # │ こんにちは                           ┆ {language: ja, confidence: 1.0000269412994385} │
    # │ 안녕하세요                           ┆ {language: ko, confidence: 0.9996028542518616} │
    # ╰──────────────────────────────────────┴─────────────────────────────────────────────╯
Last updated: 2026.05.12 19:06:31