मॉडल को evaluation मोड में सेट करना
अब आप अपने लैंग्वेज मॉडल को evaluation मोड में सेट करने के लिए तैयार हैं. यदि inference के दौरान मॉडल evaluation मोड में नहीं है, तो batch normalization और dropout जैसी लेयर्स मॉडल के व्यवहार में बदलाव ला सकती हैं, जिससे translation क्वालिटी असंगत हो सकती है. मॉडल का मूल्यांकन करने के लिए लूप बनाइए!
कुछ डेटा पहले से लोड है: model, eval_dataloader, accelerator, और metric.
यह अभ्यास पाठ्यक्रम का हिस्सा है
PyTorch के साथ कुशल AI मॉडल प्रशिक्षण
अभ्यास निर्देश
- डेटासेट में बैचों पर लूप चलाने से पहले मॉडल को evaluation मोड में सेट करें.
- Accelerator के
.gather_for_metrics()मेथड से डिवाइसेज़ के बीचpredictionsऔरlabelsको इकट्ठा करें ताकि इवैल्यूएशन मेट्रिक्स निकाले जा सकें. - अंत में इवैल्यूएशन मेट्रिक compute करें.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
metric = evaluate.load("glue", "mrpc")
# Set the model in evaluation mode
____.____()
for step, batch in enumerate(eval_dataloader):
with torch.no_grad():
outputs = model(**batch)
predictions = outputs.logits.argmax(dim=-1)
# Aggregate values across devices
predictions, references = ____.____((predictions, batch["labels"]))
metric.add_batch(predictions=predictions, references=references)
# Compute the evaluation metric
eval_metric = metric.____()
print(eval_metric)