Download example.py from zeechimp/hv-split: direct link, hf CLI and curl.
- Browser
- Download file 1.91 kB
-
https://huggingface.co/zeechimp/hv-split/resolve/main/example.py
- Command line
-
hf download hf://zeechimp/hv-split/example.py
-
curl -L -o example.py https://huggingface.co/zeechimp/hv-split/resolve/main/example.py
1.91 kB
| """ | |
| Minimal usage example for hv-split. | |
| python example.py | |
| Splits eight queries with different ambiguity sources, shows the bundle | |
| structure, and demonstrates answer_each with a mock callback. | |
| """ | |
| from hv_split import HVInterpret | |
| QUERIES = [ | |
| ("lexical", "I need to access the bank"), | |
| ("referential", | |
| "She told her that the manager had changed it, and it broke"), | |
| ("scope", "All that glitters is not gold"), | |
| ("presuppositional", "Why did the CEO resign last week?"), | |
| ("framing", | |
| "in the language of category theory, what is an identity?"), | |
| ("temporal", "recently, has the function changed?"), | |
| ("multi-source", | |
| "why did the current bank say recently that the function she used " | |
| "in the language of category theory had changed?"), | |
| ("clean", "compute 2 + 2"), | |
| ] | |
| def main() -> None: | |
| m = HVInterpret() | |
| print("=" * 78) | |
| print("Bundle summary") | |
| print("=" * 78) | |
| print(f" {'name':<16} {'ambig':>7} {'conf':>6} {'n':>3} sources") | |
| print(" " + "-" * 70) | |
| for name, q in QUERIES: | |
| b = m.split(q) | |
| srcs = ", ".join(b.sources) or "(none)" | |
| print( | |
| f" {name:<16} {b.ambiguity_score:>7.3f} " | |
| f"{b.confidence:>6.3f} {b.n_interpretations:>3} {srcs}" | |
| ) | |
| print() | |
| print("=" * 78) | |
| print("Full bundle: multi-source query") | |
| print("=" * 78) | |
| b = m.split(QUERIES[6][1]) | |
| print(m.render(b)) | |
| print("=" * 78) | |
| print("answer_each with a mock callback") | |
| print("=" * 78) | |
| for interp, answer in m.answer_each( | |
| QUERIES[0][1], | |
| lambda q, i: f"[would answer as: {i.reading}]", | |
| ): | |
| print(f" prior {interp.prior:.3f} -> {answer}") | |
| print() | |
| print("=" * 78) | |
| print("JSON output (presuppositional query)") | |
| print("=" * 78) | |
| print(m.render(m.split(QUERIES[3][1]), mode="json")) | |
| if __name__ == "__main__": | |
| main() |