Load an EncoderDetector explicitly and call detect
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 25/100
- Tipo de issue
- Nueva funcionalidad
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Área
- backend, machine-learning
Línea de trabajo
Start by reading the parent issue #126 and the blocked issues #127 and #140, then inspect the existing TransformerDetector and its tests for the named predict methods and golden fixtures. Implement the EncoderDetector API, config validation, loading, scoring, truncation warnings, usage records, and thread-safe async behavior while preserving the compatibility requirements. Done means the acceptance criteria pass, including the detector contract suite and existing tests.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Parent
#126
Branch
Branch from stateless_core and open the pull request against it, not main. Close this ticket by hand once its pull request merges there: GitHub only closes issues automatically on merges into main.
What to build
A service developer loads the fine-tuned encoder once at startup with EncoderDetector.from_pretrained, or builds EncoderDetector from a model and tokenizer it already holds, and then calls detect and adetect with a SourcesInput or a PromptInput. The result is a Detection with scored spans, optional token scores, a usage record naming the exact weights, and a warning when the input was cut to fit max_length.
TransformerDetector becomes a deprecated subclass of EncoderDetector, so there is one implementation, and today's predict* output, attributes and private method names stay as they are. Typed spans (the TaxonomyTyper) and batch methods come in later tasks; until then TransformerDetector with taxonomy_head still loads its typer as today and predict_prompt_batch is unchanged.
Acceptance criteria
-
EncoderDetector(model, tokenizer, typer=None, *, config=None, model_id=None, model_version=None)downloads nothing, reads no environment variable and writes no file: constructing it with a stub model under offline settings in an empty working directory succeeds and leaves the directory empty. -
EncoderConfighasmax_length=4096,batch_size=16andlang="en". An unknown option raisesConfigurationError(invalid_config), an unknown language raises it withinvalid_language, and abatch_sizebelow 1 raises it withinvalid_batch_size, each with itsparam. -
EncoderDetector.from_pretrained(model_id, *, device=None, taxonomy_head=None, include_taxonomy=True, model_version=None, config=None, **loader_kwargs)loads the tokenizer and the model and logsmodel_loaded.model_versionis the resolved Hugging Face commit; for a local path it is the caller'smodel_version, orNonewhen none is given. (taxonomy_headis accepted but typed spans are task #153.) -
detectandadetectaccept aSourcesInputand aPromptInputand return aDetectionwhose spans equal today'spredict(output_format="spans")andpredict_prompt(output_format="spans")output for the same input (golden fixtures), withscoreequal to today'sconfidenceandtextequal to the answer between the offsets. Sources that don't fit are scored in passage groups and aggregated withmax(), as today. -
include_tokens=TruereturnstokensasTokenScoreitems (token text, offsets into the answer,score,flagged) with the same tokens and probabilities as today's"tokens"output; the tokens are not filtered bymin_score. - When the tokenized prompt and answer exceed
max_length, or a passage group still exceeds it, theDetectionhas the warninginput_truncated, and a WARNING record with its code and the token counts is logged (never the text). -
usagehas one entry withmodel_id,model_versionand the unitssources(omitted for aPromptInput),source_chars,answer_charsandinput_tokens. -
EncoderDetectorpasses the detector contract suite from task #140. -
EncoderDetectorholds one privatethreading.RLock, created on first use under a module-level guard lock (not in__init__), around its whole scoring path, with no config field.asyncio.gatherover manyadetectcalls with different inputs on one detector, using the real offline tokenizer fromconftest.py, returns each call's own result, equal to a sequentialdetect, and a stub model shows no two scoring calls overlapping. -
TransformerDetector(model_path=..., max_length, device, lang, taxonomy_head, include_taxonomy, batch_size, **tok_kwargs)is a subclass ofEncoderDetector, warnsLettuceDetectDeprecationWarningnamingEncoderDetector.from_pretrained, keeps its attributes (model,tokenizer,device,max_length,lang,batch_size,typer) and its private method names, and itspredictandpredict_promptoutput equals the golden fixtures. -
TransformerDetectoralso exposesdetectandadetect(inherited), returning a result equal to anEncoderDetectorbuilt from the same model, with no warning beyond the one at construction. - A
TransformerDetectorcreated with__new__and onlymodel,tokenizer,device,max_length,langandtyperset by hand still answerspredictwith spans. - A
TransformerDetectorcreated with__new__answers concurrent calls too: racing first calls create exactly one lock. - The existing tests pass unchanged.
- The changed code follows the Errors and logging section of
CONTRIBUTING.md, and no customer text is logged outsidelettucedetect.content.
Blocked by
#127, #140
User stories covered
3, 4, 5, 7, 12, 15, 16, 18, 25, 34, 40, 47, 56, 57
- Lenguaje dominante
- Python
- Estrellas
- 615
- Forks
- 60
- Merge medio
- 2 d 18 h
- PR fusionados (30 d)
- 12
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de KRLabsOrg/LettuceDetect
-
enhancement
Dificultad 1/5 Menos de una hora Aptitud para principiantes 85/100
KRLabsOrg/LettuceDetect#108 ·
Los mantenedores suelen responder en 1 día
-
documentation
Dificultad 2/5 Medio día Aptitud para principiantes 70/100
KRLabsOrg/LettuceDetect#104 ·
Los mantenedores suelen responder en 1 día
-
Bugs: One typed detect interface for the detectors packagePosiblemente ocupada @hslev la tomó hace 1 día. Abierto
KRLabsOrg/LettuceDetect#192 · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
ready-for-agent
Dificultad 3/5 1-2 días Aptitud para principiantes 68/100
KRLabsOrg/LettuceDetect#181 ·
Los mantenedores suelen responder en 1 día
-
ready-for-agent
Dificultad 5/5 Más de una semana Aptitud para principiantes 22/100
KRLabsOrg/LettuceDetect#180 ·
Los mantenedores suelen responder en 1 día
Todos los issues de KRLabsOrg/LettuceDetect
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
django-cms/djangocms-frontend#413 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
NanmiCoder/MediaCrawler#1004 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
facebookresearch/xformers#1417 ·
-
question
Dificultad 1/5 Menos de una hora Aptitud para principiantes 68/100
vllm-project/vime#524 ·
Los mantenedores suelen responder en 7 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 73/100
FinanceFlash/unvibecode#675 ·
Los mantenedores suelen responder en 1 día