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:



---

### 1. **Unlabeled Attachment Score (UAS)**  
Unlabeled Attachment Score (UAS) measures the percentage of tokens in a sentence that have the correct syntactic head, regardless of the dependency label.

For a batch with \( N \) tokens, the UAS is calculated as:
\[
\text{UAS} = \frac{\sum_{i=1}^{N} \delta(h_i = \hat{h}_i)}{N}
\]
where:
- \( h_i \) is the head of the \( i \)-th token in the predicted parse.
- \( \hat{h}_i \) is the head of the \( i \)-th token in the reference parse.
- \( \delta(h_i = \hat{h}_i) \) is an indicator function that equals 1 if \( h_i = \hat{h}_i \) (i.e., if the head is correct) and 0 otherwise.

UAS focuses solely on the accuracy of head assignments without considering dependency labels.

---

### 2. **Labeled Attachment Score (LAS)**  
Labeled Attachment Score (LAS) measures the percentage of tokens in a sentence that have both the correct syntactic head and the correct dependency label.

The LAS is calculated as:
\[
\text{LAS} = \frac{\sum_{i=1}^{N} \delta(h_i = \hat{h}_i \, \text{and} \, l_i = \hat{l}_i)}{N}
\]
where:
- \( h_i \) and \( \hat{h}_i \) are the heads of the \( i \)-th token in the predicted and reference parses, respectively.
- \( l_i \) and \( \hat{l}_i \) are the dependency labels for the \( i \)-th token in the predicted and reference parses, respectively.
- \( \delta(h_i = \hat{h}_i \, \text{and} \, l_i = \hat{l}_i) \) is an indicator function that equals 1 if both the head and label are correct and 0 otherwise.

LAS combines accuracy of both head and label assignments, providing a more stringent measure than UAS.

---

### 3. **Complete Match**  
Complete Match measures the fraction of sentences in which all dependencies (both heads and labels) are correctly predicted, indicating perfectly parsed sentences.

For a batch with \( M \) sentences, Complete Match is calculated as:
\[
\text{Complete Match} = \frac{\sum_{j=1}^{M} \delta(\text{sentence}_j \, \text{is completely correct})}{M}
\]
where:
- \( \delta(\text{sentence}_j \, \text{is completely correct}) \) is 1 if all heads and labels in sentence \( j \) are correct, and 0 otherwise.

Complete Match provides an overall measure of parsing accuracy on a sentence level, showing the proportion of fully accurate parses in the batch. 

---

These metrics provide comprehensive insight into the quality of dependency parsing, from token-level head assignments to sentence-level accuracy of complete parses.