-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Vanessa Beck
committed
Dec 9, 2024
1 parent
05e9a60
commit 8faecdb
Showing
15 changed files
with
651 additions
and
67 deletions.
There are no files selected for viewing
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,30 @@ | ||
""" | ||
Dynamic Summarization and Adaptive Clustering Framework | ||
==================================================== | ||
A framework for real-time research synthesis using dynamic clustering | ||
and adaptive summarization techniques. | ||
Main Components: | ||
--------------- | ||
- Enhanced Embedding Generation | ||
- Dynamic Clustering | ||
- Adaptive Summarization | ||
- Interactive Visualization | ||
""" | ||
|
||
__version__ = '0.1.0' | ||
__author__ = 'Your Name' | ||
__license__ = 'MIT' | ||
|
||
from .embedding_generator import EnhancedEmbeddingGenerator | ||
from .clustering.dynamic_cluster_manager import DynamicClusterManager | ||
from .summarization.adaptive_summarizer import AdaptiveSummarizer | ||
from .utils.style_selector import AdaptiveStyleSelector | ||
|
||
__all__ = [ | ||
'EnhancedEmbeddingGenerator', | ||
'DynamicClusterManager', | ||
'AdaptiveSummarizer', | ||
'AdaptiveStyleSelector' | ||
] |
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
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
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
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,40 @@ | ||
from sklearn.cluster import KMeans, DBSCAN | ||
import hdbscan | ||
from sklearn.metrics import silhouette_score, davies_bouldin_score | ||
import numpy as np | ||
|
||
class DynamicClusterer: | ||
def __init__(self, config): | ||
self.config = config | ||
self.metrics = {} | ||
|
||
def select_best_algorithm(self, embeddings: np.ndarray) -> tuple: | ||
"""Dynamically select the best clustering algorithm based on data characteristics.""" | ||
algorithms = { | ||
'hdbscan': (hdbscan.HDBSCAN( | ||
min_cluster_size=self.config['clustering']['min_size'], | ||
metric='euclidean' | ||
), True), # (algorithm, handles_noise) | ||
'kmeans': (KMeans( | ||
n_clusters=self.config['clustering']['n_clusters'], | ||
random_state=42 | ||
), False) | ||
} | ||
|
||
best_score = -1 | ||
best_labels = None | ||
best_algo = None | ||
|
||
for name, (algo, handles_noise) in algorithms.items(): | ||
labels = algo.fit_predict(embeddings) | ||
if not handles_noise: # Skip evaluation if algorithm can't handle noise | ||
labels = labels[labels != -1] | ||
|
||
if len(np.unique(labels)) > 1: # Only evaluate if we have valid clusters | ||
score = silhouette_score(embeddings, labels) | ||
if score > best_score: | ||
best_score = score | ||
best_labels = labels | ||
best_algo = name | ||
|
||
return best_labels, best_algo, best_score |
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,28 @@ | ||
from typing import Dict, List, Any | ||
import numpy as np | ||
from ..utils.metrics_utils import calculate_cluster_metrics, calculate_summary_metrics | ||
from ..utils.logging_utils import MetricsLogger | ||
|
||
class EvaluationPipeline: | ||
def __init__(self, config: Dict[str, Any]): | ||
self.config = config | ||
self.logger = MetricsLogger(config) | ||
|
||
def evaluate_clustering(self, embeddings: np.ndarray, labels: np.ndarray) -> Dict[str, float]: | ||
"""Evaluate clustering quality.""" | ||
metrics = calculate_cluster_metrics(embeddings, labels) | ||
self.logger.log_metrics('clustering', metrics) | ||
return metrics | ||
|
||
def evaluate_summaries(self, | ||
generated_summaries: List[str], | ||
reference_summaries: List[str]) -> Dict[str, float]: | ||
"""Evaluate summary quality.""" | ||
metrics = { | ||
'summary_metrics': [ | ||
calculate_summary_metrics(gen, ref) | ||
for gen, ref in zip(generated_summaries, reference_summaries) | ||
] | ||
} | ||
self.logger.log_metrics('summarization', metrics) | ||
return metrics |
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
Oops, something went wrong.