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 Named Entity Linking (NEL), these metrics evaluate the accuracy and relevance of linking detected entities to entries in a knowledge base. Below are the mathematical formulations:

---

### 1. **Linking Accuracy**  
Linking Accuracy measures the proportion of named entities that are correctly linked to the appropriate knowledge base entries out of the total detected entities. 

For a batch of size \( B \) with \( E \) entities per instance:
\[
\text{Linking Accuracy} = \frac{1}{B} \sum_{i=1}^{B} \frac{\text{Correct Links}_i}{\text{Total Entities}_i}
\]
where:
- \( \text{Correct Links}_i \) is the number of correctly linked entities in instance \( i \).
- \( \text{Total Entities}_i \) is the total number of entities detected in instance \( i \).

This metric reflects the accuracy of entity linking across instances in the batch.

---

### 2. **Mean Reciprocal Rank (MRR) for Linking**  
MRR is a ranking-based metric that evaluates the relevance of the linked entity by using the rank of the first correct link among candidate links. A higher rank (lower index) for the correct link leads to a higher MRR.

For each entity in a batch of size \( B \) with \( E \) entities per instance, MRR is given by:
\[
\text{MRR} = \frac{1}{B} \sum_{i=1}^{B} \frac{1}{E} \sum_{j=1}^{E} \frac{1}{\text{Rank}_{ij}}
\]
where:
- \( \text{Rank}_{ij} \) is the rank position of the first correct link for the \( j \)-th entity in instance \( i \).
- \( E \) is the number of entities per instance.

This metric emphasizes the accuracy of early correct matches, penalizing cases where the correct entity is ranked lower.

---

### 3. **Entity Link Precision**  
Entity Link Precision calculates the fraction of entities correctly linked out of all entities identified and linked, giving a measure of the accuracy of the linking task.

For a batch of size \( B \) with \( E \) entities per instance:
\[
\text{Entity Link Precision} = \frac{1}{B} \sum_{i=1}^{B} \frac{\text{True Positives}_i}{\text{True Positives}_i + \text{False Positives}_i}
\]
where:
- \( \text{True Positives}_i \) is the count of entities correctly linked to knowledge base entries in instance \( i \).
- \( \text{False Positives}_i \) is the count of incorrectly linked entities in instance \( i \).

This precision measure reflects the model's ability to link entities accurately, avoiding incorrect associations.

---

These metrics provide a comprehensive evaluation of the effectiveness of Named Entity Linking models by assessing accuracy, ranking quality, and precision in linking tasks.