ai-metacognition-toolkit 0.3.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ai_metacognition/__init__.py +123 -0
- ai_metacognition/analyzers/__init__.py +24 -0
- ai_metacognition/analyzers/base.py +39 -0
- ai_metacognition/analyzers/counterfactual_cot.py +579 -0
- ai_metacognition/analyzers/model_api.py +39 -0
- ai_metacognition/detectors/__init__.py +40 -0
- ai_metacognition/detectors/base.py +42 -0
- ai_metacognition/detectors/observer_effect.py +651 -0
- ai_metacognition/detectors/sandbagging_detector.py +1438 -0
- ai_metacognition/detectors/situational_awareness.py +526 -0
- ai_metacognition/integrations/__init__.py +16 -0
- ai_metacognition/integrations/anthropic_api.py +230 -0
- ai_metacognition/integrations/base.py +113 -0
- ai_metacognition/integrations/openai_api.py +300 -0
- ai_metacognition/probing/__init__.py +24 -0
- ai_metacognition/probing/extraction.py +176 -0
- ai_metacognition/probing/hooks.py +200 -0
- ai_metacognition/probing/probes.py +186 -0
- ai_metacognition/probing/vectors.py +133 -0
- ai_metacognition/utils/__init__.py +48 -0
- ai_metacognition/utils/feature_extraction.py +534 -0
- ai_metacognition/utils/statistical_tests.py +317 -0
- ai_metacognition/utils/text_processing.py +98 -0
- ai_metacognition/visualizations/__init__.py +22 -0
- ai_metacognition/visualizations/plotting.py +523 -0
- ai_metacognition_toolkit-0.3.0.dist-info/METADATA +621 -0
- ai_metacognition_toolkit-0.3.0.dist-info/RECORD +30 -0
- ai_metacognition_toolkit-0.3.0.dist-info/WHEEL +5 -0
- ai_metacognition_toolkit-0.3.0.dist-info/licenses/LICENSE +21 -0
- ai_metacognition_toolkit-0.3.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"""AI Metacognition Toolkit.
|
|
2
|
+
|
|
3
|
+
A comprehensive toolkit for detecting and analyzing metacognitive capabilities
|
|
4
|
+
in AI systems, particularly around situational awareness, evaluation contexts,
|
|
5
|
+
and strategic underperformance (sandbagging).
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
__version__ = "0.2.0"
|
|
9
|
+
|
|
10
|
+
from .detectors import (
|
|
11
|
+
SituationalAwarenessDetector,
|
|
12
|
+
ObserverEffectMonitor,
|
|
13
|
+
SandbaggingDetector,
|
|
14
|
+
Alert,
|
|
15
|
+
AlertSeverity,
|
|
16
|
+
ContextType,
|
|
17
|
+
Interaction,
|
|
18
|
+
AlertHandler,
|
|
19
|
+
ConsoleAlertHandler,
|
|
20
|
+
PerformanceSample,
|
|
21
|
+
SandbaggingResult,
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
from .analyzers import (
|
|
25
|
+
CounterfactualCoTAnalyzer,
|
|
26
|
+
ModelAPI,
|
|
27
|
+
InterventionType,
|
|
28
|
+
ReasoningType,
|
|
29
|
+
ReasoningNode,
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
from .utils import (
|
|
33
|
+
extract_behavioral_features,
|
|
34
|
+
count_hedging_phrases,
|
|
35
|
+
detect_meta_commentary,
|
|
36
|
+
extract_reasoning_depth,
|
|
37
|
+
compute_kl_divergence,
|
|
38
|
+
compute_js_divergence,
|
|
39
|
+
cosine_similarity,
|
|
40
|
+
normalize_distribution,
|
|
41
|
+
bayesian_update,
|
|
42
|
+
compute_confidence_interval,
|
|
43
|
+
z_score,
|
|
44
|
+
assess_divergence_significance,
|
|
45
|
+
SignificanceLevel,
|
|
46
|
+
compute_beta_mean,
|
|
47
|
+
compute_beta_variance,
|
|
48
|
+
beta_mode,
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
from .visualizations import (
|
|
52
|
+
plot_awareness_over_time,
|
|
53
|
+
plot_causal_attribution,
|
|
54
|
+
plot_divergence_heatmap,
|
|
55
|
+
plot_feature_distributions,
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
# Probing module (requires torch, transformers, sklearn)
|
|
59
|
+
# Import separately to avoid hard dependency
|
|
60
|
+
try:
|
|
61
|
+
from .probing import (
|
|
62
|
+
ActivationHook,
|
|
63
|
+
SteeringVector,
|
|
64
|
+
LinearProbe,
|
|
65
|
+
extract_caa_vector,
|
|
66
|
+
extract_activations,
|
|
67
|
+
)
|
|
68
|
+
_PROBING_AVAILABLE = True
|
|
69
|
+
except ImportError:
|
|
70
|
+
_PROBING_AVAILABLE = False
|
|
71
|
+
|
|
72
|
+
__all__ = [
|
|
73
|
+
# Detectors
|
|
74
|
+
"SituationalAwarenessDetector",
|
|
75
|
+
"ObserverEffectMonitor",
|
|
76
|
+
"SandbaggingDetector",
|
|
77
|
+
"Alert",
|
|
78
|
+
"AlertSeverity",
|
|
79
|
+
"ContextType",
|
|
80
|
+
"Interaction",
|
|
81
|
+
"AlertHandler",
|
|
82
|
+
"ConsoleAlertHandler",
|
|
83
|
+
"PerformanceSample",
|
|
84
|
+
"SandbaggingResult",
|
|
85
|
+
# Analyzers
|
|
86
|
+
"CounterfactualCoTAnalyzer",
|
|
87
|
+
"ModelAPI",
|
|
88
|
+
"InterventionType",
|
|
89
|
+
"ReasoningType",
|
|
90
|
+
"ReasoningNode",
|
|
91
|
+
# Utils
|
|
92
|
+
"extract_behavioral_features",
|
|
93
|
+
"count_hedging_phrases",
|
|
94
|
+
"detect_meta_commentary",
|
|
95
|
+
"extract_reasoning_depth",
|
|
96
|
+
"compute_kl_divergence",
|
|
97
|
+
"compute_js_divergence",
|
|
98
|
+
"cosine_similarity",
|
|
99
|
+
"normalize_distribution",
|
|
100
|
+
"bayesian_update",
|
|
101
|
+
"compute_confidence_interval",
|
|
102
|
+
"z_score",
|
|
103
|
+
"assess_divergence_significance",
|
|
104
|
+
"SignificanceLevel",
|
|
105
|
+
"compute_beta_mean",
|
|
106
|
+
"compute_beta_variance",
|
|
107
|
+
"beta_mode",
|
|
108
|
+
# Visualizations
|
|
109
|
+
"plot_awareness_over_time",
|
|
110
|
+
"plot_causal_attribution",
|
|
111
|
+
"plot_divergence_heatmap",
|
|
112
|
+
"plot_feature_distributions",
|
|
113
|
+
]
|
|
114
|
+
|
|
115
|
+
# Add probing exports if available
|
|
116
|
+
if _PROBING_AVAILABLE:
|
|
117
|
+
__all__.extend([
|
|
118
|
+
"ActivationHook",
|
|
119
|
+
"SteeringVector",
|
|
120
|
+
"LinearProbe",
|
|
121
|
+
"extract_caa_vector",
|
|
122
|
+
"extract_activations",
|
|
123
|
+
])
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"""Analyzers module for quantifying metacognitive capabilities.
|
|
2
|
+
|
|
3
|
+
This module provides tools for analyzing and measuring various aspects of
|
|
4
|
+
metacognition in AI systems, including confidence calibration, uncertainty
|
|
5
|
+
quantification, and self-awareness metrics.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from ai_metacognition.analyzers.base import BaseAnalyzer
|
|
9
|
+
from ai_metacognition.analyzers.counterfactual_cot import (
|
|
10
|
+
CounterfactualCoTAnalyzer,
|
|
11
|
+
InterventionType,
|
|
12
|
+
ReasoningNode,
|
|
13
|
+
ReasoningType,
|
|
14
|
+
)
|
|
15
|
+
from ai_metacognition.analyzers.model_api import ModelAPI
|
|
16
|
+
|
|
17
|
+
__all__ = [
|
|
18
|
+
"BaseAnalyzer",
|
|
19
|
+
"CounterfactualCoTAnalyzer",
|
|
20
|
+
"InterventionType",
|
|
21
|
+
"ReasoningNode",
|
|
22
|
+
"ReasoningType",
|
|
23
|
+
"ModelAPI",
|
|
24
|
+
]
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"""Base analyzer class for metacognition analysis."""
|
|
2
|
+
|
|
3
|
+
from abc import ABC, abstractmethod
|
|
4
|
+
from typing import Any, Dict, List
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class BaseAnalyzer(ABC):
|
|
8
|
+
"""Abstract base class for all analyzers.
|
|
9
|
+
|
|
10
|
+
All analyzer implementations should inherit from this class and implement
|
|
11
|
+
the analyze method.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
def __init__(self) -> None:
|
|
15
|
+
"""Initialize the analyzer."""
|
|
16
|
+
self.name: str = self.__class__.__name__
|
|
17
|
+
|
|
18
|
+
@abstractmethod
|
|
19
|
+
def analyze(self, data: List[str]) -> Dict[str, Any]:
|
|
20
|
+
"""Analyze the given data for metacognitive patterns.
|
|
21
|
+
|
|
22
|
+
Args:
|
|
23
|
+
data: List of text samples to analyze
|
|
24
|
+
|
|
25
|
+
Returns:
|
|
26
|
+
A dictionary containing analysis results with metrics and statistics
|
|
27
|
+
|
|
28
|
+
Raises:
|
|
29
|
+
NotImplementedError: If the method is not implemented
|
|
30
|
+
"""
|
|
31
|
+
raise NotImplementedError("Subclasses must implement the analyze method")
|
|
32
|
+
|
|
33
|
+
def __repr__(self) -> str:
|
|
34
|
+
"""Return string representation of the analyzer.
|
|
35
|
+
|
|
36
|
+
Returns:
|
|
37
|
+
String representation
|
|
38
|
+
"""
|
|
39
|
+
return f"{self.__class__.__name__}()"
|