File size: 4,044 Bytes
63bcd5a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5e95de5
63bcd5a
 
5e95de5
63bcd5a
 
5e95de5
63bcd5a
 
5e95de5
63bcd5a
 
 
5e95de5
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
import logging
import pandas as pd

from src.similarity_model import find_similar_projects
from src.similarity_model import load_metadata

logging.basicConfig(
    level=logging.INFO,
    format="%(asctime)s | %(levelname)s | %(message)s"
)
logger = logging.getLogger(__name__)

TOP_K = 5
SELF_TEST_SAMPLES = 20

def run_self_test():

    df = load_metadata()

    total = min(len(df), SELF_TEST_SAMPLES)

    success = 0

    for i in range(total):

        row = df.loc[i]

        results = find_similar_projects(
            title=row.get("project_title", ""),
            abstract=row.get("abstract", ""),
            description=row.get("description", ""),
            features=row.get("features", []),
            top_k=1
        )

        if "project_id" in results.columns:

            pred = int(results.iloc[0]["project_id"])

            if pred == i:
                success += 1

    score = success / total

    print("\n==============================")
    print("SELF RETRIEVAL TEST")
    print("==============================")
    print(f"Projects Tested : {total}")
    print(f"Top1 Accuracy   : {score:.2%}")
    print("==============================")

    return score

def run_real_queries():

    queries = [

        {
            "title":
            "AI Clinic Management System",

            "description":
            """
            Smart clinic with booking,
            chatbot, patient records,
            doctor dashboard.
            """
        },

        {
            "title":
            "Smart Library Assistant",

            "description":
            """
            Library app with chatbot,
            recommendation system,
            qr code borrowing.
            """
        },

        {
            "title":
            "Attendance Face Recognition",

            "description":
            """
            Attendance system using
            face recognition and reports.
            """
        },

        {
            "title":
            "E-commerce Recommendation Platform",

            "description":
            """
            Online shopping website with
            recommendation engine,
            payments and dashboard.
            """
        }

    ]

    print("\n==============================")
    print("REAL QUERY TEST")
    print("==============================")

    total_score = 0
    count = 0

    for q in queries:

        results = find_similar_projects(
            title=q["title"],
            description=q["description"],
            top_k=1
        )

        if "hybrid_score" in results.columns:

            score = float(
                results.iloc[0]["hybrid_score"]
            )

            risk = str(
                results.iloc[0]["duplicate_risk"]
            )

            top_title = str(
                results.iloc[0]["project_title"]
            )

            total_score += score
            count += 1

            print()
            print("Query:", q["title"])
            print("Top Match:", top_title)
            print("Score:", round(score, 4))
            print("Risk:", risk)

    avg = total_score / count if count else 0

    print("\n==============================")
    print(f"Average Query Score: {avg:.4f}")
    print("==============================")

    return avg

def final_status(
    self_score,
    query_score
):

    print("\n==============================")
    print("FINAL MODEL STATUS")
    print("==============================")

    final_score = (
        0.60 * self_score +
        0.40 * query_score
    )

    if final_score >= 0.90:
        print("EXCELLENT [OK]")

    elif final_score >= 0.75:
        print("VERY GOOD [OK]")

    elif final_score >= 0.60:
        print("GOOD [WARN]")

    else:
        print("NEEDS IMPROVEMENT [FAIL]")

    print("Overall Score:", round(final_score, 4))
    print("==============================\n")

if __name__ == "__main__":
    self_score = run_self_test()
    query_score = run_real_queries()
    final_status(self_score, query_score)