From acaa416fc5fc5942ec0a34d2690b3341f10b9e2a Mon Sep 17 00:00:00 2001 From: thomas Date: Tue, 26 Nov 2024 08:35:35 +0100 Subject: [PATCH] removing "false positives" in ano_llm --- src/utils/ano_llm.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/utils/ano_llm.py b/src/utils/ano_llm.py index 45f9421..9cd4ca8 100644 --- a/src/utils/ano_llm.py +++ b/src/utils/ano_llm.py @@ -100,6 +100,8 @@ def find_entities(text, model=OLLAMA_MODEL, temperature=0.1, template=TEMPLATE, return result result = {k: {'matches': (m:=sorted(list(set(v)), key=len, reverse=True)), 'replacement': m[0]} for k, v in json.loads(result.strip()).items() if len(v) > 0} + result = {k: {'matches': m, 'replacement': v.get('replacement')} for k, v in result.items() + if len(m:=[i for i in v.get('matches') if text.find(i) >= 0]) > 0} for k, v in result.items(): text = text.replace(v.get('replacement'), k) return {'text': text, 'replace_dict': result}