-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add BasicReasoning module with logical, pattern, and causal reasoning…
… components; implement confidence estimation and reasoning score calculation; add unit tests for reasoning metrics
- Loading branch information
1 parent
7c08a63
commit 91a1f36
Showing
6 changed files
with
121 additions
and
1 deletion.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import pytest | ||
import torch | ||
from models.reasoning import BasicReasoning | ||
|
||
@pytest.fixture | ||
def model(): | ||
return BasicReasoning(hidden_dim=128) | ||
|
||
@pytest.fixture | ||
def sample_input(): | ||
return torch.randn(2, 5, 128) # [batch_size, seq_len, hidden_dim] | ||
|
||
class TestBasicReasoning: | ||
def test_reasoning_scores(self, model, sample_input): | ||
output = model(sample_input) | ||
|
||
# Check all components exist | ||
assert 'logical_score' in output['metrics'] | ||
assert 'pattern_score' in output['metrics'] | ||
assert 'causal_score' in output['metrics'] | ||
|
||
# Verify score ranges | ||
for key in ['logical_score', 'pattern_score', 'causal_score']: | ||
assert 0 <= output['metrics'][key] <= 1 | ||
|
||
# Calculate overall score | ||
score = model.calculate_reasoning_score(output['metrics']) | ||
assert 0 <= score <= 100 | ||
|
||
def test_confidence_estimation(self, model, sample_input): | ||
output = model(sample_input) | ||
assert 'confidence' in output | ||
assert output['confidence'].shape == (2, 5, 1) # [batch_size, seq_len, 1] | ||
assert torch.all(output['confidence'] >= 0) and torch.all(output['confidence'] <= 1) |