Skip to content

Commit

Permalink
Merge pull request #9 from logikon-ai/v0.2.0
Browse files Browse the repository at this point in the history
v0.2.0
  • Loading branch information
ggbetz authored Aug 28, 2024
2 parents dd8dc3e + fcf951f commit 27020d6
Show file tree
Hide file tree
Showing 122 changed files with 7,796 additions and 41,550 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ venv.bak/
.dmypy.json
dmypy.json

# ruff
.ruff_cache

# Pyre type checker
.pyre/

Expand Down
862 changes: 661 additions & 201 deletions LICENSE

Large diffs are not rendered by default.

238 changes: 91 additions & 147 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,183 +5,127 @@

# Logikon

Analytics for LLM Reasoning Traces.
*AI Analytics for Natural Language Reasoning.*

[Highlights](#highlights)
[Analytics](#analytics)
[Examples](#examples)
[Stay tuned](#stay-tuned-for)
Docs 🚧
[Guided Reasoning™️ Demo](https://huggingface.co/spaces/logikon/benjamin-chat) | Technical Report (coming soon)

</div>

> [!NOTE]
> 🎉&nbsp; We're excited to announce the release of `Logikon 0.2.0` –– a major update to our analytics toolbox for natural-language reasoning.
**Logikon `/\/`** is a library for analyzing and scoring the quality of plain-text reasoning traces produced by LLMs (or humans). It reveals the argumentative structure of LLM outputs, visualizes reasoning complexity, and evaluates its quality.
Main changes:

**Logikon `/\/`** allows you to automatically supervise the AI agents in your advanced LLM apps. This can be used for debugging and monitoring your AI assistants, or for evaluating the quality of human–AI interaction.
* All LLM-based argument analysis pipelines are now built with _LCEL/LangChain_ (and not with LMQL anymore).
* We're introducing _Guided Reasoning™️_ (abstract interface and simple implementations) for walking arbitrary conversational AI agents through complex reasoning processes.
* AGPL license.

**Logikon `/\/`** is highly customizable and extensible. You can choose from a variety of metrics, artifacts, and evaluation methods, pick an expert LLM for logical analysis, and even build your own metrics on top of **Logikon**'s artifacts.
Our *short-term priorities* are housekeeping, code cleaning, and documentation. Don't hesitate to reach out if you have any questions or feedback, or if you'd like to contribute to the project.


> [!WARNING]
> **Logikon `/\/`** is currently in early beta. The API is subject to change. Please be patient, and report any issues you encounter.
## Installation

## Installation

```sh
pip install git+https://github.com/logikon-ai/[email protected]
```

See [examples folder](./examples) for more details.

## Highlights

### Analyze and score completions with one extra line of code

```python
# LLM generation
prompt = "Vim or Emacs? Reason carefully before submitting your choice."
completion = llm.predict(prompt)

# Analyze and score reasoning 🚀
import logikon

score = logikon.score(prompt=prompt, completion=completion)

# >>> print(score.info())
# argmap_size: 13
# n_root_nodes: 3
# global_balance: -.23
pip install git+https://github.com/logikon-ai/[email protected]
```


### Configure metrics, artifacts and evaluation methods
## Basic usage

```python
import logikon

# Configure scoring methods
config = logikon.ScoreConfig(
expert_model = "code-davinci-002", # expert LLM for logical analysis
metrics = ["argmap_attack_ratio"], # ratio of objections
artifacts = ["svg_argmap"], # argument map as svg
import os
from logikon import ascore, ScoreConfig

# 🔧 config
config = ScoreConfig(
global_kwargs={
"expert_model": "meta-llama/Meta-Llama-3-70B-Instruct",
"inference_server_url": "https://api-inference.huggingface.co/models/meta-llama/Meta-Llama-3-70B-Instruct",
"llm_backend": "HFChat",
"api_key": os.environ["HF_TOKEN"],
"classifier_kwargs": {
"model_id": "MoritzLaurer/DeBERTa-v3-base-mnli-fever-anli",
"inference_server_url": "https://api-inference.huggingface.co/models/MoritzLaurer/DeBERTa-v3-base-mnli-fever-anli",
"api_key": os.environ["HF_TOKEN"],
"batch_size": 8,
},
}
)

# LLM generation
...
# 📝 input to evaluate
issue = "Should I eat animals?",
reasoning = "No! Animals can suffer. Animal farming causes climate heating. Meat is not healthy.",

# Debug and score reasoning
score = logikon.score(config=config, prompt=prompt, completion=completion)
# 🏃‍♀️ run argument analysis
result = await ascore(
prompt = issue,
completion = reasoning,
config = config,
)
```

## Analytics


### Argumentation quantity metrics

Score the quantity of arguments in the reasoning trace.

* [x] number of arguments
* [x] number of central claims
* [x] density of argumentation network
* [x] mean strength of arguments

> **🤔 What for?**
>
> 👉 Detect where your LLM fails to generate (sufficiently many) reasons when deliberating a decision or justifying an answer it has given—which may lead to poor AI decision-making and undermine AI explainability.

### Argumentative bias metrics

Score the balance of arguments in the reasoning trace.

* [x] mean support/attack bias averaged over all central claims
* [x] global support/attack balance
* [x] naive pros/cons ratio

> **🤔 What for?**
>
> 👉 Detect whether your (recently updated) advanced LLM app suddenly produces biased reasoning—which may indicate flawed reasoning that reduces your app's performance.
### Argumentation clarity metrics 🚧

Score the presentation of arguments in the reasoning trace.

* [ ] transparency of exposition
* [ ] redundancy of presentation
* [ ] ambiguity of argument articulation
* [ ] veracity of surface logical structure

> **🤔 What for?**
>
> 👉 Detect whether your LLM fails to render its reasoning in comprehensible ways—which may impair human-AI interaction, or prevent other AI agents from taking the reasoning fully into account.

For more technical info on our metrics, see our [Critical Thinking Zoo notebook](./examples/metrics_artifacts_zoo.ipynb) and the code's [analyst registry](https://github.com/logikon-ai/logikon/blob/eaa41db5763ce8aca24818fd3130078b20d8ed90/src/logikon/analysts/registry.py#L30).


### Argument mapping artifacts

Reveal, represent or visualize the argumentation, based on a charitable and systematic reconstruction of the reasoning trace.

- [x] pros and cons list
- [x] ✨fuzzy✨ argument map
- [x] argument map as svg
- [x] nested pros cons sunburst

> **🤔 What for?**
>
> 👉 Check visualizations rather then read lengthy reasoning traces when debugging your LLM app. <br/>
> 👉 Build your own metrics and evaluations exploiting the deep structure revealed by our artifacts.


### Argumentative text annotation artifacts 🚧

Annotate reasons, arguments and argumentative relations in LLM-generated argumentative texts.

- [ ] argumentative entity annotation
- [ ] argumentative relation annotation


> **🤔 What for?**
>
> 👉 Check visualizations rather then read lengthy reasoning traces when debugging your LLM app. <br/>
> 👉 Build your own metrics and evaluations exploiting our annotations of LLM-generated texts.


For more technical info on our artifacts, see our [Critical Thinking Zoo notebook](./examples/metrics_artifacts_zoo.ipynb) and the code's [analyst registry](https://github.com/logikon-ai/logikon/blob/eaa41db5763ce8aca24818fd3130078b20d8ed90/src/logikon/analysts/registry.py#L30).


## Examples

* [Quickstart](./examples/quickstart.ipynb)
* [Metrics & Artifacts Gallery](./examples/metrics_artifacts_zoo.ipynb)
* [Monitor Advanced CoT App](./examples/monitor_cot_workflow.ipynb)
* [Detect Legal Hallucinations](./examples/legal_hallucination_detection.ipynb)
* ...
## Guided Reasoning™️

```mermaid
sequenceDiagram
autonumber
actor User
participant C as Client LLM
User->>+C: Problem statement
create participant G as Guide LLM
C->>+G: Problem statement
loop
G->>+C: Instructions...
C->>+G: Reasoning traces...
G->>+G: Evaluation
end
destroy G
G->>+C: Answer + Protocol
C->>+User: Answer (and Protocol)
User->>+C: Why?
C->>+User: Explanation (based on Protocol)
```

See [examples folder](./examples) for details and more.
<!--
## Quickstart
Start server.
## Known limitations
```sh
bash scripts/run_vllm_server.sh
```
* Ability to correctly relate individual reasons to each other scales with model size and is severely limited for 7B expert models.
* ...
Run python client.
## Stay tuned for
```python
from logikon import ascore
await ascore(
prompt="What are the main reasons for spending a week-end in New York?",
completion="""
The main reasons for spending a week-end in New York are:
1. You can do great shopping.
2. You can eat wonderful food.
3. You can meet many interesting people and friends.
"""
)
```
* More examples [#1](https://github.com/logikon-ai/logikon/issues/1)
* Integrations with MLOps tools [#2](https://github.com/logikon-ai/logikon/issues/2)
* Model benchmarks and validation
* More metrics and artifacts
* Speedups and optimizations
* **Logikon `/\/` Cloud**
## Development
```sh
# style check
hatch run lint:style
# format code
hatch run lint:fmt
# check types (mypy)
hatch run lint:typing
# run tests
hatch run test
```
-->


7 changes: 0 additions & 7 deletions docs/api-docs/index.html

This file was deleted.

260 changes: 0 additions & 260 deletions docs/api-docs/logikon.html

This file was deleted.

269 changes: 0 additions & 269 deletions docs/api-docs/logikon/__about__.html

This file was deleted.

261 changes: 0 additions & 261 deletions docs/api-docs/logikon/analysts.html

This file was deleted.

833 changes: 0 additions & 833 deletions docs/api-docs/logikon/analysts/base.html

This file was deleted.

831 changes: 0 additions & 831 deletions docs/api-docs/logikon/analysts/director.html

This file was deleted.

255 changes: 0 additions & 255 deletions docs/api-docs/logikon/analysts/export.html

This file was deleted.

723 changes: 0 additions & 723 deletions docs/api-docs/logikon/analysts/export/htmlsunburst_exporter.html

This file was deleted.

537 changes: 0 additions & 537 deletions docs/api-docs/logikon/analysts/export/networkx_exporter.html

This file was deleted.

682 changes: 0 additions & 682 deletions docs/api-docs/logikon/analysts/export/svgmap_exporter.html

This file was deleted.

518 changes: 0 additions & 518 deletions docs/api-docs/logikon/analysts/interface.html

This file was deleted.

685 changes: 0 additions & 685 deletions docs/api-docs/logikon/analysts/lmql_analyst.html

This file was deleted.

1,193 changes: 0 additions & 1,193 deletions docs/api-docs/logikon/analysts/lmql_queries.html

This file was deleted.

256 changes: 0 additions & 256 deletions docs/api-docs/logikon/analysts/reconstruction.html

This file was deleted.

This file was deleted.

925 changes: 0 additions & 925 deletions docs/api-docs/logikon/analysts/reconstruction/issue_builder_lmql.html

This file was deleted.

2,464 changes: 0 additions & 2,464 deletions docs/api-docs/logikon/analysts/reconstruction/pros_cons_builder_lmql.html

This file was deleted.

This file was deleted.

373 changes: 0 additions & 373 deletions docs/api-docs/logikon/analysts/registry.html

This file was deleted.

254 changes: 0 additions & 254 deletions docs/api-docs/logikon/analysts/score.html

This file was deleted.

765 changes: 0 additions & 765 deletions docs/api-docs/logikon/analysts/score/argmap_graph_scores.html

This file was deleted.

906 changes: 0 additions & 906 deletions docs/api-docs/logikon/analysts/score/balance_scores.html

This file was deleted.

260 changes: 0 additions & 260 deletions docs/api-docs/logikon/debuggers.html

This file was deleted.

818 changes: 0 additions & 818 deletions docs/api-docs/logikon/debuggers/base.html

This file was deleted.

255 changes: 0 additions & 255 deletions docs/api-docs/logikon/debuggers/exporters.html

This file was deleted.

671 changes: 0 additions & 671 deletions docs/api-docs/logikon/debuggers/exporters/htmlsunburst_exporter.html

This file was deleted.

537 changes: 0 additions & 537 deletions docs/api-docs/logikon/debuggers/exporters/networkx_exporter.html

This file was deleted.

653 changes: 0 additions & 653 deletions docs/api-docs/logikon/debuggers/exporters/svgmap_exporter.html

This file was deleted.

789 changes: 0 additions & 789 deletions docs/api-docs/logikon/debuggers/factory.html

This file was deleted.

516 changes: 0 additions & 516 deletions docs/api-docs/logikon/debuggers/interface.html

This file was deleted.

323 changes: 0 additions & 323 deletions docs/api-docs/logikon/debuggers/model_registry.html

This file was deleted.

258 changes: 0 additions & 258 deletions docs/api-docs/logikon/debuggers/reconstruction.html

This file was deleted.

1,600 changes: 0 additions & 1,600 deletions docs/api-docs/logikon/debuggers/reconstruction/claim_extractor.html

This file was deleted.

This file was deleted.

2,606 changes: 0 additions & 2,606 deletions docs/api-docs/logikon/debuggers/reconstruction/informal_argmap_builder.html

This file was deleted.

866 changes: 0 additions & 866 deletions docs/api-docs/logikon/debuggers/reconstruction/issue_builder_lmql.html

This file was deleted.

516 changes: 0 additions & 516 deletions docs/api-docs/logikon/debuggers/reconstruction/lmql_debugger.html

This file was deleted.

1,175 changes: 0 additions & 1,175 deletions docs/api-docs/logikon/debuggers/reconstruction/lmql_queries.html

This file was deleted.

2,281 changes: 0 additions & 2,281 deletions docs/api-docs/logikon/debuggers/reconstruction/pros_cons_builder_lmql.html

This file was deleted.

This file was deleted.

343 changes: 0 additions & 343 deletions docs/api-docs/logikon/debuggers/registry.html

This file was deleted.

253 changes: 0 additions & 253 deletions docs/api-docs/logikon/debuggers/scorers.html

This file was deleted.

614 changes: 0 additions & 614 deletions docs/api-docs/logikon/debuggers/scorers/argmap_graph_scores.html

This file was deleted.

358 changes: 0 additions & 358 deletions docs/api-docs/logikon/debuggers/utils.html

This file was deleted.

256 changes: 0 additions & 256 deletions docs/api-docs/logikon/schemas.html

This file was deleted.

964 changes: 0 additions & 964 deletions docs/api-docs/logikon/schemas/argument_mapping.html

This file was deleted.

927 changes: 0 additions & 927 deletions docs/api-docs/logikon/schemas/configs.html

This file was deleted.

512 changes: 0 additions & 512 deletions docs/api-docs/logikon/schemas/pros_cons.html

This file was deleted.

735 changes: 0 additions & 735 deletions docs/api-docs/logikon/schemas/results.html

This file was deleted.

698 changes: 0 additions & 698 deletions docs/api-docs/logikon/score.html

This file was deleted.

254 changes: 0 additions & 254 deletions docs/api-docs/logikon/utils.html

This file was deleted.

326 changes: 0 additions & 326 deletions docs/api-docs/logikon/utils/model_registry.html

This file was deleted.

581 changes: 0 additions & 581 deletions docs/api-docs/logikon/utils/prompt_templates_registry.html

This file was deleted.

46 changes: 0 additions & 46 deletions docs/api-docs/search.js

This file was deleted.

1 change: 1 addition & 0 deletions docs/guided_reasoning_introduction/bib_all.bib
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading

0 comments on commit 27020d6

Please sign in to comment.