From 3ddeacd83f534dfe48ec8b75e9d64dfe9234e752 Mon Sep 17 00:00:00 2001 From: marioggil Date: Thu, 28 Sep 2023 14:48:59 -0500 Subject: [PATCH] Custom models of huginface --- .gitignore | 2 ++ FindinDB.py | 1 + loadModelinlocal.py | 9 +++++++++ retrainEmbbeding.py | 13 +++++++++++++ 4 files changed, 25 insertions(+) create mode 100644 loadModelinlocal.py create mode 100644 retrainEmbbeding.py diff --git a/.gitignore b/.gitignore index e0276d8..5c17688 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ names/* nameshf/* photo_2023-09-24_00-25-17.jpg __pycache__/FindinDB.cpython-38.pyc +embeddings/* +tuned_models/* \ No newline at end of file diff --git a/FindinDB.py b/FindinDB.py index e7deb46..8464d78 100644 --- a/FindinDB.py +++ b/FindinDB.py @@ -41,6 +41,7 @@ def read_main(): return {"message": "This is your main app"} + def loadModels(): #model = GPT4All("orca-mini-3b.ggmlv3.q4_0.bin") callback_manager = BaseCallbackManager([StreamingStdOutCallbackHandler()]) diff --git a/loadModelinlocal.py b/loadModelinlocal.py new file mode 100644 index 0000000..3572aae --- /dev/null +++ b/loadModelinlocal.py @@ -0,0 +1,9 @@ + +from langchain.embeddings import HuggingFaceEmbeddings +df=HuggingFaceEmbeddings( + model_name="embeddings/all-MiniLM-L6-v2" +) +text = "This is a test document." + +query_result = df.embed_query(text) +print(query_result) \ No newline at end of file diff --git a/retrainEmbbeding.py b/retrainEmbbeding.py new file mode 100644 index 0000000..197b1fe --- /dev/null +++ b/retrainEmbbeding.py @@ -0,0 +1,13 @@ +from sentence_transformers import SentenceTransformer +# Preguntas y respuestas especializado en eso "multi-qa-mpnet-base-dot-v1" +# uno de uso gereal el de mejor desempeƱo all-mpnet-base-v2 +# el mas rapido "paraphrase-MiniLM-L3-v2" y "all-MiniLM-L6-v2" +# muy rappudo y muy acertado "all-MiniLM-L12-v2" +models=["all-MiniLM-L12-v2","paraphrase-MiniLM-L3-v2" , "all-MiniLM-L6-v2","all-mpnet-base-v2","multi-qa-mpnet-base-dot-v1"] +for model in models: + modelST = SentenceTransformer(model) + # Define the path where you want to save the model + save_path = './embeddings/%s/'%(model) + # Save the model + modelST.save(save_path) +