"Don't fine-tune your LLM, Construct a vector database."
"There is No Hallucination here."
LLM-Vector-database is a powerful tool that allows you to construct a vector database using sentence embeddings. Instead of fine-tuning your Large Language Model (LLM), this project provides a unique approach to natural language processing and understanding. By embedding sentences into a vector space and constructing a database from these vectors, you can generate text responses based on this database. This makes it an ideal resource for chatbot development and other natural language processing applications.
Follow these steps to get started with the LLM-Vector-database:
1. Clone the repository
Use the following command to clone the repository:
git clone https://github.com/juicyjung/LLM-Vector-database.git
2. Install the necessary dependencies
After cloning the repository, navigate into the directory and install the necessary dependencies, vectordb and torch(appropriate version for your environment) by executing:
pip install poetry
poetry install
That's it! You've successfully set up LLM-Vector-database on your machine.
Follow these steps to utilize LLM-Vector-database in your project:
from llmvdb import Llmvdb
from llmvdb.embedding.model import HuggingFaceEmbedding
from llmvdb.llm.openai import OpenAI
embedding = HuggingFaceEmbedding()
llm = OpenAI(instruction="λλ λ²λ₯ μλ¬Έμ μν μ±λ΄μ΄μΌ. μ¬μ©μλ₯Ό μν΄ λ¨Όμ κ°μ μ μΈ κ³΅κ°μ ν΄μ€μΌν΄.")
your_llm = Llmvdb(
embedding,
llm,
hugging_face="juicyjung/easylaw_kr_documents",
workspace="workspace_path",
)
answer = your_llm.generate_prompt("μμΈλ°©μ μ»μ΄ μμ·¨λ₯Ό νκ³ μλλ° κ΅°λμ κ°μΌν©λλ€. 보μ¦κΈμ λλ €λ°μ μ μμκΉμ?")
print(answer)
The above code will return the following:
κ΅°λμ μ
λν΄μΌ νλ κ²½μ°μλ μμ°¨μΈμ΄ μλμ°¨ κ³μ½μ μ€λν΄μ§ν μ μλ μ¬μ μ ν΄λΉνμ§ μμ΅λλ€. λ°λΌμ, μ½μ ν κΈ°κ°μ΄ λ¨μ μλμ°¨μ κ²½μ°μλ 보μ¦κΈμ λλ €λ°μ μ μμΌλ©°, μ½μ ν κΈ°κ° λμ μμΈλ₯Ό μ§
κΈν΄μΌ ν©λλ€.
Using the method described above, we were able to significantly address two major issues that arose when fine-tuning LAW-Alpaca.
Fine-tuning requires high-performance GPU resources and takes about 5 hours each time based on approximately 2000 data. However, by using a Vector Database, we were able to use the LLM off-the-shelf, which saved costs during training. The process of embedding and constructing the vector database took less than 1 minute, significantly reducing the time and resources required compared to traditional fine-tuning methods.
The advantage of a language model is inference and generation from given language data, not fact searching. Therefore, if you simply ask the LLM a fact-based question, it can produce plausible but false information, regardless of how much fine-tuning has been done. However, when we applied this architecture, we changed the role of the LLM from fact-based questioning to a QA task, preserving the LLM's strength in inference while solving the problem of hallucination.
Contributions are welcome! Please check out the todos below, and feel free to open a pull request.
If you have any questions, feel free to reach out to us. We'd be more than happy to assist you!
47 commits
8 commits
Python
100.0%
"Don't fine-tune your LLM, Construct a vector database."
"There is No Hallucination here."
LLM-Vector-database is a powerful tool that allows you to construct a vector database using sentence embeddings. Instead of fine-tuning your Large Language Model (LLM), this project provides a unique approach to natural language processing and understanding. By embedding sentences into a vector space and constructing a database from these vectors, you can generate text responses based on this database. This makes it an ideal resource for chatbot development and other natural language processing applications.
Follow these steps to get started with the LLM-Vector-database:
1. Clone the repository
Use the following command to clone the repository:
git clone https://github.com/juicyjung/LLM-Vector-database.git
2. Install the necessary dependencies
After cloning the repository, navigate into the directory and install the necessary dependencies, vectordb and torch(appropriate version for your environment) by executing:
pip install poetry
poetry install
That's it! You've successfully set up LLM-Vector-database on your machine.
Follow these steps to utilize LLM-Vector-database in your project:
from llmvdb import Llmvdb
from llmvdb.embedding.model import HuggingFaceEmbedding
from llmvdb.llm.openai import OpenAI
embedding = HuggingFaceEmbedding()
llm = OpenAI(instruction="λλ λ²λ₯ μλ¬Έμ μν μ±λ΄μ΄μΌ. μ¬μ©μλ₯Ό μν΄ λ¨Όμ κ°μ μ μΈ κ³΅κ°μ ν΄μ€μΌν΄.")
your_llm = Llmvdb(
embedding,
llm,
hugging_face="juicyjung/easylaw_kr_documents",
workspace="workspace_path",
)
answer = your_llm.generate_prompt("μμΈλ°©μ μ»μ΄ μμ·¨λ₯Ό νκ³ μλλ° κ΅°λμ κ°μΌν©λλ€. 보μ¦κΈμ λλ €λ°μ μ μμκΉμ?")
print(answer)
The above code will return the following:
κ΅°λμ μ
λν΄μΌ νλ κ²½μ°μλ μμ°¨μΈμ΄ μλμ°¨ κ³μ½μ μ€λν΄μ§ν μ μλ μ¬μ μ ν΄λΉνμ§ μμ΅λλ€. λ°λΌμ, μ½μ ν κΈ°κ°μ΄ λ¨μ μλμ°¨μ κ²½μ°μλ 보μ¦κΈμ λλ €λ°μ μ μμΌλ©°, μ½μ ν κΈ°κ° λμ μμΈλ₯Ό μ§
κΈν΄μΌ ν©λλ€.
Using the method described above, we were able to significantly address two major issues that arose when fine-tuning LAW-Alpaca.
Fine-tuning requires high-performance GPU resources and takes about 5 hours each time based on approximately 2000 data. However, by using a Vector Database, we were able to use the LLM off-the-shelf, which saved costs during training. The process of embedding and constructing the vector database took less than 1 minute, significantly reducing the time and resources required compared to traditional fine-tuning methods.
The advantage of a language model is inference and generation from given language data, not fact searching. Therefore, if you simply ask the LLM a fact-based question, it can produce plausible but false information, regardless of how much fine-tuning has been done. However, when we applied this architecture, we changed the role of the LLM from fact-based questioning to a QA task, preserving the LLM's strength in inference while solving the problem of hallucination.
Contributions are welcome! Please check out the todos below, and feel free to open a pull request.
If you have any questions, feel free to reach out to us. We'd be more than happy to assist you!
47 commits
8 commits
Python
100.0%