Skip to content

Type spans in EncoderDetector.detect and meter the typer #155

Closed

Description

@hslev

Parent: #153 · Epic: #126 · Blocked by: #154, #150
Work on branch 153-get-typed-spans-from-the-encoder; commit the changes and close the ticket.

Problem

A typed call is not metered completely and typed spans don't exist in Detection: the typer's work is invisible in usage, and category/subcategory appear only in the old dicts.

Current behavior

  • Typing happens in the old predict path via TaxonomyTyper.type_spans (taxonomy_head.py:96) after _build_spans_from_tokens (transformer.py:383); context is the sources joined by newline (or the prompt).
  • Detection has no typer usage entry.

Steps

  1. In EncoderDetector._detect, when a typer is set, call it for the spans and fill DetectedSpan.category and subcategory; without a typer both are None. Context: sources joined by "\n" for SourcesInput, the prompt for PromptInput.
  2. Add a second Usage for the typer: its model_id, model_version, unit spans (0 when there are no spans).
  3. adetect on a typed EncoderDetector needs no override: it runs detect, including the typer call, in one worker thread, so the typed result is the same as the sync one.
  4. EncoderDetector.from_pretrained(taxonomy_head=..., include_taxonomy=...) builds the typer through TaxonomyTyper.from_pretrained, all four include_taxonomy forms.
  5. TransformerDetector(taxonomy_head=...) still types spans; output equals the typed golden fixtures from Pin today's TransformerDetector output with golden fixtures #128.

Acceptance criteria

  • With a stub typer every span has category and subcategory; without one both None.
  • await adetect(...) on a typed EncoderDetector equals detect: same category/subcategory on every span and the same two usage entries; the loop stays free while it waits.
  • Two usage entries with a typer, one without; typer entry reports spans = 0 when there are none.
  • Typed golden fixtures and tests/test_custom_taxonomy_pytest.py pass unchanged.
  • Contract suite passes for a typed EncoderDetector; follows CONTRIBUTING "Errors and logging".

Start here

uv run --extra dev pytest tests/test_custom_taxonomy_pytest.py tests/test_golden_transformer_pytest.py -q

Metadata

Metadata

Assignees

No one assigned

    Labels

    ready-for-agent

    Type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions