apak commited on
Commit
7e9e826
·
verified ·
1 Parent(s): eb915b6

Update ner_logic.py

Browse files
Files changed (1) hide show
  1. ner_logic.py +16 -7
ner_logic.py CHANGED
@@ -51,13 +51,22 @@ def refine_labels_batch(misc_items, full_sentence):
51
  generated_ids = llm_model.generate(model_inputs.input_ids, max_new_tokens=1500, do_sample=False)
52
  output = tokenizer.batch_decode(generated_ids[:, model_inputs.input_ids.shape[1]:], skip_special_tokens=True)[0]
53
 
54
- json_match = re.search(r'\[\s*\{.*\}\s*\]', output, re.DOTALL)
55
- if json_match:
56
- results = json.loads(json_match.group(0))
57
- for r in results:
58
- if not isinstance(r.get("karar"), str) or r["karar"] in ["True", "False"]:
59
- r["karar"] = "MISC"
60
- return results
 
 
 
 
 
 
61
  return []
 
 
 
62
  except:
63
  return []
 
51
  generated_ids = llm_model.generate(model_inputs.input_ids, max_new_tokens=1500, do_sample=False)
52
  output = tokenizer.batch_decode(generated_ids[:, model_inputs.input_ids.shape[1]:], skip_special_tokens=True)[0]
53
 
54
+ # JSON bloğunu ayıklamak için regex kullan
55
+ json_match = re.search(r'\[.*\]', output, re.DOTALL)
56
+ if json_match:
57
+ raw_json = json_match.group(0)
58
+ # Bazen model son süslü parantezi unutur, basit bir tamamlama denenebilir
59
+ if raw_json.count('{') > raw_json.count('}'):
60
+ raw_json += "}]"
61
+
62
+ results = json.loads(raw_json)
63
+ return results
64
+ else:
65
+ # Hata durumunda log bas ki ne geldiğini görelim
66
+ print(f"LLM Yanlış Format Döndürdü: {output}")
67
  return []
68
+ except Exception as e:
69
+ print(f"Parsing Hatası: {str(e)}")
70
+ return []
71
  except:
72
  return []