src.dackar.RCA.ner.hybrid_ner.llm_disambiguator¶
Classes¶
Module Contents¶
- class src.dackar.RCA.ner.hybrid_ner.llm_disambiguator.LLMDisambiguator(schema, config=LLMConfig())[source]¶
- Parameters:
config (LLMConfig)
- should_call(c)[source]¶
Decide whether to invoke the LLM for this candidate span.
Decision logic (in priority order): 1. High-confidence gazetteer hit exists → bypass LLM entirely (trust deterministic match). 2. No proposed labels at all → ask LLM (span has no evidence). 3. All hypotheses lack a known schema group → ask LLM (labels are unrecognised). 4. Multiple competing schema groups → ask LLM (genuine ambiguity). 5. Best score in the uncertain confidence band → ask LLM (embed result is marginal). 6. Best score below the floor → do NOT ask LLM (span is too weak; LLM would speculate). 7. Best score above the ceiling → do NOT ask LLM (embed is confident enough).
- Parameters:
- Return type:
bool
- _build_prompt(doc_text, c, candidate_labels)[source]¶
- Parameters:
doc_text (str)
candidate_labels (List[str])
- Return type:
str
- _extract_json_object(s)[source]¶
Some models occasionally wrap JSON with extra text. Try to recover the first {…} object.
- Parameters:
s (str)
- Return type:
Optional[Dict[str, Any]]
- disambiguate(doc_text, candidates)[source]¶
- Parameters:
doc_text (str)
candidates (List[src.dackar.RCA.ner.hybrid_ner.models.CandidateSpan])
- Return type:
None
- _call_llm_for_candidate(doc_text, c)[source]¶
- Parameters:
doc_text (str)
- Return type:
Optional[Dict[str, Any]]
- _parse_llm_response(resp, c)[source]¶
- Parameters:
resp (Any)
- Return type:
Optional[src.dackar.RCA.ner.hybrid_ner.models.LabelHypothesis]