latest editions

This commit is contained in:
ajokar 2025-07-17 20:36:22 +03:30
parent 420979be7d
commit 05e0a22874
2 changed files with 75 additions and 34 deletions

51
data/classes51new.txt Normal file
View File

@ -0,0 +1,51 @@
1 - آب
2 - آمار، برنامه و بودجه
3 - آموزش و پرورش
4 - آموزش عالی، پژوهش و فناوری
5 - آیین دادرسی مدنی و اداری
6 - آیین دادرسی کیفری
7 - اداری و استخدامی
8 - اموال و معاملات دولتی
9 - اطلاعات و امنیت
10 - امور زیربنایی
11 - انتخابات
12 - اوقاف، اماکن دینی و امور مذهبی
13 - ایثـارگران
14 - بانکداری
15 - برق و انرژی‌های نو
16 - بیمـه‌
17 - پولی و مالی
18 - تأمین اجتماعی
19 - تجارت
20 - تشکل‌های مدنی و احزاب
21 - تشکیلات و امور اداری قوه قضائیه
22 - تعـاون
23 - تعزیرات حکومتی
24 - تقسیمات کشوری و مدیریت محلی
25 - ثبت اسناد و املاک
26 - حمل و نقل
27 - خانواده
28 - رسانه
29 - سلامت
30 - صنعـت
31 - فناوری اطلاعات و ارتباطات
32 - فرهنگ و هنر
33 - کار
34 - کشاورزی و دامپروری
35 - کیفـری
36 - مالکیت فکری
37 - مالیات
38 - محاسبات عمومی
39 - محیط زیست
40 - مـدنـی
41 - مسکن و شهرسازی
42 - مصرف
43 - معـدن
44 - منابع طبیعی
45 - مناطق آزاد و ویژه اقتصادی
46 - میراث فرهنگی و گردشگری
47 - نظام قانون‌گذاری
48 - نظام‌های صنفی و حرفه‌ای
49 - نظامی و انتظامی
50 - نفت و گاز
51 - ورزش

View File

@ -3,37 +3,22 @@
""" """
import json import json
with open('./data/classes51.txt', 'r') as file: with open('./data/classes51new.txt', 'r') as file:
classes = file.readlines() classes = file.read()
classes_list = classes.splitlines()
with open('./data/classification_ds.json', 'r') as file: with open('./data/classification_ds.json', 'r') as file:
sections = json.load(file) sections = json.load(file)
# send content of some sections and classes to llama chat # send content of some sections and classes to llama chat
# and ask about the best class # and ask for the best class
from transformers import AutoModelForCausalLM, AutoTokenizer
from html import escape
from lxml import etree
from datetime import datetime
from elasticsearch import Elasticsearch
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline, TextIteratorStreamer
from threading import Thread
import torch import torch
import time import time
from concurrent.futures import ThreadPoolExecutor
import concurrent
import threading
import json import json
import os.path from funcs import write_to_json
import os
import normalizer
from funcs import write_to_json, read_from_json
#lock = threading.Lock()
#lock1 = threading.Lock()
#from cleantext import clean
#import re
if torch.cuda.is_available(): if torch.cuda.is_available():
model_id = "PartAI/Dorna-Llama3-8B-Instruct" model_id = "PartAI/Dorna-Llama3-8B-Instruct"
@ -46,22 +31,22 @@ remained = 0
id = '' id = ''
keywords_count = 15 keywords_count = 15
def command(text): def command(text):
global remained global remained
try: try:
messages = [{"role": "system", "content": "تو یک وکیل حقوق دان هستی و باید بتوانی متن های قانونی و حقوقی را به خوبی تفسیر کنی. " }, messages = [{"role": "system", "content": "تو یک حقوق دان هستی و باید بتوانی متن های قانونی و حقوقی را به صورت حرفه ای تفسیر کنی. " },
{"role": "user", "content": {"role": "user", "content":
'''با توجه به 51 کلاسی که در ادامه می آید، بهترین کلاس که از نظر محتوایی با متن زیر مطابقت دارد را از میان کلاس های ارائه شده انتخاب کن. تاکید می کنم که فقط اجازه داری یک کلاس را انتخاب کنی. '''51 دسته در متن پرامپت می آید. در بین این دسته ها، شماره دسته ای که از نظر معنایی می تواند نزدیک ترین عنوان دسته برای متن باشد را انتخاب کن
نام کلاس باید دقیقا مطابق با عنوان های کلاس های 51 گانه باشد. تاکید می کنم که فقط اجازه داری یک دسته را انتخاب کنی.
هیچ توضیح اضافه ای پیش یا پس از عنوان کلاس ننویس. فقط شماره دسته را به صورت یک عدد در خروجی بیاور.
به هیچ عنوان، هیچ توضیح اضافه ای پیش یا پس از شماره دسته در خروجی ننویس.
"متن": {} "متن": {}
'''.format(text) '''.format(text)
}, },
{"role": "user", "content": {"role": "user", "content":
'''کلاس های 51 گانه عبارت اند از: {} '''دسته های 51 گانه عبارت اند از: {}
'''.format(classes) '''.format(classes)
}, },
] ]
@ -111,25 +96,30 @@ if __name__ == "__main__":
content = sections[counter]['content'] content = sections[counter]['content']
new_class = command(content) new_class = command(content)
try:
new_class_title = (classes_list[(int(new_class))-1].split('-')[1]).strip()
except:
new_class_title = '-'
print("section " + str(count) + "/" + str(len(sections)) + " class extracting ... ") print("section " + str(count) + "/" + str(len(sections)) + " class extracting ... ")
classes_dict.append({ classes_dict.append({
'id': count,
'content':content, 'content':content,
'prev-class': prev_class, 'prev-class': prev_class,
'new-class': new_class 'new-class-title': new_class_title,
'new-class': new_class,
}) })
count+= 1 count+= 1
counter+= 500 counter+= 500
if counter > 49387: if counter > 49387:
break break
write_to_json(classes_dict, "./data/result.json") write_to_json(classes_dict, "./data/result4.json")
except Exception as inst: except Exception as inst:
print(type(inst)) # the exception type print(type(inst)) # the exception type
print(inst.args) # arguments stored in .args print(inst.args) # arguments stored in .args
end_time = time.time() end_time = time.time()
print(end_time) print(end_time)
operation_time = (int(end_time-start_time)/60)/60 operation_time = (int(end_time-start_time)/60)/60