AGENT SKILL

data-preparation

Clean extracted text, stage Unstructured elements for annotation and labeling tools, use lightweight NLP helpers, and prepare local outputs for downstream systems. Route raw partitioning to partitioning, generic element JSON/schema work to elements-and-metadata, provider embeddings to embeddings, and chunk composition to chunking.

License 许可
Apache-2.0
最近更新
2026-09-03
Stars
★ 351
Forks
27

01 前言 Front Matter

name
data-preparation
license
Apache 2.0
metadata
{ "disco-role": "operating" }
description
Clean extracted text, stage Unstructured elements for annotation and labeling tools, use lightweight NLP helpers, and prepare local outputs for downstream systems. Route raw partitioning to partitioning, generic element JSON/schema work to elements-and-metadata, provider embeddings to embeddings, and chunk composition to chunking.
disable-model-invocation
true

02 资源文件 3

03 SKILL.md 正文

Data Preparation

Use this sub-skill when a task starts from text or already-partitioned Unstructured elements and needs local cleanup, annotation export, lightweight tokenization, or preparation for downstream systems. Do not use it to partition raw source files, design embeddings providers, or inspect the full element JSON schema.

Start Here

  • For OCR or PDF-extracted text cleanup, use unstructured.cleaners.core first; these helpers are local and deterministic.
  • For metadata extraction from email-like text or HTML snippets, use unstructured.cleaners.extract regular-expression helpers.
  • For annotation tools, stage existing text elements with unstructured.staging.prodigy, label_studio, label_box, datasaur, baseplate, or huggingface after confirming each target tool's schema.
  • For tokenization and sentence splitting, use unstructured.nlp.tokenize only when the environment can load the spaCy model; first use may install or load model data.
  • Treat translation, Hugging Face tokenizers/models, annotation SaaS APIs, and hosted storage URLs as third-party/service boundaries; require explicit dependencies, network access, and credentials where applicable.

Local Text Cleaning

Use the combined clean() function for simple normalization:

from unstructured.cleaners.core import clean

normalized = clean(
    raw_text,
    extra_whitespace=True,
    dashes=True,
    bullets=True,
    trailing_punctuation=True,
)

Use focused cleaners when order matters or when a single transform is safer:

  • clean_extra_whitespace() collapses newlines, non-breaking spaces, and repeated spaces.
  • clean_bullets() removes a leading Unicode bullet only, preserving bullets elsewhere.
  • clean_ordered_bullets() removes numeric/alphanumeric outline prefixes such as 1.1 when they look like section markers.
  • clean_ligatures() maps common ligatures such as fi and fl to ASCII-style text.
  • replace_unicode_quotes() fixes common mojibake quote/dash sequences; replace_mime_encodings() decodes quoted-printable MIME fragments.
  • clean_prefix() and clean_postfix() remove anchored regex patterns from text edges.

For a safe command-line preview, use the bundled script:

python sub-skills/data-preparation/scripts/clean_text_preview.py --text "●  RISK\u00a0FACTORS---"
python sub-skills/data-preparation/scripts/clean_text_preview.py input.txt --json-output preview.json
python sub-skills/data-preparation/scripts/clean_text_preview.py elements.json --elements-json --max-items 5

The script reads local text or Unstructured element JSON, applies selected local cleaners, and writes a preview. It does not call partition APIs, translation models, hosted services, or annotation APIs.

Extraction Helpers

Use unstructured.cleaners.extract for lightweight pattern extraction:

from unstructured.cleaners.extract import extract_email_address, extract_text_after

emails = extract_email_address(header_text)
body = extract_text_after(raw_email, r"\n\n", index=0)

Common helpers include extract_email_address(), extract_ip_address(), extract_ip_address_name(), extract_mapi_id(), extract_datetimetz(), extract_us_phone_number(), extract_ordered_bullets(), and extract_image_urls_from_html(). extract_text_before() and extract_text_after() raise ValueError if the requested match index does not exist; catch that when patterns are optional.

Annotation Staging Routes

Work from Text-like elements (Title, NarrativeText, Text, etc.) whenever an annotation target expects plain text examples:

from unstructured.staging.prodigy import stage_for_prodigy

