From 91a1f361af7a57d6cd4e2e96632933c218285e9e Mon Sep 17 00:00:00 2001 From: kasinadhsarma Date: Thu, 26 Dec 2024 23:21:06 +0530 Subject: [PATCH] Add BasicReasoning module with logical, pattern, and causal reasoning components; implement confidence estimation and reasoning score calculation; add unit tests for reasoning metrics --- core/__pycache__/config.cpython-310.pyc | Bin 0 -> 3798 bytes models/__pycache__/base_model.cpython-310.pyc | Bin 0 -> 3390 bytes models/__pycache__/reasoning.cpython-310.pyc | Bin 0 -> 5479 bytes models/reasoning.py | 88 +++++++++++++++++- ...est_reasoning.cpython-310-pytest-8.3.4.pyc | Bin 0 -> 3972 bytes tests/test_reasoning.py | 34 +++++++ 6 files changed, 121 insertions(+), 1 deletion(-) create mode 100644 core/__pycache__/config.cpython-310.pyc create mode 100644 models/__pycache__/base_model.cpython-310.pyc create mode 100644 models/__pycache__/reasoning.cpython-310.pyc create mode 100644 tests/__pycache__/test_reasoning.cpython-310-pytest-8.3.4.pyc create mode 100644 tests/test_reasoning.py diff --git a/core/__pycache__/config.cpython-310.pyc b/core/__pycache__/config.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..a155c41afd363fa65df73af04bb05e94939b1c13 GIT binary patch literal 3798 zcmb7H&2J<}74Pop>6z&ne|zKoh_amk2?N@3$U+EUuvdo7ZbY1wb`jEWXqCIlGwtn< zNmY-tHnxPctK7H)C;ONScg|elAE+B}!GZ%4oIptYUUkp-BVGYDsyDA*y{@kJ>iyoU z&Sz$P3vKOR$$-yT)}Lr_zPT7|psNCeTYZb$+)3=z={q*@wWOB1eK)Q5>t^gGUf&bW z`xdWr?}f#^=gxDx-!PH}Z$i>ElBSWgxDSbMBrPLp^A02(Bk{TW*y_$4e7c!uJMmyF zSrO-1kmh`xh+rp|!M%q;lxHf6^Rdc=QbC-K5|N6mFseP@e=>~KN>jl(TFz167Bvl zR>f9CO6S|ufe#=RR^Nsbogcw<{Tg@ruBZ!-*VZiV!bwf=b?{!lC4AAmVPV`@vqYP> zIl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M?Cv zhw3nIAKZP(QJhtW&#$r7ox3tvX-ns-#MDGdSFY0RyTp+}Wl(=e+}Z98XCQSS6F)&$ zgvzoKEK(J4B+Yc&rYzx0WAd3Kl%%YpJ=9yIFLN=JE+nO+>GEf)hKX^r##OJ?&9(Aw b`aKE^MfK0MI_^A5DBTmCTj)2bFWdhCyM4SK literal 0 HcmV?d00001 diff --git a/models/__pycache__/base_model.cpython-310.pyc b/models/__pycache__/base_model.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..fb40d379af0875eccf55fd08400e484bbafba7d0 GIT binary patch literal 3390 zcmZ`+-H#kc5%2E#p8d%A>{t#-qm{0s#fj_(hA5FL1EgY#96qUiAwgoN$_wUj0im)?*a=EVVMbXH)VM!Yyt;CfpWm z?3`LX7dQ@gf#WVY9`}SdVBF`yW4q^b`U&ZV&pE6w@-2aVh$Ek*kJ%d@Xnt2U3z#GN%hdNkuCXv5En; zDhsGxI&&Aebb&nY!pOfc3NDO77&R(uf%2N1z{%-;x1}95od~J@C`$6Aj3Vj4_R>Xy zH>_EnYxkoh7qQgN(NxG|Z5@hZ?L3Insn9N*XEH6dcdtI1_Lhh2+S*nk9ehLHQ?O|i z8H+~IQ}X49yQ3l#yN9t#@|cfQEVFo5JOY&xyyD${F$A^1EH~1(Z*1_hf{Rq`9)RT{ z)8CmK%K#KcrPVf&khQq;CsLav%N6iuiUwZQLCt3G0xCz9`hMVC1Yx_YW9!dZp zBHK6)N*U*BQYfLF65~y~SzKn*6qX;!Qo9hnssI-qq(xlnV45p%RsjLn$YOOUcr-}T zRC}rzlv(^pUP7T^zkrY*PK&9MF9D<5l;}B{KGHU>(mw18VUZ7Yco3KUQ617ghI0hU zYkH*Vp{5VCtNMi$N_!7QG8~n)IQcRNtI1Uq>kSI|FqZr>4Ah%ILfWL)tZVcdZCXv} zU$=a=MX%5{vl)D|w!mpaHhcM^+b*SasYJ+l%J%Pf1B~B1&O{XHFv5VCrr2*r(a|(c zmtVXn;zb|WR+5+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rw@^{pYHt^8Lq2qnC|Z(@>%ko^c5;zQ^CrLkzHF2G2#WO+YLM$U zMoAgd$-P-S-||~Sa>PaE3qJS%;hF}c0>k2Lzy+9$OJ_GeNb@+78?b_d7*R{eeGU&D zG?EKoO>u?V8ws+C8*SL)x>5#arlybW&c5I4pWC@eZwZof2X;X@o&3Zcy=EDmq#29|%Oa zPLU7FG`KCzlm{8b#E4ZnBHlDk0uh&Yq=k4k9ZEAUc?v33YDd;bHfvqSMr5CJ?rt`w8i+FjY%-_YC}D>L{RFedg+EsH&hU8UOBp#_B zqD*=f7U-Hu7x6PbH-H8`GB1MOBI}|Cn$sg&l^iNvpfdbAv^J{pv4K$9+n}hTIez(C zkc6WIVeDr9F&9CSEZnihKQVVUm7W~@^)K}N^Yw#Q)$@!**{CZ>iKt!R)Mo_ zRDOB~oTESLz)0$kTzmZD%1J+QA~;KL(yrPoMqL_lR#tJEzNK{kKzSn4zM=jNP~o Dict[str, torch.Tensor]: + # Logical reasoning + logical_out = self.logical_layer(x) + + # Pattern recognition through attention + pattern_out, pattern_weights = self.pattern_recognition(x, x, x) + + # Causal inference by combining logical and pattern outputs + causal_input = torch.cat([logical_out, pattern_out], dim=-1) + causal_out = self.causal_inference(causal_input) + + # Calculate reasoning confidence + confidence_input = torch.cat([logical_out, pattern_out, causal_out], dim=-1) + confidence = self.confidence_estimator(confidence_input) + + # Calculate normalized reasoning scores + with torch.no_grad(): + # Normalize using softmax for pattern weights + pattern_weights_norm = torch.softmax(pattern_weights, dim=-1) + pattern_score = torch.mean(pattern_weights_norm) + + # Normalize cosine similarities to [0,1] range + logical_sim = torch.cosine_similarity(logical_out, x, dim=-1) + logical_score = torch.clamp((logical_sim + 1) / 2, 0, 1).mean() + + causal_sim = torch.cosine_similarity(causal_out, x, dim=-1) + causal_score = torch.clamp((causal_sim + 1) / 2, 0, 1).mean() + + return { + 'output': causal_out, + 'confidence': confidence, + 'metrics': { + 'logical_score': logical_score.item(), + 'pattern_score': pattern_score.item(), + 'causal_score': causal_score.item(), + 'reasoning_weights': pattern_weights + } + } + + def calculate_reasoning_score(self, metrics: Dict[str, float]) -> float: + """Calculate overall reasoning capability score""" + weights = { + 'logical': 0.4, + 'pattern': 0.3, + 'causal': 0.3 + } + + score = ( + weights['logical'] * metrics['logical_score'] + + weights['pattern'] * metrics['pattern_score'] + + weights['causal'] * metrics['causal_score'] + ) + + return score * 100 # Convert to percentage diff --git a/tests/__pycache__/test_reasoning.cpython-310-pytest-8.3.4.pyc b/tests/__pycache__/test_reasoning.cpython-310-pytest-8.3.4.pyc new file mode 100644 index 0000000000000000000000000000000000000000..c2e8386f978c62f14d90139264d9ada0b83e0303 GIT binary patch literal 3972 zcmcIn%WmYx6=m_&Z1z*{$4nB%@xVjJdbQrc%wX&|$RdCiNmd;M1gDFVTI!dJ)MQ2} z0zqcB0lWy1EF3_+NMHx~g?vIbUUC~CfPP^XhR-c_OKeG5x`Db~RlIf2saxc^WWQ2z zHT=qd=^p>n)U^N7ApbKkc#alv7_M>F(V9&C>s>?FnASC$7R#>KOle z9(F9mj|j`vg@eC4tjR&KuA&obmyCFGV`zZ6d3Z%jugFK>I5baBt++2*C#fZZ9`D`I z&w2&;q~$2+4mzRV?hVf4B4!kRRTmZX@8A=_b8>nJ6ROi}>cru#)-1(6TSLaJFZ6jWDR7$?WTDN_cVYuqP3a8T8}>)sf2Nk0Xm(<8=U$|f?*OTI zFVf$>10?rT?YF;3io7&NltpCHMaJASme{YA-c-e*kYsR)-AhKSE!peviS2`Ze&L zQ@kBM&ljYlc-Kd~>-X_aYFxv;ym**aI{o8zE9m%9t1rT|&<$hJZbc9pz1{QJ#q^`c zgV&p0w9@XaP+BeQ)`4WcL%vAVYFMKrmaRt7;FhoUzMT5bjB(HO!rL=6vz zm?yJ9hQVBs@$`54lc!=yb#IWLJXO(myeOMPXJs_E2R4S7!2$x_A+t9@=^&$Ya79Y( z>34!+JJ}pMMH3=?f!WTNlZ%=DLcK5 z{9r3TXk>$o<4%6Cml|i`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