Add EncoderDetector and EncoderConfig with detect spans
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
- 45/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Ambito
- backend, machine-learning, testing
Direzione di ricerca
Start with lettucedetect/detectors/transformer.py:28-83 and the scoring methods at :84, :241, :341, and :383; run uv run --extra dev pytest tests/test_inference_pytest.py -q. Then review the #128 golden span output, the #143 contract suite, and the local_wordpiece_tokenizer fixture. Done means the new detector passes those contracts, configuration errors carry the specified codes and parameters, and the concurrency tests confirm per-instance serialization and a single lock under racing first calls.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Parent: #148 · Epic: #126 · Blocked by: #128, #143
Branch from stateless_core; open the PR against it.
Problem
TransformerDetector.__init__ downloads the tokenizer and model inside the constructor, so a service cannot build a detector from objects it already holds, and every option is a keyword whose conflicts are checked at runtime.
Current behavior
lettucedetect/detectors/transformer.py:28-83constructor:batch_size < 1raisesValueError(:58),AutoTokenizer.from_pretrained(:62),AutoModelForTokenClassification.from_pretrained(:63).- Scoring:
_predict_single(:241),_predict_chunked(:341,max()over passage groups),_group_passages_into_chunks(:84),_build_spans_from_tokens(:383). - Spans carry
confidence; noscore,usageorwarnings.
Steps
- Add
EncoderConfig(frozen pydantic,extra="forbid"):max_length=4096,batch_size=16,lang="en". Unknown option →ConfigurationError(invalid_config); unknown language →invalid_language;batch_size < 1→invalid_batch_size; each withparam. - Add
EncoderDetector(model, tokenizer, typer=None, *, config=None, model_id=None, model_version=None). It downloads nothing, reads no environment variable, writes no file. - Implement
_detectforSourcesInputandPromptInputby moving the scoring code (private method names stay) behind it.scoreis the maximum token probability of the span;textequals the answer between offsets. - Plug into the #143 contract suite with a stub model and the
local_wordpiece_tokenizerfixture. - Guard the scoring path with one private
threading.RLock:_detecttakes it around tokenizing, the forward pass and aggregation, so concurrentdetectandadetectcalls on one instance run one at a time. Reason:transformersrewrites the fast tokenizer's truncation and padding settings on every call, so concurrent calls on one tokenizer can return wrong tokens or raiseValueError(reproduced locally by forcing thread switches; rare at default interpreter settings), and threads sharing one model gain little on a CPU or GPU. It is anRLockso thatdetect_batch(#177) can fall back to the single-request path while it holds the lock. The lock is created on first use by a private helper, not in__init__, because a detector built with__new__and its attributes set by hand never runs__init__(story 56); a module-level guard lock makes two racing first calls get the same lock. No config field and no public argument. The private scoring methods that existing tests patch don't take the lock themselves. - Add the two concurrency tests below.
Acceptance criteria
- Constructing with a stub model offline in an empty cwd succeeds and leaves it empty.
-
detect/adetectspans equal the #128 golden"spans"output for the same inputs, withscore= oldconfidence; multi-group sources are aggregated withmax()as today. -
await adetect(...)equalsdetectfor both request kinds (the model call runs inadetect's worker thread; no override). -
asyncio.gatherover at least 16adetectcalls with different inputs on oneEncoderDetector(stub model, the reallocal_wordpiece_tokenizerfixture, inputs long enough to truncate and pad) returns each call's own result, equal to the same inputs run one by one withdetect, and a stub model that records entries and exits shows no two scoring calls overlapping. - Racing first calls from several threads (released together by a barrier) on a detector built with
__new__and its attributes set by hand create exactly one lock. - Config errors carry the listed codes and
param. -
EncoderDetectorpasses the contract suite. - Existing tests pass; follows CONTRIBUTING "Errors and logging".
Start here
uv run --extra dev pytest tests/test_inference_pytest.py -q
- Lingua principale
- Python
- Stelle
- 615
- Fork
- 60
- Merge medio
- 1g 8h
- PR unite (30g)
- 10
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di KRLabsOrg/LettuceDetect
-
Stop-hook --min-confidence drops every --llm-model span (missing confidence treated as 0.0), reporting hallucinated answers as cleanForse già presa @Clannad47 l’ha presa 17 giorni fa. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
KRLabsOrg/LettuceDetect#117 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
enhancement
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
KRLabsOrg/LettuceDetect#108 ·
I maintainer di solito rispondono entro 1 giorno
-
Add AGENTS.md: one entry file for coding agents and new contributorsForse già presa @ShryukGrandhi l’ha presa 18 giorni fa. Apertadocumentation
Difficoltà 2/5 Mezza giornata Idoneità per principianti 70/100
KRLabsOrg/LettuceDetect#104 ·
I maintainer di solito rispondono entro 1 giorno
-
ready-for-agent
Difficoltà 3/5 1-2 giorni Idoneità per principianti 68/100
KRLabsOrg/LettuceDetect#181 ·
I maintainer di solito rispondono entro 1 giorno
-
ready-for-agent
Difficoltà 5/5 Più di una settimana Idoneità per principianti 22/100
KRLabsOrg/LettuceDetect#180 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di KRLabsOrg/LettuceDetect
Issue simili
-
integration: logger
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
home-assistant/core#191147 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 1 giorno
-
documentation p4
Difficoltà 1/5 1-3 ore Idoneità per principianti 88/100
MillenniumDawn/focus-tree-creation-tool#417 ·
I maintainer di solito rispondono entro 3 giorni
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
CharlesP44/Beem_Energy#96 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
rheeloaded/paperpull#153 ·
I maintainer di solito rispondono entro 1 giorno