diff --git a/README.md b/README.md index d79bd7d..94f98c0 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # PromptZ - OpenMesh Hackathon - Challenge 4: Genetic Algorithm Project + + ## 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. @@ -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. + + - **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)). + + E.g: ```python # Using keywords based @@ -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. + + - **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. + + ```python # Similarity based evaluator = SemanticSimilarityEvaluator() @@ -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). + + E.g: ```python { @@ -182,6 +194,8 @@ E.g: ### Frontend/Backend real-time interactive As mentioned in the introduction, we firmly believe in **usability** and **interpretability**. + + 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. @@ -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) + + +### Keywords Generator (KeywordsGenerator) + + ## Contributors @@ -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! \ No newline at end of file diff --git a/docs/bidirectional_arch.png b/docs/bidirectional_arch.png new file mode 100644 index 0000000..3fd7855 Binary files /dev/null and b/docs/bidirectional_arch.png differ diff --git a/docs/chromosome_llm_generation.png b/docs/chromosome_llm_generation.png new file mode 100644 index 0000000..f5a1659 Binary files /dev/null and b/docs/chromosome_llm_generation.png differ diff --git a/docs/hypercycle_arch.png b/docs/hypercycle_arch.png new file mode 100644 index 0000000..74f719d Binary files /dev/null and b/docs/hypercycle_arch.png differ diff --git a/docs/intro.png b/docs/intro.png index 6f8876e..b48246a 100644 Binary files a/docs/intro.png and b/docs/intro.png differ diff --git a/docs/keywords_arch.png b/docs/keywords_arch.png new file mode 100644 index 0000000..946688b Binary files /dev/null and b/docs/keywords_arch.png differ diff --git a/docs/keywordsgenerator.png b/docs/keywordsgenerator.png new file mode 100644 index 0000000..7be8f19 Binary files /dev/null and b/docs/keywordsgenerator.png differ diff --git a/docs/logo.png b/docs/logo.png new file mode 100644 index 0000000..219101b Binary files /dev/null and b/docs/logo.png differ diff --git a/docs/nlgenerator.png b/docs/nlgenerator.png new file mode 100644 index 0000000..71a5b91 Binary files /dev/null and b/docs/nlgenerator.png differ diff --git a/docs/objective_evaluator.png b/docs/objective_evaluator.png new file mode 100644 index 0000000..c431c2c Binary files /dev/null and b/docs/objective_evaluator.png differ diff --git a/docs/semantic_similarity_evaluator.png b/docs/semantic_similarity_evaluator.png new file mode 100644 index 0000000..71ec48e Binary files /dev/null and b/docs/semantic_similarity_evaluator.png differ diff --git a/src/ga_prompt_llm/frontend/index.html b/src/ga_prompt_llm/frontend/index.html index b211c16..d60a9c0 100644 --- a/src/ga_prompt_llm/frontend/index.html +++ b/src/ga_prompt_llm/frontend/index.html @@ -3,7 +3,7 @@
-