Skip to content

Commit a0983c0

Browse files
authored
Merge pull request #1234 from llmware-ai/update-010526-ov-embedding-models
update ov embedding models
2 parents 5dbc93e + a1796c7 commit a0983c0

5 files changed

Lines changed: 1130 additions & 13 deletions

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
""" Using OpenVINO classifier-based models - illustrates how to get started using
3+
classifier encoding models with OpenVINO."
4+
5+
`pip3 install openvino`
6+
7+
"""
8+
9+
from llmware.models import ModelCatalog
10+
11+
# classifies the likelihood of a prompt injection
12+
cl_name = "protectai-prompt-injection-ov"
13+
14+
# e.g., other examples:
15+
# -- "unitary-toxic-roberta-ov" - classifies potential toxicity
16+
# -- "valurank-bias-ov" - classifies potential bias
17+
18+
classifier_model = ModelCatalog().load_model(cl_name)
19+
20+
text = "The sun is shining in New York today."
21+
22+
response = classifier_model.classify(text)
23+
24+
print("--response: ", response)
25+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
""" OpenVINO embedding models - this example shows how to use OpenVINO embedding
3+
models which can be prepared in batch, and used in conjunction with vector databases
4+
or other vector semantic search retrieval applications.
5+
6+
Prerequisites:
7+
-- pip3 install openvino
8+
9+
"""
10+
11+
from llmware.models import ModelCatalog
12+
13+
# industry-bert-contracts-ov
14+
# industry-bert-insurance-ov
15+
# all-mini-lm-l6-v2-ov
16+
# all-mpnet-base-v2-ov
17+
18+
model = ModelCatalog().load_model("industry-bert-contracts-ov")
19+
20+
text = "We are at the airport waiting for our flight."
21+
text2 = "The airport is boring, but OK to work from."
22+
text3 = "I am looking forward to our trip."
23+
24+
embedding = model.embedding([text, text2,text3])
25+
26+
print("--test: embedding - ", embedding.shape, embedding)
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
2+
""" openvino reranker model - this example shows how to use openvino reranker model -
3+
it is modeled directly off other reranker example in the repository -
4+
5+
please note that you should import openvino to run this example, e.g.,
6+
7+
-- `pip install openvino`
8+
9+
"""
10+
11+
import os
12+
13+
from llmware.parsers import Parser
14+
from llmware.models import ModelCatalog
15+
from llmware.prompts import Prompt
16+
from llmware.setup import Setup
17+
18+
def rag_in_memory_with_reranker():
19+
20+
""" Executes a rag process in memory using semantic reranker model and bling-phi-3-gguf to answer the question. """
21+
22+
query = "What is the annual rate of the executive's base salary?"
23+
24+
sample_files_path = Setup().load_sample_files(over_write=False)
25+
contracts_path = os.path.join(sample_files_path, "Agreements")
26+
27+
files = os.listdir(contracts_path)
28+
29+
# will use two models for the example - reranker + a 'question-answer' rag llm
30+
31+
# reranker examples:
32+
# -- jina-reranker-v1-turbo-en-ov
33+
# -- jina-reranker-v1-tiny-en-ov
34+
35+
# use ov reranker model to find the most relevant parts of the text
36+
reranker_model = ModelCatalog().load_model("jina-reranker-v1-tiny-en-ov")
37+
38+
# use small ov generative model to review and answer the question
39+
prompter = Prompt().load_model("bling-tiny-llama-ov", temperature=0.0, sample=False)
40+
41+
for i, doc in enumerate(files):
42+
43+
if doc.endswith(".pdf"):
44+
45+
print("\nPROCESSING: ", i, doc)
46+
47+
parser_output = Parser().parse_one(contracts_path,doc,save_history=False)
48+
49+
output = reranker_model.rank(query,parser_output,top_n=10, relevance_threshold=0.25)
50+
51+
use_top = 3
52+
if len(output) > use_top:
53+
output = output[0:use_top]
54+
55+
for i, results in enumerate(output):
56+
print("semantic ranking results: ", i, results["rerank_score"], results["text"])
57+
58+
sources = prompter.add_source_query_results(output)
59+
responses = prompter.prompt_with_source(query,prompt_name="default_with_context")
60+
61+
for i, resp in enumerate(responses):
62+
print("\nllm answers: ", i, resp)
63+
64+
prompter.clear_source_materials()
65+
66+
return 0
67+
68+
69+
if __name__ == "__main__":
70+
71+
rag_in_memory_with_reranker()

llmware/model_configs.py

