Add test_predictions.py
Browse files
concept-classifier/test_predictions.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from inference2 import ProgrammingParadigmClassifier
|
| 2 |
+
import numpy as np
|
| 3 |
+
|
| 4 |
+
clf = ProgrammingParadigmClassifier()
|
| 5 |
+
test_cases = [
|
| 6 |
+
"How can I make this function pure so it doesn’t rely on external state?",
|
| 7 |
+
"Why does my deep inheritance hierarchy make the code harder to maintain?",
|
| 8 |
+
"Is it bad practice to structure everything inside one big main function?",
|
| 9 |
+
"How do I simulate method overloading in a language that doesn’t support classes?",
|
| 10 |
+
"Why does mutating this shared list inside the loop cause unpredictable bugs?",
|
| 11 |
+
"Should I replace this class with a set of small composable functions?",
|
| 12 |
+
"How much memory does each element in this C array actually occupy?",
|
| 13 |
+
"What’s the cleanest way to enforce encapsulation of internal fields?",
|
| 14 |
+
"Is using higher-order functions here clearer than writing explicit loops?",
|
| 15 |
+
"Why does adding global state make this script difficult to test?", "Why does returning new objects instead of mutating inputs make reasoning easier?", "How can I eliminate side effects from this function chain?", "Is currying useful for simplifying this API?", "Why does immutability reduce concurrency bugs?", "Should I refactor this loop into a map/filter pipeline?", "Why does this subclass violate the Liskov Substitution Principle?", "Should this behavior belong in the base class or a derived class?", "How do I prevent external access to private fields?", "Is composition better than inheritance here?", "Why does this object have too many responsibilities?", "Does passing large structs by value increase stack usage?", "Why does this pointer arithmetic cause undefined behavior?", "Is it better to use a static array or dynamic allocation here?", "Why does this recursive function overflow the stack?", "How much overhead does a function call add in C?", "Should I break this large class into independent helper functions?", "Why does this method depend on so many global variables?", "Is wrapping this logic inside an object really necessary?", "Would pure functions make this module easier to test?", "Is this abstraction hiding too much implementation detail?", "Can I use higher-order functions inside a class method?", "Should this singleton be replaced with dependency injection?", "Why does mutating object state inside a callback cause race conditions?", "Is storing functions as object fields good design?", "Can encapsulation coexist with immutability?", "Is this just a scripting style issue or a paradigm design problem?", "Does using namespaces make this object-oriented?", "If everything is technically procedural at runtime, do paradigms matter?", "Is this code functional just because it uses lambdas?", "Does avoiding classes automatically make code procedural?"
|
| 16 |
+
|
| 17 |
+
]
|
| 18 |
+
|
| 19 |
+
print("\n" + "=" * 70)
|
| 20 |
+
print("Testing All Prediction Cases")
|
| 21 |
+
print("=" * 70)
|
| 22 |
+
|
| 23 |
+
for text in test_cases:
|
| 24 |
+
prediction, probs, max_prob = clf.predict(text)
|
| 25 |
+
sorted_items = sorted(probs.items(), key=lambda x: x[1], reverse=True)
|
| 26 |
+
top_class, top_prob = sorted_items[0]
|
| 27 |
+
second_class, second_prob = sorted_items[1]
|
| 28 |
+
margin = top_prob - second_prob
|
| 29 |
+
|
| 30 |
+
print(f"\nText: {text}")
|
| 31 |
+
print(f"Result: {prediction}")
|
| 32 |
+
print(f"Max: {top_class} ({top_prob:.3f}), 2nd: {second_class} ({second_prob:.3f}), Margin: {margin:.3f}")
|