bug ai_json_move_to_index

This commit is contained in:
hsafaei
2025-09-30 09:55:33 +03:30
parent 7140efa3f0
commit d8821c6678
2 changed files with 110 additions and 59 deletions
+95 -48
View File
@@ -134,73 +134,101 @@ def moveSimplifies(elastic, index_name_o, data):
def moveClassifierAiCodes(elastic, index_name_o, data): def moveClassifierAiCodes(elastic, index_name_o, data, version_key = "D51_v1"):
text_normal = TextNormalizer() text_normal = TextNormalizer()
index = 0 index = 0
percent_prev = 0 percent_prev = 0
send_round = 1 send_round = 1
list_bulk=[] list_bulk=[]
for item in data: best_code = {}
index += 1 other_codes = []
percent = int((index / len(data)) * 100) eid = 0
if percent != percent_prev: try:
print("progress -> %.2f %%" % percent) for item in data:
percent_prev = percent index += 1
percent = int((index / len(data)) * 100)
if percent != percent_prev:
print("progress -> %.2f %%" % percent)
percent_prev = percent
id = item eid = item
best_code = data[item]['best-class'] best_code = data[item]['best-class']
other_codes = data[item]['other-classes'] other_codes = data[item]['other-classes']
ai_code = best_code
ai_codes = other_codes
ai_code = best_code history_codes = []
ai_codes = other_codes try:
item = elastic.get_doctument(index_name_o, eid)
history_codes = item.get("_source", {}).get("history_codes", [])
except Exception as e:
continue
#----------------------------------------------
for label_doc in ai_codes:
label = text_normal.normalize_qanon(label_doc["label"])
label_doc["label"] = label
if label_doc["score"] >= 1 :
label_doc["score"] = label_doc["score"] / 100
#---------------------------------------------- history_codes.append({
for label_doc in ai_codes: "version_key": version_key,
label = text_normal.normalize_qanon(label_doc["label"]) "sub_key": "sub",
label_doc["label"] = label "label": text_normal.normalize_qanon(label_doc['label']),
if label_doc["score"] >= 1 : "score": label_doc['score'],
label_doc["score"] = label_doc["score"] / 100 })
if ai_code["score"] >= 1 : if ai_code :
ai_code["score"] = ai_code["score"] / 100 if ai_code["score"] >= 1 :
ai_code["score"] = ai_code["score"] / 100
label = ai_code["label"] label = ai_code["label"]
label = text_normal.normalize_qanon(ai_code["label"]) label = text_normal.normalize_qanon(ai_code["label"])
ai_code["label"] = label ai_code["label"] = label
#---------------------------------------------- history_codes.append({
"version_key": version_key,
"sub_key": "main",
"label": text_normal.normalize_qanon(ai_code['label']),
"score": ai_code['score'],
})
#----------------------------------------------
list_bulk.append({ list_bulk.append({
'_id': id, '_id': eid,
'_source': { '_source': {
"ai_code" : ai_code, "ai_code" : ai_code,
"ai_codes" : ai_codes "ai_codes" : ai_codes,
} "history_codes": history_codes
}) }
})
if len(list_bulk) > 200 : if len(list_bulk) > 200 :
elastic.updateBulkList(list_bulk, index_name_o) elastic.updateBulkList(list_bulk, index_name_o)
list_bulk = [] list_bulk = []
# print(f"send_round -> {send_round}") # print(f"send_round -> {send_round}")
send_round += 1 send_round += 1
except Exception as e:
print("error ---> ", str(e))
print("index, id ", index, eid)
if len(list_bulk) : if len(list_bulk) :
elastic.updateBulkList(list_bulk, index_name_o) elastic.updateBulkList(list_bulk, index_name_o)
# print(f"last ::: send_round -> {send_round}") print(f"last ::: send_round -> {len(list_bulk)}")
load_dotenv(dotenv_path='config.env') load_dotenv(dotenv_path='config.env')
# host=os.getenv('HOST_160') host=os.getenv('HOST_160')
# password=os.getenv('HOST_160_PASS') password=os.getenv('HOST_160_PASS')
# host=os.getenv('HOST_112') # host=os.getenv('HOST_112')
# password=os.getenv('HOST_112_PASS') # password=os.getenv('HOST_112_PASS')
host=os.getenv('HOST_113') # host=os.getenv('HOST_113')
password=os.getenv('HOST_113_PASS') # password=os.getenv('HOST_113_PASS')
# host=os.getenv('HOST_60') # host=os.getenv('HOST_60')
# password=os.getenv('HOST_60_PASS') # password=os.getenv('HOST_60_PASS')
@@ -213,27 +241,46 @@ path_base_map = "G:/Project2/gateway2_main/repo/_other/"
elastic = ElasticHelper(host, password, "elastic", path_base_map) elastic = ElasticHelper(host, password, "elastic", path_base_map)
#---------------------------
#مرحله اول در بهار 1404
#برای کدهای 54 گانه
#در دو بخش تحویل داده شد
# moveKeywords(elastic,"mj_qa_section", "data/sections_kw_llama8b_170k_concatenated.json") # moveKeywords(elastic,"mj_qa_section", "data/sections_kw_llama8b_170k_concatenated.json")
# moveKeywords(elastic,"mj_qa_section", "data/sections_kw_llama8b_40k_concatenated.json") # moveKeywords(elastic,"mj_qa_section", "data/sections_kw_llama8b_40k_concatenated.json")
#---------------------------
# moveZipSimplifies(elastic,"mj_qa_section", "G:\Work\_majles\_data\simpilified_final.zip") # moveZipSimplifies(elastic,"mj_qa_section", "G:\Work\_majles\_data\simpilified_final.zip")
#---------------------------
# کدهای 51 گانه ولی آموزش دیده با 60 هزار دیتاست بسیار ضعیف
# لذا خطا داشت و زود جایگزین شد
#-----نسخه قبلی اجرای مدل #-----نسخه قبلی اجرای مدل
# with open("./data/all_sections_classes.json", "r", encoding="utf-8") as f: # with open("./data/all_sections_classes.json", "r", encoding="utf-8") as f:
# classes = json.load(f) # classes = json.load(f)
#---------------------------
#---------------------------
# کدهای 51 گانه، آموزش دیده با حدود 2500 دیتاست خبرگانی خوب
#-----نسخه آخر اجرای مدل #-----نسخه آخر اجرای مدل
# with open("./data/all_sections_classes_full_140405.json", "r", encoding="utf-8") as f: # with open("./data/all_sections_classes_full_140405.json", "r", encoding="utf-8") as f:
# classes = json.load(f) # classes = json.load(f)
# moveClassifierAiCodes(elastic,"mj_qa_section", classes)
# print('finished!')
#-----داده های جدید نسخه آخر اجرای مدل #---#-----داده های جدید نسخه
with open("./data/all_sections_classes_new_140406.json", "r", encoding="utf-8") as f: #with open("./data/all_sections_classes_new_140406.json", "r", encoding="utf-8") as f:
classes = json.load(f) # classes = json.load(f)
moveClassifierAiCodes(elastic,"mj_qa_section", classes) # moveClassifierAiCodes(elastic,"mj_qa_section", classes, "D51_v1")
#---------------------------
#---------------------------
# کدهای 49 گانه آموزش دیده با دیتاست خوب حدود15 الی 20 هزارتایی که با کمک فایلهای تبیین مفهومی و مدلهای زبانی به دست آمد
with open("./data/all_sections_classes_full_140407.json", "r", encoding="utf-8") as f:
classes = json.load(f)
moveClassifierAiCodes(elastic,"mj_qa_section", classes, "D49_v1")
print('finished!') print('finished!')
+9 -5
View File
@@ -11,8 +11,8 @@ from app.temp_refactor_gn_dataset import *
load_dotenv(dotenv_path="config.env") load_dotenv(dotenv_path="config.env")
host = os.getenv("HOST_160") # host = os.getenv("HOST_160")
password = os.getenv("HOST_160_PASS") # password = os.getenv("HOST_160_PASS")
# host=os.getenv('HOST_112') # host=os.getenv('HOST_112')
# password=os.getenv('HOST_112_PASS') # password=os.getenv('HOST_112_PASS')
@@ -23,8 +23,8 @@ password = os.getenv("HOST_160_PASS")
# host=os.getenv('HOST_118') # host=os.getenv('HOST_118')
# password=os.getenv('HOST_118_PASS') # password=os.getenv('HOST_118_PASS')
# host=os.getenv('HOST_60') host=os.getenv('HOST_60')
# password=os.getenv('HOST_60_PASS') password=os.getenv('HOST_60_PASS')
# host=os.getenv('HOST_161') # host=os.getenv('HOST_161')
# password=os.getenv('HOST_161_PASS') # password=os.getenv('HOST_161_PASS')
@@ -45,9 +45,13 @@ elastic = ElasticHelper(host, password, "elastic", path_base_map)
# elastic.backupIndexToZipfile("G:/Project2/111/haditha", "dh_volume") # elastic.backupIndexToZipfile("G:/Project2/111/haditha", "dh_volume")
# elastic.backupIndexToZipfile("G:/Project2/111/haditha", "dh_haditha") # elastic.backupIndexToZipfile("G:/Project2/111/haditha", "dh_haditha")
# elastic.backupIndexToZipfile("G:/Project2/111", "mn_spr_sanad")
# elastic.createIndex( 'mn_spr_sanad', 'monir', 'mn_spr_sanad')
elastic.restorFileToElastic2('G:/Project2/111/mn_spr_sanad.zip', 'mn_spr_sanad', 'monir', False, 'mn_spr_sanad')
# elastic.backupIndexToZipfile("G:/Project2/111", "mj_qa_domain") # elastic.backupIndexToZipfile("G:/Project2/111", "mj_qa_domain")
# elastic.createIndex( 'mj_qa_domain', 'majles', 'mj_domain') # elastic.createIndex( 'mj_qa_domain', 'majles', 'mj_domain')
# elastic.restorFileToElastic2('G:/Project2/111/mj_qa_domain.zip', 'mj_qa_domain', 'majles', False, 'mj_domain') # elastic.restorFileToElastic2('G:/Project2/111/mj_qa_domain_base1.zip', 'mj_qa_domain', 'majles', False, 'mj_qa_domain')
# elastic.backupIndexToZipfile("G:/Project2/111", "mj_qa_section-m1") # elastic.backupIndexToZipfile("G:/Project2/111", "mj_qa_section-m1")