Spaces:
Sleeping
Sleeping
Merge pull request #11 from luisrodriguesphd/refact-params-tg
Browse files
conf/params.yml
CHANGED
@@ -16,12 +16,16 @@ embedding_dir: ["data", "03_indexed"]
|
|
16 |
|
17 |
|
18 |
# LLM / Text Generation
|
19 |
-
model_id: "M4-ai/tau-1.8B"
|
20 |
# See instructions for parameters: https://www.ibm.com/docs/en/watsonx-as-a-service?topic=lab-model-parameters-prompting
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
|
|
|
|
|
|
|
|
|
|
25 |
# See instructions for the prompt: https://huggingface.co/spaces/Locutusque/Locutusque-Models/blob/main/app.py
|
26 |
prompt_dir: ["data", "04_prompts"]
|
27 |
promp_file: "prompt_template_for_explaning_why_is_a_good_fit.json"
|
|
|
16 |
|
17 |
|
18 |
# LLM / Text Generation
|
|
|
19 |
# See instructions for parameters: https://www.ibm.com/docs/en/watsonx-as-a-service?topic=lab-model-parameters-prompting
|
20 |
+
generative_model:
|
21 |
+
model_name: "M4-ai/tau-1.8B"
|
22 |
+
model_kwargs:
|
23 |
+
trust_remote_code: True
|
24 |
+
generate_kwargs:
|
25 |
+
top_k: 30
|
26 |
+
top_p: 0.7
|
27 |
+
temperature: 0.3
|
28 |
+
max_new_tokens: 256
|
29 |
# See instructions for the prompt: https://huggingface.co/spaces/Locutusque/Locutusque-Models/blob/main/app.py
|
30 |
prompt_dir: ["data", "04_prompts"]
|
31 |
promp_file: "prompt_template_for_explaning_why_is_a_good_fit.json"
|
src/resume_worth/pipelines/text_generation/nodes.py
CHANGED
@@ -1,4 +1,6 @@
|
|
1 |
import os
|
|
|
|
|
2 |
from langchain_community.llms.huggingface_pipeline import HuggingFacePipeline
|
3 |
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
|
4 |
from langchain_core.prompts import PromptTemplate
|
@@ -10,20 +12,34 @@ import transformers
|
|
10 |
transformers.logging.set_verbosity_error()
|
11 |
|
12 |
|
13 |
-
|
14 |
-
def load_hf_text_generation_model_to_langchain(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
"""
|
16 |
Function to load a text generation model hosted on Hugging Face to se used in LangChain.
|
17 |
More info, see: https://python.langchain.com/docs/integrations/llms/huggingface_pipelines/
|
18 |
"""
|
19 |
|
20 |
-
|
21 |
-
|
|
|
|
|
|
|
22 |
|
23 |
-
pipe = pipeline("text-generation", model=model, tokenizer=tokenizer,
|
24 |
return_full_text=False, do_sample=True,
|
25 |
-
|
26 |
-
num_beams=1, repetition_penalty=1.1, num_return_sequences=1
|
27 |
)
|
28 |
|
29 |
hf = HuggingFacePipeline(pipeline=pipe)
|
|
|
1 |
import os
|
2 |
+
os.environ['HF_HOME'] = ".cache/huggingface"
|
3 |
+
|
4 |
from langchain_community.llms.huggingface_pipeline import HuggingFacePipeline
|
5 |
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
|
6 |
from langchain_core.prompts import PromptTemplate
|
|
|
12 |
transformers.logging.set_verbosity_error()
|
13 |
|
14 |
|
15 |
+
#@lru_cache(maxsize=None)
|
16 |
+
def load_hf_text_generation_model_to_langchain(
|
17 |
+
model_name:str='gpt2',
|
18 |
+
model_kwargs:dict={
|
19 |
+
'trust_remote_code': True,
|
20 |
+
},
|
21 |
+
generate_kwargs:dict={
|
22 |
+
'top_k': 50,
|
23 |
+
'top_p': 0.95,
|
24 |
+
'temperature': 0.4,
|
25 |
+
'max_new_tokens': 1024,
|
26 |
+
}
|
27 |
+
):
|
28 |
"""
|
29 |
Function to load a text generation model hosted on Hugging Face to se used in LangChain.
|
30 |
More info, see: https://python.langchain.com/docs/integrations/llms/huggingface_pipelines/
|
31 |
"""
|
32 |
|
33 |
+
print(f"-> Load a pretrained text embedding model {model_name}")
|
34 |
+
|
35 |
+
# https://huggingface.co/apple/OpenELM
|
36 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name, **model_kwargs)
|
37 |
+
model = AutoModelForCausalLM.from_pretrained(model_name, **model_kwargs)
|
38 |
|
39 |
+
pipe = pipeline("text-generation", model=model, tokenizer=tokenizer,
|
40 |
return_full_text=False, do_sample=True,
|
41 |
+
**generate_kwargs,
|
42 |
+
num_beams=1, repetition_penalty=1.1, num_return_sequences=1,
|
43 |
)
|
44 |
|
45 |
hf = HuggingFacePipeline(pipeline=pipe)
|
src/resume_worth/pipelines/text_generation/pipeline.py
CHANGED
@@ -11,11 +11,7 @@ from resume_worth.pipelines.text_generation.nodes import load_hf_text_generation
|
|
11 |
|
12 |
|
13 |
params = get_params()
|
14 |
-
|
15 |
-
top_p = params['top_p']
|
16 |
-
top_k = params['top_k']
|
17 |
-
temperature = params['temperature']
|
18 |
-
max_new_tokens = params['max_new_tokens']
|
19 |
prompt_dir = params['prompt_dir']
|
20 |
promp_file = params['promp_file']
|
21 |
|
@@ -24,7 +20,7 @@ def generate_explanation_why_resume_for_a_job(resume: str, job: str):
|
|
24 |
|
25 |
# Stage 1 - [cacheable] Load text generation model
|
26 |
|
27 |
-
text_generation_model = load_hf_text_generation_model_to_langchain(
|
28 |
|
29 |
# Stage 2 - [cacheable] Load text generation model
|
30 |
|
|
|
11 |
|
12 |
|
13 |
params = get_params()
|
14 |
+
generative_model = params['generative_model']
|
|
|
|
|
|
|
|
|
15 |
prompt_dir = params['prompt_dir']
|
16 |
promp_file = params['promp_file']
|
17 |
|
|
|
20 |
|
21 |
# Stage 1 - [cacheable] Load text generation model
|
22 |
|
23 |
+
text_generation_model = load_hf_text_generation_model_to_langchain(generative_model['model_name'], generative_model['model_kwargs'], generative_model['generate_kwargs'])
|
24 |
|
25 |
# Stage 2 - [cacheable] Load text generation model
|
26 |
|
src/resume_worth/utils/utils.py
CHANGED
@@ -1,4 +1,6 @@
|
|
1 |
import os
|
|
|
|
|
2 |
import yaml
|
3 |
from langchain_community.embeddings import HuggingFaceEmbeddings
|
4 |
import fitz # imports the pymupdf library
|
|
|
1 |
import os
|
2 |
+
os.environ['HF_HOME'] = ".cache/huggingface"
|
3 |
+
|
4 |
import yaml
|
5 |
from langchain_community.embeddings import HuggingFaceEmbeddings
|
6 |
import fitz # imports the pymupdf library
|