Add token scores, input_truncated and usage to EncoderDetector

Cerrado
#150 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
55/100
Tipo de issue
Nueva funcionalidad
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
python, pytorch

Línea de trabajo

Start with transformer.py at _decode_sample, _predict_single, the batch and predict_prompt truncation paths, and the passage-group path; run the focused pytest command in the issue. Compare token results with the #128 golden output and check usage and truncation behavior, including a log-capture test that verifies counts without input text. The issue is blocked by #149 and asks for a branch from stateless_core.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

ready-for-agent

Parent: #148 · Epic: #126 · Blocked by: #149
Branch from stateless_core; open the PR against it.

Problem

The encoder can show token-level evidence only through the output_format="tokens" dict path, truncation is only logged (and not at all when a passage group still exceeds max_length), and nothing reports which weights ran or how much work a call did.

Current behavior

  • Tokens: transformer.py:163 _decode_sample, :241 _predict_single with output_format="tokens" (pred, prob keys).
  • Truncation warnings: transformer.py:319-322 (batch path, text-free but only logged) and :511-521 (predict_prompt, only logged). The passage-group path (:105-125) logs nothing when a group still exceeds max_length.
  • No usage.

Steps

  1. include_tokens=True (set supports_tokens = True) returns Detection.tokens as TokenScore (token text, offsets into the answer, score = model probability, flagged = old pred). Same tokens and probabilities as the old "tokens" output; not filtered by min_score; aggregated over passage groups with max().
  2. When the tokenized prompt + answer exceed max_length, or a group still exceeds it, add the warning input_truncated to the Detection and log a WARNING with the code and token counts (never text).
  3. Add usage: one entry with model_id, model_version, units sources (omitted for PromptInput), source_chars, answer_chars, input_tokens (summed over passage groups).

Acceptance criteria

  • Tokens equal the #128 golden "tokens" output field for field (pred→flagged, prob→score).
  • A too-long input yields input_truncated; a log-capture test shows the code and counts and no input text.
  • usage has the listed units; sources absent for PromptInput.
  • Contract suite still passes; existing tests pass; follows CONTRIBUTING "Errors and logging".

Start here

uv run --extra dev pytest tests/test_inference_pytest.py -q -k "truncat or token"
Lenguaje dominante
Python
Estrellas
615
Forks
60
Merge medio
2 d 18 h
PR fusionados (30 d)
12

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de KRLabsOrg/LettuceDetect

Todos los issues de KRLabsOrg/LettuceDetect

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.