Following this instruction :
1. Strictly adhere to PEP-8 standards, ensuring code is clean, well-structured, and follows Python's style guide for readability.
2. Use appropriate modules like `typing` for type hints, ensuring code clarity, maintainability, and leveraging Python's standard libraries effectively.
3. Focus on time, space, robustness, scalability; write optimized, efficient code that can handle large datasets and scale seamlessly.
4. Implement comprehensive error handling, catching exceptions gracefully, providing meaningful error messages, and ensuring code robustness under unexpected conditions.
5. Ensure the developer agent writes advanced, maintainable Python code, balancing performance and readability while adhering to best practices.

TASK : Generalised robustness metrics Pipeline (logits or predictions or loss values)

NOTE : using the only torch module we have implement below scratch 

Problem Statement:

In coreference resolution, these metrics assess how well predicted entity clusters match the reference clusters. Here are the mathematical formulations for each:

---

### 1. **MUC Score**  
The MUC (Link-based) Score measures the matching of predicted and reference entity clusters by evaluating the number of links (connections between mentions in the same cluster) that need to be added or removed to make the predicted clusters match the reference clusters.

The MUC precision and recall are defined as:
\[
\text{MUC Precision} = \frac{\sum_{i=1}^{K} (|C_i| - R_i)}{\sum_{j=1}^{P} (|C_j| - 1)}
\]
\[
\text{MUC Recall} = \frac{\sum_{i=1}^{K} (|C_i| - R_i)}{\sum_{k=1}^{R} (|C_k| - 1)}
\]
where:
- \( C_i \) is the \(i\)-th reference cluster.
- \( R_i \) is the number of predicted clusters that overlap with \( C_i \).
- \( K \) is the number of reference clusters.
- \( P \) and \( R \) are the total predicted and reference clusters, respectively.

The MUC F1-score can be derived from these precision and recall values.

---

### 2. **B³ (B-Cubed) Score**  
The B³ score evaluates the overlap of coreference mentions by computing precision and recall based on each mention's association with a cluster.

For a set of mentions \( M \) with predicted clusters \( C \) and reference clusters \( R \):
\[
\text{B}^3 \text{ Precision} = \frac{1}{|M|} \sum_{m \in M} \frac{|C_m \cap R_m|}{|C_m|}
\]
\[
\text{B}^3 \text{ Recall} = \frac{1}{|M|} \sum_{m \in M} \frac{|C_m \cap R_m|}{|R_m|}
\]
where:
- \( C_m \) and \( R_m \) are the predicted and reference clusters containing mention \( m \).
- \( |C_m \cap R_m| \) is the overlap of mentions in both the predicted and reference clusters.

The B³ F1-score can be computed from these precision and recall values.

---

### 3. **CEAF (Constrained Entity-Alignment F-measure) Score**  
CEAF measures alignment by finding the best one-to-one matching between predicted and reference clusters. This is done by maximizing the alignment score between clusters.

For a batch of predicted clusters \( C = \{C_1, \dots, C_p\} \) and reference clusters \( R = \{R_1, \dots, R_r\} \), CEAF precision and recall are:
\[
\text{CEAF Precision} = \frac{\sum_{i=1}^{K} \phi(C_i, R_i)}{\sum_{j=1}^{P} \phi(C_j, C_j)}
\]
\[
\text{CEAF Recall} = \frac{\sum_{i=1}^{K} \phi(C_i, R_i)}{\sum_{k=1}^{R} \phi(R_k, R_k)}
\]
where:
- \( \phi(C_i, R_i) \) represents the similarity (often measured as overlap or a distance metric) between a predicted cluster \( C_i \) and a reference cluster \( R_i \).
- \( K \) is the total number of matched clusters.

The F1-score for CEAF is calculated from these precision and recall values, representing the alignment quality between the entity clusters in the predicted and reference sets.

---

These scores provide insight into coreference resolution quality, measuring how well clusters of mentions in a text align with clusters in the reference.