records = stage_for_prodigy(elements, metadata=[{"source": "batch-a"} for _ in elements])
  • Prodigy: stage_for_prodigy() emits JSON-like records with text and meta; stage_csv_for_prodigy() emits CSV. Do not pass an id key in metadata because element ids are injected into meta.id.
  • Label Studio: stage_for_label_studio() emits task dictionaries under data; optional annotations/predictions must match element count. LabelStudioResult.type must be one of the module's supported label types, and prediction score must be between 0 and 1. This function is deprecated in the package, so prefer validating against current Label Studio tooling before production use.
  • Labelbox: stage_for_label_box() writes one text file per element and returns import config with data URLs. It requires an output directory and a URL prefix where those files will be hosted; attachment type must be IMAGE, VIDEO, RAW_TEXT, TEXT_URL, or HTML.
  • Datasaur: stage_for_datasaur() emits text plus entities; each entity requires text, type, start_idx, and end_idx, and the entity list length must match the elements length.
  • Baseplate: stage_for_baseplate() flattens element dictionaries into rows with data and metadata fields suitable for API upload payloads.
  • Hugging Face/transformers: stage_for_transformers() and chunk_by_attention_window() split long text to fit a provided tokenizer's attention window. This requires a tokenizer object and the transformers dependency.

See references/cleaning-and-staging.md for schema examples and references/troubleshooting.md for common validation failures.

NLP and Translation Boundaries

unstructured.nlp.tokenize.sent_tokenize(), word_tokenize(), and pos_tag() use spaCy under the hood with caching. They may load or install a pinned en_core_web_sm model on first use, so do not assume they are zero-dependency helpers in locked-down or offline environments.

unstructured.cleaners.translate.translate_text() uses langdetect, transformers, Marian tokenizer/model loading, and Hugging Face model names such as Helsinki-NLP/opus-mt-de-en. It returns unchanged text when the source and target language are the same or when text is blank, but actual translation can require large model downloads, network access, and supported source/target language pairs. Ask before enabling it in offline, credential-sensitive, or latency-sensitive workflows.

Boundaries

  • Raw document partitioning and document-specific parser options belong to partitioning.
  • Element schema inspection, generic JSON/NDJSON/Markdown/Text conversion, metadata coordinates, and table fidelity belong to elements-and-metadata.
  • Chunk construction with chunk_elements() or chunk_by_title() belongs to chunking; this sub-skill only covers Hugging Face attention-window staging.
  • Provider embeddings, embedding interfaces, and vector output preparation belong to embeddings.
  • Review/test artifacts do not belong in this runtime subtree.

Evidence

This sub-skill is grounded in the package cleaner, staging, and NLP helper modules plus their behavior tests.

04 同仓库更多 Skills

VectorSpaceLab
VectorSpaceLab/AREX-Skill

passnet-triton-opt

Make a single PassNet Triton kernel fast AND numerically faithful: performance model (when a replacement can win at all), block/grid/warp tuning, autotune policy, launch overhead, and per-op numeric recipes to pass the dtype baseline tolerances. Use when a pass matches and is correct but speedup below expected, or when correctness fails by small numeric margins.

★ 351
VectorSpaceLab
VectorSpaceLab/AREX-Skill

passnet-solve

END-TO-END playbook for solving one PassNet sample: analyze the computation graphs, decide the optimization strategy (what to fuse, what to replace, what to leave alone), drive the iteration loop, and maximize the sample score. This is the ENTRY skill — invoke it first for any PassNet optimization task; it tells you when to use passnet-pattern-fusion, passnet-triton-opt and passnet-feedback.

★ 351
VectorSpaceLab
VectorSpaceLab/AREX-Skill

passnet-skill

PassNet GPU kernel optimization via compiler passes. Design and implement Triton-based optimization passes, create pass files under ./pass_dir/, self-evaluate with pass_evaluator, and iterate to maximize GPU speedup.

★ 351
VectorSpaceLab
VectorSpaceLab/AREX-Skill

passnet-pattern-fusion

Author PassNet pass files: write patterns that actually MATCH the FX graph, pick fusion regions (which ops to absorb into one Triton kernel), and structure multi-pass submissions with the mandatory shared-dispatch architecture. Use when creating or fixing pattern()/replacement_args()/replacement_func() files, when a pass "failed to match", or when deciding how to fuse multiple kernels/ops.

★ 351
VectorSpaceLab
VectorSpaceLab/AREX-Skill

passnet-orchestrate

Round/batch planning and decision support for PassNet graph optimization. Use for multi-sample triage, worker allocation, eval-budget policy, and post-eval keep/revert decisions. For solving one concrete sample end to end, use passnet-solve as the entry skill; consult this skill only when you need broader planning or a specific decision gate.

★ 351
VectorSpaceLab
VectorSpaceLab/AREX-Skill

passnet-feedback

Fast, deterministic feedback for PassNet work: pre-flight pattern/match verification WITHOUT burning a GPU evaluation, per-node bottleneck analysis of a sample's graphs, and eval-log parsing into per-variant status + estimated score + failure classification. Use BEFORE every GPU evaluation (check_pattern), at the START of a sample (analyze_graph), and AFTER every evaluation (parse_eval_log).

★ 351