บทนำ
TensorFlow เฟรมเวิร์ก ML จาก Google โค้ดเปิด ใช้กับ Python ใช้ในงานวิจัยและการผลิต
การติดตั้ง
pip install tensorflow
Tensor และชุดข้อมูล Iliad
เทนเซอร์ = อาร์เรย์หลายมิติ สำหรับ Data flow graph Iliad: ข้อความ 3 งานแปลของ Cowper, Derby, Butler ฝึกระบุผู้แปลจากบรรทัดเดียว preprocessing: ลบ header/footer, line numbers, chapter titles
ตัวอย่าง: Export Model พร้อม Preprocessing Layer
print("ขั้นตอน Preprocessing ที่ปรับแต่ง")
preprocess_layer = TextVectorization(
max_tokens=vocab_size,
standardize=tf_text.case_fold_utf8,
split=tokenizer.tokenize,
output_mode='int',
output_sequence_length=MAX_SEQUENCE_LENGTH)
preprocess_layer.set_vocabulary(vocab)
print("กำลัง Export โมเดล")
export_model = tf.keras.Sequential([
preprocess_layer,
model,
layers.Activation('sigmoid')
])
ที่มา: TensorFlow Text Loading Tutorial
ผลลัพธ์
ขั้นตอน Preprocessing ที่ปรับแต่ง กำลัง Export โมเดล
คำอธิบาย
- สร้าง
TextVectorizationlayer ทำ preprocessing เหมือนเดิม - Vocabulary ฝึกแล้ว ใช้
set_vocabularyโหลด vocabulary ใหม่ - รวม preprocessing layer, model, และ activation layer เป็น Sequential model ใหม่
- โมเดลนี้รับ raw strings ได้โดยตรง