Spaces:
Sleeping
Sleeping
Update ner_logic.py
Browse files- 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 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 []
|