# AI Safety Chatbot

![](https://lh4.googleusercontent.com/laVzwSk-fXxkv5a1gfonBvu_j1hCbJOkv55_W80rfE8aox2Xz6jyH08pQhDLHGFo1LPejLeWJdNqjJ0BtMHAIvQ_dtSy7jIyjuCn0oCzSKV5miVKxVtlCZW-AnW7bi2MTQikW8ZBu1Vwf6Vo)

Hello World! The [AISafety.info](https://aisafety.info/) team is launching a prototype of the [AI Safety Chatbot](http://chat.aisafety.info).

The chatbot uses [a dataset of alignment literature](https://huggingface.co/datasets/StampyAI/alignment-research-dataset) to answer any questions related to AI safety that you might have, while also citing established sources. Please keep in mind that this is a very early prototype and despite citing references, it may still provide inaccurate or inappropriate information.

The overall objective is to help people better understand AI Safety issues based on alignment research using an LLM. This helps with tailoring content to the user's needs and technical level. The chatbot can hopefully be used by both newcomers to AI safety, as well as researchers and engineers who want to get up to speed on specific topics.

How it works
------------

This chatbot builds upon [AlignmentSearch](https://www.lesswrong.com/posts/bGn9ZjeuJCg7HkKBj/introducing-alignmentsearch-an-ai-alignment-informed). Our work also expands upon the alignment research dataset (ARD) developed during [AI Safety Camp 6](https://www.lesswrong.com/posts/FgjcHiWvADgsocE34/a-descriptive-not-prescriptive-overview-of-current-ai). This involved updating and curating the dataset to focus more on quality over quantity. Additionally, we created a process to regularly fetch new articles from selected sources. The ARD contains information about alignment from various books, research papers, and blog posts. For a full list of all the sources being used, look at the readme of the repository on [GitHub](https://github.com/stampyAI/alignment-research-dataset) or [HuggingFace](https://huggingface.co/datasets/StampyAI/alignment-research-dataset).

We use a process called [retrieval-augmented generation (RAG)](https://huggingface.co/docs/transformers/model_doc/rag) to generate the answers. Since LLM data is static, RAG increases the capabilities of a LLM by referencing an external authoritative knowledge base before generating a response. So the process can be roughly broken into - 1) getting and storing the data in a vector database, and then 2) generating an answer based on that data.

The information storage process is outlined below:

![](https://39669.cdn.cke-cs.com/rQvD3VnunXZu34m86e5f/images/14db2b8a7d45245465c2e456f326d734af7eed807ca7f16e.png)

Source: DeepLearning.AI (2023) “[LangChain: Chat with Your Data](https://www.deeplearning.ai/short-courses/langchain-chat-with-your-data/)”

*   **Document Loading**: The articles are scraped from various sources such as the ones mentioned above. They are then parsed and stored in an SQL database while making sure that metadata values fields are valid.
*   **Splitting**: Then the text content of the documents is broken up into fixed-sized chunks.
*   **Storage**: These chunks are then embedded into the [Pinecone](https://www.pinecone.io/) vector database using the [OpenAI embedding model](https://openai.com/blog/introducing-text-and-code-embeddings).

Once we have a database of alignment literature, we use the following series of steps to generate an answer based on a user query:

![](https://39669.cdn.cke-cs.com/rQvD3VnunXZu34m86e5f/images/10698355acd89bf8a5ae281133fe644ef937d8819a018f30.png)

Source: DeepLearning.AI (2023) “[LangChain: Chat with Your Data](https://www.deeplearning.ai/short-courses/langchain-chat-with-your-data/)”

*   **Query**: A user types in a question.
*   **Storage+Retrieval**: We retrieve chunks from the vector database that are semantically similar to the user's question.
*   **Prompt**: A prompt is formed that includes all the text retrieved from the relevant chunks provided as context, along with additional instructions on how to format citations and structure the answer.
*   **Output**: This prompt is then passed to the LLM, which synthesizes an answer based on the relevant chunk of data along with accurate inline citations to the source material.

Additionally, as the answer is generated, a ‘[glossary](https://docs.google.com/document/d/1Rm7tN5zTErZq0E4qqAZoNVzClS94Kb_rQOLaViu2p6c/edit)’ is injected with manually written one-sentence definitions of common jargon. The following image example shows what  Goodhart’s Law looks like on hover:

![](https://lh7-us.googleusercontent.com/YgiaHsA8xmpgiY0VmLOTCuaTH55Bbw-AC_5qR_Y_MRHhRqcRkOFyy9e13oJq-PPD_Ro4SVscItOPMNvawC4utb-UeX9ODr-GThRFHOMXh97eAfpD03fdEnKcz6KLMDIH0f_lOtyXcoFBZXg5GJdCNWsBGnw_HK3VWNSuASgosj3uuYziPLhCmFR3sy_jgw)

With automatic updates, the ARD will periodically fetch new article entries from trusted sources and add or update items to a SQL database. A separate process adds text to the dataset from [user suggested sources](https://huggingface.co/datasets/StampyAI/alignment-research-dataset). This dataset is available on [HuggingFace](https://huggingface.co/datasets/StampyAI/alignment-research-dataset), which includes instructions on how to download and use it. This means that the chatbot will always be able to produce the more relevant and newer information.

We are also experimenting with multiple modes for different audiences. Currently, we offer three options, which produce answers of varying complexity, using the same chunks but adjusting the prompt sent to the LLM.

![](https://lh7-us.googleusercontent.com/fIiB9_z47GgqWO1Ufru93YaL2Op_0U0_x4lkqyQGX3VqO-dsyXn3sHjv7mu8JyoDk0VgLQsPQpXCMaMuPIarx1K9L_cbeC4ycDhIP5PssniLiOzSeXJzWcxhwxVKDBopql3vZgutmqNeB5LEfLCNn5-MFrZCrdrdvVioVx4px2RiEfzfQ67FZewaxVXM3w)

Hallucinations
--------------

Each chunk is attached to some primary source (e.g. an arXiv paper or blog post). When we have our final answer synthesized from these chunks, we can link back to the primary sources from where the information used in generating the answer was gathered. This is one attempt to stop the generation of misinformation. Additionally, we are experimenting with prompt engineering and dataset curation to make sure that only quality articles are included in the dataset. Overall, it is still a work in progress, but we are putting in effort to reduce hallucinations.

Integration with manual distillations
-------------------------------------

The initial answer will always be generated by the LLM; however, we also integrate with the existing effort by the [AISafety.info](https://aisafety.info/) contributors. So, at the end of every generated answer, the chatbot recommends human-written follow-up questions. To distinguish a human-written answer from a generated one, the background color for human answers is darker as shown in the image below.

![](https://lh7-us.googleusercontent.com/xOkwcP_BOEuen46j8eS8EiYHkzsunn_mSjKitnsGTveluMrP3QSEL-xQcSVstX30-gHP11FCe8PHFS4XWG0omMbN9_3utjnB4N7ZxgYpmpjuSzETkw4wnN16Du3jpVvxh7_W0MSZiwHfuTZvaYR3_ZE6jtd6pQRc4iuxf0cBRWsp7NEFi3jNebKzsnqboA)

Future Plans
------------

A number of planned features aim to enhance the quality of generated content while minimizing hallucinations. We plan to invest more effort into formalizing methods to optimize and evaluate prompts based on current research and best practices. Refinements to the retrieval method show promise for improvement as well.  

A UI/UX revamp is underway for the frontend. Some planned features include adding a thumbs up or down option next to completions, so that we can A/B test our prompts. There might also eventually be an option to easily share or save conversation histories to the local machine.

The text of some answers also relies on equations, so we are working on getting properly formatted equations rendered in LaTeX.

Other potential future plans include offering a semantic search of the ARD as an OpenAI API function call or plug-in. We are also considering fine-tuning an LLM with the dataset of human crafted answers to see if it improves generated answers.

Overall, there’s still substantial work ahead, but the potential is encouraging.

Feedback & Contributions
------------------------

If you have suggestions about the chatbot, such as noticing hallucinations on a certain topic, or if you feel that certain sources should be removed, please [use this link](http://bit.ly/stampy-chat-issues) to provide feedback.

Alternatively, if you have new sources that you think should be added to the overall alignment research dataset, please suggest including them using [this link](https://bit.ly/ard-suggestion).

If you want to use the alignment research dataset in your own project, please feel free to download it on [HuggingFace](https://huggingface.co/datasets/StampyAI/alignment-research-dataset) and use it. The link also contains detailed instructions on how to get set up.

Those who would like to contribute to the development effort can join the [Rob Miles Discord](https://discord.com/invite/Bt8PaRTDQC) and post in the [chat dev thread](https://discord.com/channels/677546901339504640/1125882946952384635).

Crossposted to EA Forum: [https://forum.effectivealtruism.org/posts/33KCtJfBTzK4TPjCy/ai-safety-chatbot](https://forum.effectivealtruism.org/posts/33KCtJfBTzK4TPjCy/ai-safety-chatbot)