"""Kiểm tra hồi quy câu teen code bằng toàn bộ checkpoint đang triển khai.""" from pathlib import Path import sys ROOT = Path(__file__).resolve().parents[1] sys.path.insert(0, str(ROOT)) from model_service import service # noqa: E402 def main(): text = 'c0n gà 0c h3o' result = service.predict_many([text]) row = result['rows'][0] prep = row['preprocessing'] print('Câu gốc :', text) print('Đầu vào model :', prep['inference_text']) print('Thay thế :', ', '.join( item['original'] + ' -> ' + item['normalized'] for item in prep['obfuscation_replacements'])) print('Kết luận :', row['verdict']['label']) print('Vote model :', row['vote']['toxic'], 'TOXIC /', row['vote']['total']) print() for model in row['models']: score = (f"P(TOXIC)={model['prob_toxic']:.6f}" if model['prob_toxic'] is not None else f"margin={model['decision_score']:.6f}" if model['decision_score'] is not None else 'không có score') print(f"{model['name']:<42} {model['label']:<5} {score}") if result['errors']: print('\nLỗi mô hình:') for error in result['errors']: print('-', error['name'] + ':', error['error']) raise SystemExit(1) tfidf = [m for m in row['models'] if m['id'].startswith('tf_idf_')] if len(tfidf) != 3 or any(m['label'] != 'TOXIC' for m in tfidf): raise SystemExit('FAILED: ba mô hình TF-IDF chưa cùng nhận TOXIC.') print('\nPASS: chuẩn hóa có lưu vết và 3/3 mô hình TF-IDF nhận TOXIC.') if __name__ == '__main__': main()