Lines changed: 115 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3578,7 +3578,121 @@
35783578
"validation_files": ["phi-3-v-128k-instruct-text.onnx.data",
35793579
"phi-3-v-128k-instruct-vision.onnx.data",
35803580
"phi-3-v-128k-instruct-embedding.onnx.data"],
3581-
"custom_model_files": [], "custom_model_repo": "", "parameters": 3.8}
3581+
"custom_model_files": [], "custom_model_repo": "", "parameters": 3.8},
3582+
3583+
{"model_name": "jina-reranker-v1-tiny-en-ov", "display_name": "jina-reranker-v1-tiny-en-ov",
3584+
"model_family": "OVEmbeddingModel", "model_category": "embedding", "model_location": "llmware_repo",
3585+
"embedding_dims": 384, "context_window": 8192, "use_case": "ranker",
3586+
"link": "https://www.huggingface.com/llmware/jina-reranker-v1-tiny-en-ov",
3587+
"custom_model_repo": "", "hf_repo": "llmware/jina-reranker-v1-tiny-en-ov"},
3588+
3589+
{"model_name": "jina-reranker-v1-turbo-en-ov", "display_name": "jina-reranker-v1-turbo-en-ov",
3590+
"model_family": "OVEmbeddingModel", "model_category": "embedding", "model_location": "llmware_repo",
3591+
"embedding_dims": 384, "context_window": 8192, "use_case": "ranker",
3592+
"link": "https://www.huggingface.com/llmware/jina-reranker-v1-turbo-en-ov",
3593+
"custom_model_repo": "", "hf_repo": "llmware/jina-reranker-v1-turbo-en-ov"},
3594+
3595+
{"model_name": "industry-bert-contracts-ov", "display_name": "industry-bert-contracts-ov",
3596+
"model_family": "OVEmbeddingModel", "model_category": "embedding", "model_location": "llmware_repo",
3597+
"embedding_dims": 768, "context_window": 512, "link": "https://none",
3598+
"custom_model_repo": "", "hf_repo": "llmware/industry-bert-contracts-ov"},
3599+
3600+
{"model_name": "industry-bert-insurance-ov", "display_name": "industry-bert-insurance-ov",
3601+
"model_family": "OVEmbeddingModel", "model_category": "embedding", "model_location": "llmware_repo",
3602+
"embedding_dims": 768, "context_window": 512, "link": "https://none",
3603+
"custom_model_repo": "", "hf_repo": "llmware/industry-bert-insurance-ov"},
3604+
3605+
{"model_name": "industry-bert-asset-management-ov", "display_name": "industry-bert-asset-management-ov",
3606+
"model_family": "OVEmbeddingModel", "model_category": "embedding", "model_location": "llmware_repo",
3607+
"embedding_dims": 768, "context_window": 512, "link": "https://none",
3608+
"custom_model_repo": "", "hf_repo": "llmware/industry-bert-asset-management-ov"},
3609+
3610+
{"model_name": "industry-bert-sec-ov", "display_name": "industry-bert-sec-ov",
3611+
"model_family": "OVEmbeddingModel", "model_category": "embedding", "model_location": "llmware_repo",
3612+
"embedding_dims": 768, "context_window": 512, "link": "https://none",
3613+
"custom_model_repo": "", "hf_repo": "llmware/industry-bert-sec-ov"},
3614+
3615+
{"model_name": "industry-bert-loans-ov", "display_name": "industry-bert-loans-ov",
3616+
"model_family": "OVEmbeddingModel", "model_category": "embedding", "model_location": "llmware_repo",
3617+
"embedding_dims": 768, "context_window": 512, "link": "https://none",
3618+
"custom_model_repo": "", "hf_repo": "llmware/industry-bert-loans-ov"},
3619+
3620+
{"model_name": "all-mini-lm-l6-v2-ov", "display_name": "all-mini-lm-l6-v2-ov",
3621+
"model_family": "OVEmbeddingModel", "model_category": "embedding", "model_location": "llmware_repo",
3622+
"embedding_dims": 384, "context_window": 512, "link": "https://none",
3623+
"custom_model_repo": "", "hf_repo": "llmware/all-mini-lm-l6-v2-ov"},
3624+
3625+
{"model_name": "all-mpnet-base-v2-ov", "display_name": "all-mpnet-base-v2-ov",
3626+
"model_family": "OVEmbeddingModel", "model_category": "embedding", "model_location": "llmware_repo",
3627+
"embedding_dims": 768, "context_window": 514, "link": "https://none",
3628+
"custom_model_repo": "", "hf_repo": "llmware/all-mpnet-base-v2-ov"},
3629+
3630+
{"model_name": "paraphrase-multilingual-MiniLM-L12-v2-ov",
3631+
"display_name": "paraphrase-multilingual-MiniLM-L12-v2-ov",
3632+
"model_family": "OVEmbeddingModel", "model_category": "embedding", "model_location": "llmware_repo",
3633+
"embedding_dims": 384, "context_window": 512, "link": "https://none",
3634+
"custom_model_repo": "", "hf_repo": "llmware/paraphrase-multilingual-MiniLM-L12-v2-ov"},
3635+
3636+
{"model_name": "gte-small-ov", "display_name": "gte-small-ov",
3637+
"model_family": "OVEmbeddingModel", "model_category": "embedding", "model_location": "llmware_repo",
3638+
"embedding_dims": 384, "context_window": 512, "link": "https://none",
3639+
"custom_model_repo": "", "hf_repo": "llmware/gte-small-ov"},
3640+
3641+
{"model_name": "gte-base-ov", "display_name": "gte-base-ov",
3642+
"model_family": "OVEmbeddingModel", "model_category": "embedding", "model_location": "llmware_repo",
3643+
"embedding_dims": 768, "context_window": 512, "link": "https://none",
3644+
"custom_model_repo": "", "hf_repo": "llmware/gte-base-ov"},
3645+
3646+
{"model_name": "gte-large-ov",
3647+
"display_name": "gte-large-ov",
3648+
"model_family": "OVEmbeddingModel", "model_category": "embedding", "model_location": "llmware_repo",
3649+
"embedding_dims": 1024, "context_window": 512, "link": "https://none",
3650+
"custom_model_repo": "", "hf_repo": "llmware/gte-large-ov"},
3651+
3652+
{"model_name": "bge-small-en-v1.5-ov",
3653+
"display_name": "bge-small-en-v1.5-ov",
3654+
"model_family": "OVEmbeddingModel", "model_category": "embedding", "model_location": "llmware_repo",
3655+
"embedding_dims": 384, "context_window": 512, "link": "https://none",
3656+
"custom_model_repo": "", "hf_repo": "llmware/bge-small-en-v1.5-ov"},
3657+
3658+
{"model_name": "bge-base-en-v1.5-ov",
3659+
"display_name": "bge-base-en-v1.5-ov",
3660+
"model_family": "OVEmbeddingModel", "model_category": "embedding", "model_location": "llmware_repo",
3661+
"embedding_dims": 768, "context_window": 512, "link": "https://none",
3662+
"custom_model_repo": "", "hf_repo": "llmware/bge-base-en-v1.5-ov"},
3663+
3664+
{"model_name": "bge-large-en-v1.5-ov",
3665+
"display_name": "bge-large-en-v1.5-ov",
3666+
"model_family": "OVEmbeddingModel", "model_category": "embedding", "model_location": "llmware_repo",
3667+
"embedding_dims": 1024, "context_window": 512, "link": "https://none",
3668+
"custom_model_repo": "", "hf_repo": "llmware/bge-large-en-v1.5-ov"},
3669+
3670+
{"model_name": "protectai-prompt-injection-ov", "display_name": "protectai-prompt-injection-ov",
3671+
"model_family": "OVEmbeddingModel", "model_category": "embedding", "model_location": "llmware_repo",
3672+
"embedding_dims": 768, "context_window": 512, "link": "https://none",
3673+
"hf_repo": "llmware/protectai-prompt-injection-ov", "use_case": "classifier",
3674+
"custom_model_repo": "", "pytorch_model_repo": "protectai/deberta-v3-base-prompt-injection"},
3675+
3676+
{"model_name": "xlm-roberta-language-detector-ov",
3677+
"display_name": "xlm-roberta-language-detector-ov",
3678+
"model_family": "OVEmbeddingModel", "model_category": "embedding",
3679+
"model_location": "llmware_repo", "use_case": "classifier",
3680+
"embedding_dims": 768, "context_window": 512, "link": "https://none",
3681+
"custom_model_repo": "", "pytorch_repo": "papluca/xlm-roberta-base-language-detection",
3682+
"hf_repo": "llmware/xlm-roberta-language-detector-ov"},
3683+
3684+
{"model_name": "valurank-bias-ov", "display_name": "valurank-bias-ov",
3685+
"model_family": "OVEmbeddingModel", "model_category": "embedding",
3686+
"model_location": "llmware_repo", "use_case": "classifier",
3687+
"embedding_dims": 768, "context_window": 512, "link": "https://none",
3688+
"custom_model_repo": "", "pytorch_model_repo": "valurank/distilroberta-bias",
3689+
"hf_repo": "llmware/valurank-bias-ov"},
3690+
3691+
{"model_name": "unitary-toxic-roberta-ov", "display_name": "unitary-toxic-roberta-ov",
3692+
"model_family": "OVEmbeddingModel", "model_category": "embedding",
3693+
"model_location": "llmware_repo", "use_case": "classifier",
3694+
"embedding_dims": 768, "context_window": 512, "link": "https://none",
3695+
"custom_model_repo": "", "hf_repo": "llmware/unitary-toxic-roberta-ov"}
35823696

35833697
]
35843698

0 commit comments

Comments
 (0)