โดยการฝึกอบรมข้อความด้วยแท็กที่มีอยู่การจำแนกประเภทของข้อความใหม่จะเกิดขึ้นได้
2019.3.25: โครงการเดิมเป็นธุรกิจการวิเคราะห์ความคิดเห็นสาธารณะของ บริษัท แต่ต่อมามันเข้าร่วมในการแข่งขันบางอย่างและเพิ่มฟังก์ชั่นเล็ก ๆ น้อย ๆ ในเวลานั้นฉันแค่ต้องการรวมรูปแบบง่าย ๆ ของการเรียนรู้ของเครื่องจักรและการเรียนรู้อย่างลึกซึ้งเพื่อใช้ทักษะด้านวิศวกรรมของฉัน หลังจากสื่อสารกับชาวเน็ตบางคนฉันรู้สึกว่าไม่จำเป็นต้องสร้างโมดูลทั่วไป (ไม่มีใครใช้มันต่อไปฮ่าฮ่า ~) เมื่อเร็ว ๆ นี้ฉันค่อนข้างสบายดังนั้นฉันจึงลบพารามิเตอร์และฟังก์ชั่นแฟนซีที่ไร้ประโยชน์ทั้งหมดเพื่อจุดประสงค์ในการเป็นแบบง่ายขึ้น
ข้อมูลอีคอมเมิร์ซแบบฉลากเดี่ยวมากกว่า 4,000 ข้อมูลและข้อมูลอาชญากรรมตุลาการหลายคนได้รับการจัดทำขึ้นมากกว่า 15,000 ครั้ง ข้อมูลมีไว้สำหรับการวิจัยเชิงวิชาการเท่านั้นและห้ามเผยแพร่เชิงพาณิชย์
from TextClassification . load_data import load_data
# 单标签
data = load_data ( 'single' )
x = data [ 'evaluation' ]
y = [[ i ] for i in data [ 'label' ]]
# 多标签
data = load_data ( 'multiple' )
x = [ i [ 'fact' ] for i in data ]
y = [ i [ 'accusation' ] for i in data ]

ใช้ในการประมวลผลข้อมูลข้อความต้นฉบับล่วงหน้ารวมถึงการแบ่งส่วนคำ, การเข้ารหัสการแปลง, ความสม่ำเสมอความยาวและวิธีการอื่น ๆ
preprocess = DataPreprocess ()
# 处理文本
texts_cut = preprocess . cut_texts ( texts , word_len )
preprocess . train_tokenizer ( texts_cut , num_words )
texts_seq = preprocess . text2seq ( texts_cut , sentence_len )
# 得到标签
preprocess . creat_label_set ( labels )
labels = preprocess . creat_labels ( labels ) รวมการประมวลผลล่วงหน้าการฝึกอบรมเครือข่ายและการทำนายเครือข่าย โปรดดูสคริปต์ตัวอย่างสองรายการสำหรับการสาธิต
วิธีนี้มีดังนี้:
from TextClassification import TextClassification
clf = TextClassification ()
texts_seq , texts_labels = clf . get_preprocess ( x_train , y_train ,
word_len = 1 ,
num_words = 2000 ,
sentence_len = 50 )
clf . fit ( texts_seq = texts_seq ,
texts_labels = texts_labels ,
output_type = data_type ,
epochs = 10 ,
batch_size = 64 ,
model = None )
# 保存整个模块,包括预处理和神经网络
with open ( './%s.pkl' % data_type , 'wb' ) as f :
pickle . dump ( clf , f )
# 导入刚才保存的模型
with open ( './%s.pkl' % data_type , 'rb' ) as f :
clf = pickle . load ( f )
y_predict = clf . predict ( x_test )
y_predict = [[ clf . preprocess . label_set [ i . argmax ()]] for i in y_predict ]
score = sum ( y_predict == np . array ( y_test )) / len ( y_test )
print ( score ) # 0.9288