Download example.py from zeechimp/hv-temporal-context-v1: direct link, hf CLI and curl.
- Browser
- Download file 1.43 kB
-
https://huggingface.co/zeechimp/hv-temporal-context-v1/resolve/main/example.py
- Command line
-
hf download hf://zeechimp/hv-temporal-context-v1/example.py
-
curl -L -o example.py https://huggingface.co/zeechimp/hv-temporal-context-v1/resolve/main/example.py
1.43 kB
| """ | |
| example.py | |
| Minimal usage example for hv-temporal-context. | |
| """ | |
| from hv_temporal_context import HVTemporalContext | |
| def main(): | |
| model = HVTemporalContext.load("temporal_context_model") | |
| queries = [ | |
| ("what is the forecast for rome", "weather"), | |
| ("how do i debug a python function", "coding"), | |
| ("how much did i spend on groceries", "finance"), | |
| ("how do i cook soup", "cooking"), | |
| ] | |
| print("Pure similarity retrieval:") | |
| print() | |
| for q, _ in queries: | |
| idx, scores = model.retrieve(q, k=3) | |
| print(f" {q}") | |
| for i, (j, s) in enumerate(zip(idx, scores)): | |
| print(f" top{i+1} [{model.topics[j]:<10}] sim={s:.3f}") | |
| print() | |
| print("Position-conditional retrieval (with topic hint):") | |
| print() | |
| for q, topic in queries: | |
| idx, scores = model.retrieve_temporal(q, topic, k=3) | |
| print(f" {q} (hint: {topic})") | |
| for i, (j, s) in enumerate(zip(idx, scores)): | |
| print(f" top{i+1} [{model.topics[j]:<10}] sim={s:.3f}") | |
| print() | |
| print("Topic-shift detection:") | |
| print() | |
| boundaries = model.topic_boundaries() | |
| print(f" detected boundaries at positions: {boundaries[:10]}") | |
| print(f" total boundaries: {len(boundaries)}") | |
| print(f" median surprise magnitude: " | |
| f"{float(__import__('numpy').median(model.surprise_mags)):.3f}") | |
| if __name__ == "__main__": | |
| main() |