|
|
|
|
|
from model import AcoliModel |
|
|
import json |
|
|
|
|
|
def batch_test(): |
|
|
print("Loading model and test data...") |
|
|
model = AcoliModel("./acoli-model") |
|
|
|
|
|
|
|
|
test_samples = [] |
|
|
with open('../acoli-dataset/data.jsonl', 'r', encoding='utf-8') as f: |
|
|
for i, line in enumerate(f): |
|
|
if i >= 10: |
|
|
break |
|
|
data = json.loads(line) |
|
|
test_samples.append(data) |
|
|
|
|
|
print(f"\n=== Batch Testing on {len(test_samples)} samples ===") |
|
|
|
|
|
correct = 0 |
|
|
for i, sample in enumerate(test_samples, 1): |
|
|
text = sample['text'] |
|
|
true_label = sample['label'] |
|
|
|
|
|
prediction = model.predict(text) |
|
|
predicted_label = int(prediction[0]['label'].split('_')[-1]) |
|
|
|
|
|
is_correct = (predicted_label == true_label) |
|
|
if is_correct: |
|
|
correct += 1 |
|
|
|
|
|
status = "β
" if is_correct else "β" |
|
|
print(f"{status} Sample {i}: True={true_label}, Predicted={predicted_label}") |
|
|
print(f" Text: {text[:60]}...") |
|
|
|
|
|
accuracy = correct / len(test_samples) * 100 |
|
|
print(f"\nπ Accuracy: {correct}/{len(test_samples)} ({accuracy:.1f}%)") |
|
|
|
|
|
if __name__ == "__main__": |
|
|
batch_test() |