Repository navigation
feat: add VelaDetector and VelaConfig for in-process Vela 2.0 models (#118) - #193
Conversation
adaamko
left a comment
There was a problem hiding this comment.
@FurkanAtass thanks, this follows the issue closely. I read vela.py and vela_client.py in full and ran the suite on the stacked branch (#194 on top of this): all Vela tests pass. The evaluation note is a good addition.
A few things, the first is the one I'd like settled before merge:
SourcesInputis the weaker path. Your own numbers: the joined prompt gives 0.847 with no failed rows, while question and sources sent separately give 0.830 and 586 of 10,698 rows raiseinput_too_long. A service will mostly calldetectwithSourcesInput, so that path should not be the worse one. CouldSourcesInputbuild the joined prompt (the same textPromptUtils.format_contextgives the encoder) and send it assource, likePromptInputdoes? Then long sources are cut withinput_truncatedinstead of raising. If there is a reason to keeprequestseparate, please say so in the docstring with the numbers.- Undeclared dependencies.
vela_client.pyimportshttpxat module top, anddetectors/__init__.pynow imports it on everyimport lettucedetect.detectors.httpxis only in thedevandapiextras; it works today becauseopenaidepends on it. Please add it to the core dependencies. The same holds forpackaginginvela.py(it comes withtransformerstoday). - Vela's span
labelis dropped. With the default single criterion nothing is lost, but with a customVelaConfig.criteriathe caller cannot tell which criterion a span matched. Putting the label inDetectedSpan.categorywhen the config has more than one criterion would keep it. input_truncatedcan be reported for an input that was not cut, when it fits exactly or when a long answer is scored in windows. Your comment says so. If the reply gives no way to tell, please say it in the warning's docs too, so a service does not alert on it.- Other
ValueErrors of the local model are re-raised as they are. ASystemOneErrorof another type thantoo_longleavesdetectas a plainValueError, not aLettuceDetectError. AnUpstreamErrorwith the codeinvalid_model_output(without the message, in case it quotes the input) would fit the convention.
One note on CI: pull requests against stateless_core only ran the rights check until now. #195 makes the test workflow run on them. Once it is merged, please rebase so the tests run here as well. #195 also makes the arguments of EncoderDetector after tokenizer keyword-only; your code does not call it, so nothing changes for you.
|
@FurkanAtass to make point 1 of my review concrete, this is what I would do:
If neither join gets near 0.847, keeping I don't know whether the dataset's Please also rebase on the current |
71256a4 to
8c06081
Compare
|
@adaamko I've addressed all the points and rebased on the latest I ran the full test set with every row sent as
The dataset's prompt uses the The rest:
|
adaamko
left a comment
There was a problem hiding this comment.
Thanks, all five points are handled and the numbers settle the SourcesInput question: the User request: join matches the joined prompt (0.847) with no failed rows. I read the updated diff and ran the suite on the stacked branch; everything passes, and CI is green here after the rebase. Good to go from my side.
Summary
Adds
VelaDetector, an in-process detector for Vela 2.0 models (#118, pull request 1 of 2). It asks Vela's hallucination span question throughmodel.system_one(...)and returns a typedDetection. It followsEncoderDetector: the constructor takes a loaded model,from_pretrainedloads one, and only_detectis implemented. The HTTP mode and the docs follow in PR 2.Base branch is
stateless_core, notmain. Close #118 by hand after PR 2 merges.Details:
PromptInputis supported. A LettuceDetect prompt is the request plus the context, which is the context format Vela was trained on.request, so they raiseInvalidInputError(input_too_long). A long prompt is cut and getsinput_truncated.from_pretrainedalways setstrust_remote_code=True, takesrevision(the docstrings say to pin it), and records the resolved commit asmodel_version.ConfigurationErrornamingpip install 'lettucedetect[vela]'. The extra addstransformers>=5.17,safetensorsandtokenizers.flash-linear-attentionis left out because it needs CUDA and would break CPU installs.prompt(question and context joined) asPromptInput, the same input the encoder models were evaluated on. That reproduces Vela's score (0.847 vs 0.848) with no rows lost to errors. Sending the question and the context separately (SourcesInput) gives 0.830, and 586 of the 10,698 rows fail withinput_too_long.pyproject.tomladds amodel_downloadpytest marker and skips it by default; run it with-m model_download.scripts/evaluate_span_model.pygains--method velaand--revision; the default staystransformer.Related issue
Relates to #118 (pull request 1 of 2). The HTTP mode and docs follow in PR 2.
This PR targets
stateless_core, notmain, so GitHub will not close the issue automatically. Close it by hand once PR 2 merges.Type of change
Testing
ruff format --check lettucedetect/ lettucedetect_api/ tests/ruff check lettucedetect/ lettucedetect_api/ tests/ --extend-exclude lettucedetect/integrations/python -m pytestpython -m pytest -m model_download tests/test_vela_from_pretrained_pytest.py(real 0.3B model, passes)Results: 99 files already formatted; all checks passed; 772 passed, 1 deselected (the real-model test).
Evaluation:
scripts/evaluate_span_model.py --method velaon the 10,698-example test set gives 0.847 example-F1 (Vela reports 0.848) and 0.707 on RAGTruth (Vela reports 0.706). The command and the per-dataset table are indocs/code-hallucination/results_vela.md.New test files:
tests/test_vela_detector_pytest.py: tests detection, plus the shared contract suite.tests/test_vela_from_pretrained_pytest.py: tests loading the model, plus one real 0.3B test that is skipped by default.Checklist
Rights & sign-off (required)
distributed under the repository's MIT license
(see CONTRIBUTING).