Skip to content

Commit

Permalink
Merge pull request #22 from adriaciurana/calvin/final_changes
Browse files Browse the repository at this point in the history
Calvin/final changes
  • Loading branch information
adriaciurana authored Dec 22, 2023
2 parents 0b10744 + 9ae3fb5 commit 3de200d
Show file tree
Hide file tree
Showing 12 changed files with 23 additions and 2 deletions.
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# PromptZ - OpenMesh Hackathon - Challenge 4: Genetic Algorithm Project

![Logo](./docs/logo.png)

## Overview

This repository contains a project developed for Challenge 4: Genetic Algorithm in the OpenMesh Hackathon. The project provides various tools for optimizing prompts using a genetic algorithm (GA) approach.
Expand Down Expand Up @@ -100,8 +102,12 @@ It allows generating variations in the population and creating new chromosomes.
There are mainly two types of generations:
- **Keyword-Based**: As mentioned earlier, keyword-based generation involves defining adjectives, nouns, and verbs to subsequently generate the prompt using a generative algorithm (trained by us or using an LLM). Mutations/crossovers are performed in the keyword space.

![KeywordsGenerator](./docs/keywordsgenerator.png)

- **Natural Language-Based**: In this case, it applies directly to the prompts, and LLMs are used to generate similar sentences (mutations) and crossovers (using an approach similar to the one proposed in the paper [Promptmix](https://aclanthology.org/2023.emnlp-main.323.pdf)).

![NLGenerator](./docs/nlgenerator.png)

E.g:
```python
# Using keywords based
Expand All @@ -116,8 +122,12 @@ The evaluator is responsible for defining how to weigh the chromosomes. In our c

- **Semantic Similarity-Based**: It compares the output of the LLM and the target using a document retrieval model.

![Semantic Similarity Evaluator](./docs/semantic_similarity_evaluator.png)

- **Objective-Based**: When the exact desired output is not known, but the objective is clear. It is useful, for example, for "prompt injection," such as creating offensive language or explaining harmful actions. We believe that this could be extremely useful if we train an LLM model on information that could be sensitive, and we want to ensure that we have no security vulnerabilities. For instance, let's consider training the model with data from a database of legal cases to develop an LLM that can provide assistance in future legal scenarios. Currently, we use a separate LLM model without safeguards to generate potential targets. However, a similar objective can be achieved by pre-training a classification model, indicating, for instance, whether the output is confidential or not.

![Objective Evaluator](./docs/objective_evaluator.png)

```python
# Similarity based
evaluator = SemanticSimilarityEvaluator()
Expand Down Expand Up @@ -157,6 +167,8 @@ Don't worry about importing the dependencies; our system will handle the injecti
### Hypercycle backend
This setup allows you to execute our algorithm by making a POST call to a RestAPI (you can find the specifications [here](https://github.com/adriaciurana/PromptZ/blob/main/src/ga_prompt_llm/backend/hypercycle_server.py#L34)). It returns the best result. You can also find an example [here](https://github.com/adriaciurana/PromptZ/blob/main/src/ga_prompt_llm/backend/test_manual_hypercycle_server.py).

![Hypercycle Architecture](./docs/hypercycle_arch.png)

E.g:
```python
{
Expand All @@ -182,6 +194,8 @@ E.g:
### Frontend/Backend real-time interactive
As mentioned in the introduction, we firmly believe in **usability** and **interpretability**.

![Bidirectional Architecture](./docs/bidirectional_arch.png)

If we cannot interpret our results, how can we analyze correctly our Large Language Model (LLM)? That's why we've included a dashboard that allows real-time interpretation of the Genetic Algorithm (GA) results. We consider this feature as the :cherries: on the :cake: for our solution.

This solution maintains a persistent connection with the server, enabling each advancement in the Genetic Algorithm (GA) to be visualized as a Direct Acyclic Graph (DAG) in real-time. Additionally, real-time updates of the top-k best solutions are also included.
Expand Down Expand Up @@ -211,6 +225,13 @@ You can also interact with the graph, and by clicking on a node, you can access
#### docker
`./docker/run_backend_bidirectional.sh`

## Extra diagrams
### Natural Language Generator (NLGenerator)
![Natural Languange Generator](./docs/chromosome_llm_generation.png)

### Keywords Generator (KeywordsGenerator)
![Interactive Graph](./docs/keywords_arch.png)


## Contributors

Expand All @@ -225,4 +246,4 @@ This project is licensed under the [MIT License](LICENSE). See the [LICENSE](LIC

---

Feel free to contribute to the project and make it even more robust and versatile!
Feel free to contribute to the project and make it even more robust and versatile!
Binary file added docs/bidirectional_arch.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/chromosome_llm_generation.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/hypercycle_arch.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/intro.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/keywords_arch.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/keywordsgenerator.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/nlgenerator.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/objective_evaluator.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/semantic_similarity_evaluator.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/ga_prompt_llm/frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Prompt</title>
<title>PromptZ</title>
<meta name="author" content="Error 404 Team" />
<link
rel="stylesheet"
Expand Down

0 comments on commit 3de200d

Please sign in to comment.