trismik 0.9.1__tar.gz → 0.9.4__tar.gz

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.
trismik-0.9.4/PKG-INFO ADDED
@@ -0,0 +1,172 @@
1
+ Metadata-Version: 2.3
2
+ Name: trismik
3
+ Version: 0.9.4
4
+ Summary:
5
+ Author: Bartosz Kielczewski
6
+ Author-email: bk352@cam.ac.uk
7
+ Requires-Python: >=3.9
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Programming Language :: Python :: 3.9
10
+ Classifier: Programming Language :: Python :: 3.10
11
+ Classifier: Programming Language :: Python :: 3.11
12
+ Classifier: Programming Language :: Python :: 3.12
13
+ Classifier: Programming Language :: Python :: 3.13
14
+ Provides-Extra: examples
15
+ Requires-Dist: accelerate (>=1.7.0,<2.0.0) ; extra == "examples"
16
+ Requires-Dist: notebook (>=7.4.4,<8.0.0) ; extra == "examples"
17
+ Requires-Dist: openai (>=1.81.0,<2.0.0) ; extra == "examples"
18
+ Requires-Dist: torch (>=2.7.0,<3.0.0) ; extra == "examples"
19
+ Requires-Dist: torchaudio (>=2.7.0,<3.0.0) ; extra == "examples"
20
+ Requires-Dist: torchvision (>=0.22.0,<1.0.0) ; extra == "examples"
21
+ Requires-Dist: transformers (>=4.51.3,<5.0.0) ; extra == "examples"
22
+ Description-Content-Type: text/markdown
23
+
24
+ <h1 align="center"> Trismik SDK</h1>
25
+
26
+ <p align="center">
27
+ <img alt="PyPI - Version" src="https://img.shields.io/pypi/v/trismik">
28
+ <img alt="Python Version" src="https://img.shields.io/badge/python-3.9%2B-blue">
29
+ <img alt="License" src="https://img.shields.io/badge/license-MIT-green">
30
+ </p>
31
+
32
+ ## Table of Contents
33
+ - [Overview](#overview)
34
+ - [Quick Start](#quick-start)
35
+ - [Installation](#installation)
36
+ - [API Key Setup](#api-key-setup)
37
+ - [Basic Usage](#basic-usage)
38
+ - [Interpreting Results](#interpreting-results)
39
+ - [Theta (θ)](#theta-θ)
40
+ - [Other Metrics](#other-metrics)
41
+ - [Contributing](#contributing)
42
+ - [License](#license)
43
+
44
+ ## Overview
45
+
46
+ [**Trismik**](https://trismik.com) is a Cambridge, UK based startup offering adversarial testing for LLMs. The APIs we provide through this library allow you to call our adaptive test engine and evaluate LLMs up to 95% faster (and cheaper!) than traditional evaluation techniques.
47
+
48
+ Our **adaptive testing** algorithm allows to estimate the precision of the model by looking only at a small portion of a dataset. Through this library, we provide access to a number of open source datasets over several dimensions (reasoning, toxicity, tool use...) to speed up model testing in several scenarios, like foundation model training, supervised fine tuning, prompt engineering, and so on.
49
+
50
+ ## Quick Start
51
+
52
+ ### Installation
53
+
54
+ To use our API, you need to get an API key first. Please register on [dashboard.trismik.com](https://dashboard.trismik.com) and obtain an API key.
55
+
56
+ Trismik is available via [pypi](https://pypi.org/project/trismik/). To install Trismik, run the following in your terminal (in a virtualenv, if you use one):
57
+
58
+ ```bash
59
+ pip install trismik
60
+ ```
61
+
62
+ ### API Key Setup
63
+
64
+ You can provide your API key in one of the following ways:
65
+
66
+ 1. **Environment Variable**:
67
+ ```bash
68
+ export TRISMIK_API_KEY="your-api-key"
69
+ ```
70
+
71
+ 2. **`.env` File**:
72
+ ```bash
73
+ # .env
74
+ TRISMIK_API_KEY=your-api-key
75
+ ```
76
+ Then load it with `python-dotenv`:
77
+ ```python
78
+ from dotenv import load_dotenv
79
+ load_dotenv()
80
+ ```
81
+
82
+ 3. **Direct Initialization**:
83
+ ```python
84
+ client = TrismikAsyncClient(api_key="YOUR_API_KEY")
85
+ ```
86
+
87
+ ### Basic Usage
88
+
89
+ Running a test is straightforward:
90
+
91
+ 1. Implement a method that wraps model inference over a dataset item
92
+ 2. Create an `AdaptiveTest` instance
93
+ 3. Run the test!
94
+
95
+ Here's a basic example:
96
+
97
+ ```python
98
+ def model_inference(item: TrismikItem) -> Any:
99
+ model_output = ... # call your model here
100
+ return model_output
101
+
102
+
103
+ # Initialize the test runner
104
+ runner = AdaptiveTest(model_inference)
105
+
106
+ # Run the test
107
+ results = await runner.run_async(
108
+ "MMLUPro2025", # or any dataset we support
109
+ with_responses=True,
110
+ run_metadata=sample_metadata,
111
+ )
112
+
113
+ # Print the test output
114
+ for result in results:
115
+ print(f"{result.trait} ({result.name}): {result.value}")
116
+ ```
117
+
118
+ ### Examples
119
+
120
+ You can find more examples in the `examples` folder:
121
+ - [`example_transformers.py`](examples/example_transformers.py) - Example using Hugging Face Transformers models
122
+ - [`example_openai.py`](examples/example_openai.py) - Example using OpenAI models
123
+ - [`example_adaptive_test.py`](examples/example_adaptive_test.py) - Example of adaptive testing configuration
124
+
125
+ To run the examples, you will need to clone this repo, navigate to the
126
+ source folder, and then run:
127
+
128
+ ```bash
129
+ poetry install --with examples
130
+ poetry run python examples/example_adaptive_test.py # or any other example
131
+ ```
132
+
133
+ ## Interpreting Results
134
+
135
+ ### Theta (θ)
136
+
137
+ Our adversarial test returns several values; however, you will be interested mainly in `theta`. Theta ($\theta$) is our metric; it measures the ability of the model on a certain dataset, and it can be used as a proxy to approximate the original metric used on that dataset. For example, on an accuracy-based dataset, a high theta correlates with a high accuracy, and low theta correlates with low accuracy.
138
+
139
+ To interpret a theta score, consider that $\theta=0$ corresponds to a 50% chance for a model to get an answer right - in other words, to an accuracy of 50%.
140
+ A negative theta means that the model will give more bad answers then good ones, while a positive theta means that the model will give more good answers then bad answers.
141
+ While theta is unbounded in our implementation (i.e. $-\infty < \theta < \infty$), in practice we have that for most cases $\theta$ will take values between -3 and 3.
142
+
143
+ Compared to classical benchmark testing, the estimated accuracy from adaptive testing uses fewer but more informative items while avoiding noise from overly easy or difficult questions. This makes it a more efficient and stable measure, especially on very large datasets.
144
+
145
+ ### Other Metrics
146
+
147
+ - **Standard Deviation (`std`)**:
148
+ - A measure of the uncertainty or error in the theta estimate
149
+ - A smaller `std` indicates a more precise estimate
150
+ - You should see a `std` around or below 0.25
151
+
152
+ - **Correct Responses (`responsesCorrect`)**:
153
+ - The number of correct answers delivered by the model
154
+
155
+ - **Important note**: A higher number of correct answers does not necessarily
156
+ correlate with a high theta. Our algorithm navigates the dataset to find a
157
+ balance of “hard” and “easy” items for your model, so by the end of the test,
158
+ it encounters a representative mix of inputs it can and cannot handle. In
159
+ practice, expect responsesCorrect to be roughly half of responsesTotal.
160
+
161
+ - **Total Responses (`responsesTotal`)**:
162
+ - The number of items processed before reaching a stable theta.
163
+ - Expected range: 60 ≤ responses_total ≤ 80
164
+
165
+ ## Contributing
166
+
167
+ See `CONTRIBUTING.md`.
168
+
169
+ ## License
170
+
171
+ This library is licensed under the MIT license. See `LICENSE` file.
172
+
@@ -0,0 +1,148 @@
1
+ <h1 align="center"> Trismik SDK</h1>
2
+
3
+ <p align="center">
4
+ <img alt="PyPI - Version" src="https://img.shields.io/pypi/v/trismik">
5
+ <img alt="Python Version" src="https://img.shields.io/badge/python-3.9%2B-blue">
6
+ <img alt="License" src="https://img.shields.io/badge/license-MIT-green">
7
+ </p>
8
+
9
+ ## Table of Contents
10
+ - [Overview](#overview)
11
+ - [Quick Start](#quick-start)
12
+ - [Installation](#installation)
13
+ - [API Key Setup](#api-key-setup)
14
+ - [Basic Usage](#basic-usage)
15
+ - [Interpreting Results](#interpreting-results)
16
+ - [Theta (θ)](#theta-θ)
17
+ - [Other Metrics](#other-metrics)
18
+ - [Contributing](#contributing)
19
+ - [License](#license)
20
+
21
+ ## Overview
22
+
23
+ [**Trismik**](https://trismik.com) is a Cambridge, UK based startup offering adversarial testing for LLMs. The APIs we provide through this library allow you to call our adaptive test engine and evaluate LLMs up to 95% faster (and cheaper!) than traditional evaluation techniques.
24
+
25
+ Our **adaptive testing** algorithm allows to estimate the precision of the model by looking only at a small portion of a dataset. Through this library, we provide access to a number of open source datasets over several dimensions (reasoning, toxicity, tool use...) to speed up model testing in several scenarios, like foundation model training, supervised fine tuning, prompt engineering, and so on.
26
+
27
+ ## Quick Start
28
+
29
+ ### Installation
30
+
31
+ To use our API, you need to get an API key first. Please register on [dashboard.trismik.com](https://dashboard.trismik.com) and obtain an API key.
32
+
33
+ Trismik is available via [pypi](https://pypi.org/project/trismik/). To install Trismik, run the following in your terminal (in a virtualenv, if you use one):
34
+
35
+ ```bash
36
+ pip install trismik
37
+ ```
38
+
39
+ ### API Key Setup
40
+
41
+ You can provide your API key in one of the following ways:
42
+
43
+ 1. **Environment Variable**:
44
+ ```bash
45
+ export TRISMIK_API_KEY="your-api-key"
46
+ ```
47
+
48
+ 2. **`.env` File**:
49
+ ```bash
50
+ # .env
51
+ TRISMIK_API_KEY=your-api-key
52
+ ```
53
+ Then load it with `python-dotenv`:
54
+ ```python
55
+ from dotenv import load_dotenv
56
+ load_dotenv()
57
+ ```
58
+
59
+ 3. **Direct Initialization**:
60
+ ```python
61
+ client = TrismikAsyncClient(api_key="YOUR_API_KEY")
62
+ ```
63
+
64
+ ### Basic Usage
65
+
66
+ Running a test is straightforward:
67
+
68
+ 1. Implement a method that wraps model inference over a dataset item
69
+ 2. Create an `AdaptiveTest` instance
70
+ 3. Run the test!
71
+
72
+ Here's a basic example:
73
+
74
+ ```python
75
+ def model_inference(item: TrismikItem) -> Any:
76
+ model_output = ... # call your model here
77
+ return model_output
78
+
79
+
80
+ # Initialize the test runner
81
+ runner = AdaptiveTest(model_inference)
82
+
83
+ # Run the test
84
+ results = await runner.run_async(
85
+ "MMLUPro2025", # or any dataset we support
86
+ with_responses=True,
87
+ run_metadata=sample_metadata,
88
+ )
89
+
90
+ # Print the test output
91
+ for result in results:
92
+ print(f"{result.trait} ({result.name}): {result.value}")
93
+ ```
94
+
95
+ ### Examples
96
+
97
+ You can find more examples in the `examples` folder:
98
+ - [`example_transformers.py`](examples/example_transformers.py) - Example using Hugging Face Transformers models
99
+ - [`example_openai.py`](examples/example_openai.py) - Example using OpenAI models
100
+ - [`example_adaptive_test.py`](examples/example_adaptive_test.py) - Example of adaptive testing configuration
101
+
102
+ To run the examples, you will need to clone this repo, navigate to the
103
+ source folder, and then run:
104
+
105
+ ```bash
106
+ poetry install --with examples
107
+ poetry run python examples/example_adaptive_test.py # or any other example
108
+ ```
109
+
110
+ ## Interpreting Results
111
+
112
+ ### Theta (θ)
113
+
114
+ Our adversarial test returns several values; however, you will be interested mainly in `theta`. Theta ($\theta$) is our metric; it measures the ability of the model on a certain dataset, and it can be used as a proxy to approximate the original metric used on that dataset. For example, on an accuracy-based dataset, a high theta correlates with a high accuracy, and low theta correlates with low accuracy.
115
+
116
+ To interpret a theta score, consider that $\theta=0$ corresponds to a 50% chance for a model to get an answer right - in other words, to an accuracy of 50%.
117
+ A negative theta means that the model will give more bad answers then good ones, while a positive theta means that the model will give more good answers then bad answers.
118
+ While theta is unbounded in our implementation (i.e. $-\infty < \theta < \infty$), in practice we have that for most cases $\theta$ will take values between -3 and 3.
119
+
120
+ Compared to classical benchmark testing, the estimated accuracy from adaptive testing uses fewer but more informative items while avoiding noise from overly easy or difficult questions. This makes it a more efficient and stable measure, especially on very large datasets.
121
+
122
+ ### Other Metrics
123
+
124
+ - **Standard Deviation (`std`)**:
125
+ - A measure of the uncertainty or error in the theta estimate
126
+ - A smaller `std` indicates a more precise estimate
127
+ - You should see a `std` around or below 0.25
128
+
129
+ - **Correct Responses (`responsesCorrect`)**:
130
+ - The number of correct answers delivered by the model
131
+
132
+ - **Important note**: A higher number of correct answers does not necessarily
133
+ correlate with a high theta. Our algorithm navigates the dataset to find a
134
+ balance of “hard” and “easy” items for your model, so by the end of the test,
135
+ it encounters a representative mix of inputs it can and cannot handle. In
136
+ practice, expect responsesCorrect to be roughly half of responsesTotal.
137
+
138
+ - **Total Responses (`responsesTotal`)**:
139
+ - The number of items processed before reaching a stable theta.
140
+ - Expected range: 60 ≤ responses_total ≤ 80
141
+
142
+ ## Contributing
143
+
144
+ See `CONTRIBUTING.md`.
145
+
146
+ ## License
147
+
148
+ This library is licensed under the MIT license. See `LICENSE` file.
@@ -0,0 +1,90 @@
1
+ [project]
2
+ name = "trismik"
3
+ dynamic = []
4
+ description = ""
5
+ authors = [
6
+ { name = "Bartosz Kielczewski", email = "bk352@cam.ac.uk" },
7
+ { name = "Peter Monks", email = "peter.monks@systemc.com" },
8
+ { name = "Greg Holdridge", email = "greg.holdridge@systemc.com" },
9
+ { name = "Marco Basaldella", email = "marco@trismik.com" }
10
+ ]
11
+ readme = "README.md"
12
+ requires-python = ">=3.9"
13
+ version = "0.9.4"
14
+
15
+ [project.optional-dependencies]
16
+ examples = [
17
+ "transformers>=4.51.3,<5.0.0",
18
+ "torch>=2.7.0,<3.0.0",
19
+ "torchvision>=0.22.0,<1.0.0",
20
+ "torchaudio>=2.7.0,<3.0.0",
21
+ "accelerate>=1.7.0,<2.0.0",
22
+ "openai>=1.81.0,<2.0.0",
23
+ "notebook>=7.4.4,<8.0.0"
24
+ ]
25
+
26
+
27
+ [tool.poetry]
28
+ packages = [{ include = "trismik", from = "src" }]
29
+
30
+ [tool.poetry.requires-plugins]
31
+ poetry-dynamic-versioning = { version = ">=1.0.0,<2.0.0", extras = ["plugin"] }
32
+
33
+ [tool.poetry.group.main.dependencies]
34
+ httpx = "^0.27.2"
35
+ nest-asyncio = "^1.6.0"
36
+ tqdm = "^4.67.1"
37
+
38
+
39
+
40
+ [tool.poetry.group.dev.dependencies]
41
+ pytest = "^8.3.2"
42
+ python-dotenv = "^1.0.1"
43
+ pytest-asyncio = "^0.24.0"
44
+ pre-commit = "^3.6.2"
45
+ black = "^24.3.0"
46
+ isort = "^5.13.2"
47
+ Flake8-pyproject = "^1.2.3"
48
+ flake8 = "^7.0.0"
49
+ mypy = "^1.15.0"
50
+ autoflake = "^2.3.1"
51
+
52
+ [tool.poetry-dynamic-versioning]
53
+ # Expected Git tags: vX.Y.Z, vX.Y.Z-alphaN, vX.Y.Z-betaN, vX.Y.Z-rcN
54
+ enable = false
55
+ vcs = "git"
56
+
57
+ [build-system]
58
+ requires = ["poetry-core>=1.0.0", "poetry-dynamic-versioning>=1.0.0,<2.0.0"]
59
+ build-backend = "poetry_dynamic_versioning.backend"
60
+
61
+ [tool.pytest.ini_options]
62
+ asyncio_default_fixture_loop_scope = "class"
63
+
64
+ [tool.black]
65
+ line-length = 80
66
+ target-version = ['py39']
67
+ include = '\.pyi?$'
68
+
69
+ [tool.isort]
70
+ profile = "black"
71
+ line_length = 80
72
+ multi_line_output = 3
73
+
74
+ [tool.mypy]
75
+ python_version = "3.9"
76
+ warn_return_any = true
77
+ warn_unused_configs = true
78
+ disallow_untyped_defs = true
79
+ disallow_incomplete_defs = true
80
+ check_untyped_defs = true
81
+ disallow_untyped_decorators = true
82
+ no_implicit_optional = true
83
+ warn_redundant_casts = true
84
+ warn_unused_ignores = true
85
+ warn_no_return = true
86
+ warn_unreachable = true
87
+ install_types = true
88
+
89
+ [tool.flake8] # note that this depends on Flake8-pyproject
90
+ ignore = ["D202", "W503", "W504"]
@@ -0,0 +1,10 @@
1
+ """
2
+ Trismik Python Client.
3
+
4
+ A Python client for the Trismik API.
5
+ """
6
+
7
+ import importlib.metadata
8
+
9
+ # get version from pyproject.toml
10
+ __version__ = importlib.metadata.version(__package__ or __name__)