This commit is contained in:
Legimmort
2025-09-30 10:11:03 +03:30
2 changed files with 110 additions and 59 deletions
+63 -16
View File
@@ -134,12 +134,16 @@ 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()
index = 0
percent_prev = 0
send_round = 1
list_bulk=[]
best_code = {}
other_codes = []
eid = 0
try:
for item in data:
index += 1
percent = int((index / len(data)) * 100)
@@ -147,14 +151,19 @@ def moveClassifierAiCodes(elastic, index_name_o, data):
print("progress -> %.2f %%" % percent)
percent_prev = percent
id = item
eid = item
best_code = data[item]['best-class']
other_codes = data[item]['other-classes']
ai_code = best_code
ai_codes = other_codes
history_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"])
@@ -162,19 +171,34 @@ def moveClassifierAiCodes(elastic, index_name_o, data):
if label_doc["score"] >= 1 :
label_doc["score"] = label_doc["score"] / 100
history_codes.append({
"version_key": version_key,
"sub_key": "sub",
"label": text_normal.normalize_qanon(label_doc['label']),
"score": label_doc['score'],
})
if ai_code :
if ai_code["score"] >= 1 :
ai_code["score"] = ai_code["score"] / 100
label = ai_code["label"]
label = text_normal.normalize_qanon(ai_code["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({
'_id': id,
'_id': eid,
'_source': {
"ai_code" : ai_code,
"ai_codes" : ai_codes
"ai_codes" : ai_codes,
"history_codes": history_codes
}
})
@@ -184,23 +208,27 @@ def moveClassifierAiCodes(elastic, index_name_o, data):
# print(f"send_round -> {send_round}")
send_round += 1
except Exception as e:
print("error ---> ", str(e))
print("index, id ", index, eid)
if len(list_bulk) :
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')
# host=os.getenv('HOST_160')
# password=os.getenv('HOST_160_PASS')
host=os.getenv('HOST_160')
password=os.getenv('HOST_160_PASS')
# host=os.getenv('HOST_112')
# password=os.getenv('HOST_112_PASS')
host=os.getenv('HOST_113')
password=os.getenv('HOST_113_PASS')
# host=os.getenv('HOST_113')
# password=os.getenv('HOST_113_PASS')
# host=os.getenv('HOST_60')
# 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)
#---------------------------
#مرحله اول در بهار 1404
#برای کدهای 54 گانه
#در دو بخش تحویل داده شد
# moveKeywords(elastic,"mj_qa_section", "data/sections_kw_llama8b_170k_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")
#---------------------------
# کدهای 51 گانه ولی آموزش دیده با 60 هزار دیتاست بسیار ضعیف
# لذا خطا داشت و زود جایگزین شد
#-----نسخه قبلی اجرای مدل
# with open("./data/all_sections_classes.json", "r", encoding="utf-8") as f:
# classes = json.load(f)
#---------------------------
#---------------------------
# کدهای 51 گانه، آموزش دیده با حدود 2500 دیتاست خبرگانی خوب
#-----نسخه آخر اجرای مدل
# with open("./data/all_sections_classes_full_140405.json", "r", encoding="utf-8") as 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)
# 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)
moveClassifierAiCodes(elastic,"mj_qa_section", classes, "D49_v1")
print('finished!')
+9 -5
View File
@@ -11,8 +11,8 @@ from app.temp_refactor_gn_dataset import *
load_dotenv(dotenv_path="config.env")
host = os.getenv("HOST_160")
password = os.getenv("HOST_160_PASS")
# host = os.getenv("HOST_160")
# password = os.getenv("HOST_160_PASS")
# host=os.getenv('HOST_112')
# password=os.getenv('HOST_112_PASS')
@@ -23,8 +23,8 @@ password = os.getenv("HOST_160_PASS")
# host=os.getenv('HOST_118')
# password=os.getenv('HOST_118_PASS')
# host=os.getenv('HOST_60')
# password=os.getenv('HOST_60_PASS')
host=os.getenv('HOST_60')
password=os.getenv('HOST_60_PASS')
# host=os.getenv('HOST_161')
# 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_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.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")