codebook-lab 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- codebook_lab/__init__.py +69 -0
- codebook_lab/annotate.py +742 -0
- codebook_lab/examples.py +87 -0
- codebook_lab/experiments.py +319 -0
- codebook_lab/metrics.py +1422 -0
- codebook_lab/ollama.py +117 -0
- codebook_lab/prompts.py +146 -0
- codebook_lab/py.typed +0 -0
- codebook_lab/tasks/__init__.py +1 -0
- codebook_lab/tasks/policy-sentiment/codebook.json +42 -0
- codebook_lab/tasks/policy-sentiment/ground-truth.csv +21 -0
- codebook_lab/types.py +116 -0
- codebook_lab-1.0.0.dist-info/METADATA +338 -0
- codebook_lab-1.0.0.dist-info/RECORD +17 -0
- codebook_lab-1.0.0.dist-info/WHEEL +5 -0
- codebook_lab-1.0.0.dist-info/licenses/LICENSE +661 -0
- codebook_lab-1.0.0.dist-info/top_level.txt +1 -0
codebook_lab/__init__.py
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from importlib import import_module
|
|
4
|
+
from importlib.metadata import PackageNotFoundError, version
|
|
5
|
+
from typing import TYPE_CHECKING, Any
|
|
6
|
+
|
|
7
|
+
from .examples import copy_example_task, get_example_task_dir, get_example_task_files, list_example_tasks
|
|
8
|
+
from .ollama import ensure_ollama_available, ensure_ollama_model, get_ollama_base_url
|
|
9
|
+
from .prompts import (
|
|
10
|
+
PromptContext,
|
|
11
|
+
get_prompt_wrapper,
|
|
12
|
+
list_prompt_wrappers,
|
|
13
|
+
register_prompt_wrapper,
|
|
14
|
+
)
|
|
15
|
+
from .types import AnnotationRunResult, ExperimentRunResult, ExperimentSpec, MetricsRunResult
|
|
16
|
+
|
|
17
|
+
if TYPE_CHECKING:
|
|
18
|
+
from .annotate import run_annotation
|
|
19
|
+
from .experiments import expand_param_grid, resolve_task_dir, run_experiment, run_experiment_grid
|
|
20
|
+
from .metrics import run_metrics
|
|
21
|
+
|
|
22
|
+
try:
|
|
23
|
+
__version__ = version("codebook-lab")
|
|
24
|
+
except PackageNotFoundError:
|
|
25
|
+
__version__ = "0.0.0"
|
|
26
|
+
|
|
27
|
+
_LAZY_EXPORTS = {
|
|
28
|
+
"expand_param_grid": (".experiments", "expand_param_grid"),
|
|
29
|
+
"resolve_task_dir": (".experiments", "resolve_task_dir"),
|
|
30
|
+
"run_annotation": (".annotate", "run_annotation"),
|
|
31
|
+
"run_experiment": (".experiments", "run_experiment"),
|
|
32
|
+
"run_experiment_grid": (".experiments", "run_experiment_grid"),
|
|
33
|
+
"run_metrics": (".metrics", "run_metrics"),
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
__all__ = [
|
|
37
|
+
"PromptContext",
|
|
38
|
+
"AnnotationRunResult",
|
|
39
|
+
"ExperimentRunResult",
|
|
40
|
+
"ExperimentSpec",
|
|
41
|
+
"MetricsRunResult",
|
|
42
|
+
"copy_example_task",
|
|
43
|
+
"ensure_ollama_available",
|
|
44
|
+
"ensure_ollama_model",
|
|
45
|
+
"expand_param_grid",
|
|
46
|
+
"get_example_task_dir",
|
|
47
|
+
"get_example_task_files",
|
|
48
|
+
"get_ollama_base_url",
|
|
49
|
+
"get_prompt_wrapper",
|
|
50
|
+
"list_example_tasks",
|
|
51
|
+
"list_prompt_wrappers",
|
|
52
|
+
"register_prompt_wrapper",
|
|
53
|
+
"resolve_task_dir",
|
|
54
|
+
"run_annotation",
|
|
55
|
+
"run_experiment",
|
|
56
|
+
"run_experiment_grid",
|
|
57
|
+
"run_metrics",
|
|
58
|
+
]
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def __getattr__(name: str) -> Any:
|
|
62
|
+
"""Load heavier runtime modules only when their exports are requested."""
|
|
63
|
+
if name not in _LAZY_EXPORTS:
|
|
64
|
+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
|
65
|
+
|
|
66
|
+
module_name, attr_name = _LAZY_EXPORTS[name]
|
|
67
|
+
value = getattr(import_module(module_name, __name__), attr_name)
|
|
68
|
+
globals()[name] = value
|
|
69
|
+
return value
|