Type spans in EncoderDetector.detect and meter the typer

Aperta
#155 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
54/100
Tipo di issue
Funzionalità
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python, pytorch

Direzione di ricerca

Start with EncoderDetector._detect, EncoderDetector.adetect, EncoderDetector.from_pretrained, and TransformerDetector; the issue also points to taxonomy_head.py:96 and transformer.py:383. Run the listed pytest command first, then trace how spans and usage are built and inspect the typed golden fixtures from #128. Done when typed and untyped outputs, both usage entries, and the stated test suites match the acceptance criteria.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

ready-for-agent

Parent: #153 · Epic: #126 · Blocked by: #154, #150
Branch from stateless_core; open the PR against it.

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 #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
Lingua principale
Python
Stelle
615
Fork
60
Merge medio
1g 8h
PR unite (30g)
10

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di KRLabsOrg/LettuceDetect

Tutte le issue di KRLabsOrg/LettuceDetect

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.