คอมโพเนนต์ไปป์ไลน์ของ Evaluator TFX จะทำการวิเคราะห์เชิงลึกเกี่ยวกับผลการฝึกสำหรับแบบจำลองของคุณ เพื่อช่วยให้คุณเข้าใจว่าแบบจำลองของคุณทำงานอย่างไรกับชุดย่อยของข้อมูลของคุณ ผู้ประเมินยังช่วยให้คุณตรวจสอบแบบจำลองที่ส่งออกของคุณ เพื่อให้แน่ใจว่าโมเดล "ดีเพียงพอ" ที่จะถูกผลักดันสู่การผลิต
เมื่อเปิดใช้งานการตรวจสอบความถูกต้อง ผู้ประเมินจะเปรียบเทียบโมเดลใหม่กับข้อมูลพื้นฐาน (เช่น โมเดลที่ให้บริการในปัจจุบัน) เพื่อตรวจสอบว่าโมเดลเหล่านี้ "ดีเพียงพอ" หรือไม่เมื่อเทียบกับข้อมูลพื้นฐาน ทำได้โดยการประเมินทั้งสองรุ่นในชุดข้อมูล eval และคำนวณประสิทธิภาพในหน่วยเมตริก (เช่น AUC, การสูญเสีย) หากเมตริกของโมเดลใหม่ตรงตามเกณฑ์ที่นักพัฒนากำหนดซึ่งสัมพันธ์กับโมเดลพื้นฐาน (เช่น AUC ไม่ต่ำกว่า) โมเดลดังกล่าวจะ "ได้รับพร" (ทำเครื่องหมายว่าดี) ซึ่งบ่งชี้ให้ผู้ ผลักดัน ทราบว่าสามารถผลักดันโมเดลไปสู่การผลิตได้
- กิน:
- การแบ่งอีวาจาก ExampleGen
- โมเดลฝึกหัดจาก Trainer
- โมเดลที่ได้รับพรก่อนหน้านี้ (หากต้องดำเนินการตรวจสอบ)
- ปล่อย:
- ผลการวิเคราะห์ ข้อมูลเมตา ML
- การตรวจสอบผลลัพธ์ไปยัง ML Metadata (หากจะทำการตรวจสอบความถูกต้อง)
ตัวประเมินและการวิเคราะห์แบบจำลองเทนเซอร์โฟลว์
Evaluator ใช้ประโยชน์จาก ไลบรารี TensorFlow Model Analysis เพื่อทำการวิเคราะห์ ซึ่งจะใช้ Apache Beam สำหรับการประมวลผลที่ปรับขนาดได้
การใช้ส่วนประกอบของเครื่องประเมิน
โดยปกติแล้ว ส่วนประกอบไปป์ไลน์ของ Evaluator นั้นง่ายต่อการปรับใช้และต้องการการปรับแต่งเพียงเล็กน้อย เนื่องจากงานส่วนใหญ่ทำโดยส่วนประกอบ Evaluator TFX
ในการตั้งค่าผู้ประเมิน จำเป็นต้องมีข้อมูลต่อไปนี้:
- เมตริกที่จะกำหนดค่า (จำเป็นเฉพาะเมื่อมีการเพิ่มเมตริกเพิ่มเติมนอกเหนือจากที่บันทึกไว้ในโมเดล) ดูเมตริกการ วิเคราะห์แบบจำลอง Tensorflow สำหรับข้อมูลเพิ่มเติม
- สไลซ์ที่จะกำหนดค่า (หากไม่มีการกำหนดสไลซ์ สไลซ์ "โดยรวม" จะถูกเพิ่มโดยค่าเริ่มต้น) ดูการตั้งค่าการ วิเคราะห์แบบจำลอง Tensorflow สำหรับข้อมูลเพิ่มเติม
หากต้องการรวมการตรวจสอบความถูกต้อง จำเป็นต้องมีข้อมูลเพิ่มเติมต่อไปนี้:
- รุ่นใดที่จะเปรียบเทียบกับ (พรล่าสุด ฯลฯ )
- การตรวจสอบแบบจำลอง (เกณฑ์) เพื่อตรวจสอบ ดูการตรวจสอบแบบจำลองการ วิเคราะห์แบบจำลอง Tensorflow สำหรับข้อมูลเพิ่มเติม
เมื่อเปิดใช้งาน การตรวจสอบจะดำเนินการกับเมตริกและสไลซ์ทั้งหมดที่กำหนดไว้
รหัสทั่วไปมีลักษณะดังนี้:
import tensorflow_model_analysis as tfma
...
# For TFMA evaluation
eval_config = tfma.EvalConfig(
model_specs=[
# This assumes a serving model with signature 'serving_default'. If
# using estimator based EvalSavedModel, add signature_name='eval' and
# remove the label_key. Note, if using a TFLite model, then you must set
# model_type='tf_lite'.
tfma.ModelSpec(label_key='<label_key>')
],
metrics_specs=[
tfma.MetricsSpec(
# The metrics added here are in addition to those saved with the
# model (assuming either a keras model or EvalSavedModel is used).
# Any metrics added into the saved model (for example using
# model.compile(..., metrics=[...]), etc) will be computed
# automatically.
metrics=[
tfma.MetricConfig(class_name='ExampleCount'),
tfma.MetricConfig(
class_name='BinaryAccuracy',
threshold=tfma.MetricThreshold(
value_threshold=tfma.GenericValueThreshold(
lower_bound={'value': 0.5}),
change_threshold=tfma.GenericChangeThreshold(
direction=tfma.MetricDirection.HIGHER_IS_BETTER,
absolute={'value': -1e-10})))
]
)
],
slicing_specs=[
# An empty slice spec means the overall slice, i.e. the whole dataset.
tfma.SlicingSpec(),
# Data can be sliced along a feature column. In this case, data is
# sliced along feature column trip_start_hour.
tfma.SlicingSpec(feature_keys=['trip_start_hour'])
])
# The following component is experimental and may change in the future. This is
# required to specify the latest blessed model will be used as the baseline.
model_resolver = Resolver(
strategy_class=dsl.experimental.LatestBlessedModelStrategy,
model=Channel(type=Model),
model_blessing=Channel(type=ModelBlessing)
).with_id('latest_blessed_model_resolver')
model_analyzer = Evaluator(
examples=examples_gen.outputs['examples'],
model=trainer.outputs['model'],
baseline_model=model_resolver.outputs['model'],
# Change threshold will be ignored if there is no baseline (first run).
eval_config=eval_config)
ผู้ประเมินสร้าง EvalResult (และเป็นทางเลือก ValidationResult หากใช้การตรวจสอบความถูกต้อง) ที่สามารถโหลดได้โดยใช้ TFMA ต่อไปนี้เป็นตัวอย่างวิธีการโหลดผลลัพธ์ลงในสมุดบันทึก Jupyter:
import tensorflow_model_analysis as tfma
output_path = evaluator.outputs['evaluation'].get()[0].uri
# Load the evaluation results.
eval_result = tfma.load_eval_result(output_path)
# Visualize the metrics and plots using tfma.view.render_slicing_metrics,
# tfma.view.render_plot, etc.
tfma.view.render_slicing_metrics(tfma_result)
...
# Load the validation results
validation_result = tfma.load_validation_result(output_path)
if not validation_result.validation_ok:
...
รายละเอียดเพิ่มเติมมีอยู่ในการ อ้างอิงของ Evaluator API