Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -16,7 +16,7 @@ tokenizer.pad_token = tokenizer.eos_token
|
|
16 |
|
17 |
MAX_INPUT_TOKEN_LENGTH = 4096
|
18 |
|
19 |
-
def generate_response(input_text, temperature=0.5, max_new_tokens=
|
20 |
input_ids = tokenizer.encode(input_text, return_tensors='pt').to(model.device)
|
21 |
|
22 |
if input_ids.shape[1] > MAX_INPUT_TOKEN_LENGTH:
|
@@ -28,7 +28,9 @@ def generate_response(input_text, temperature=0.5, max_new_tokens=20):
|
|
28 |
input_ids=input_ids,
|
29 |
streamer=streamer,
|
30 |
max_new_tokens=max_new_tokens,
|
31 |
-
|
|
|
|
|
32 |
temperature=temperature,
|
33 |
eos_token_id=[tokenizer.eos_token_id]
|
34 |
)
|
@@ -44,7 +46,6 @@ def generate_response(input_text, temperature=0.5, max_new_tokens=20):
|
|
44 |
if not outputs:
|
45 |
raise ValueError("No se gener贸 ninguna respuesta.")
|
46 |
|
47 |
-
# Post-procesamiento m谩s restrictivo
|
48 |
response = "".join(outputs).strip().split("\n")[0]
|
49 |
return response
|
50 |
except Exception as e:
|
@@ -61,14 +62,25 @@ def main():
|
|
61 |
|
62 |
if 'job_title' in df.columns:
|
63 |
job_titles = df['job_title'].tolist()
|
64 |
-
query = "aspiring human resources specialist"
|
65 |
-
|
66 |
-
st.write("Archivo CSV cargado exitosamente:")
|
67 |
-
st.write(df.head())
|
68 |
|
69 |
-
|
70 |
-
|
71 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
|
73 |
if st.button("Generar respuesta"):
|
74 |
with st.spinner("Generando respuesta..."):
|
@@ -89,3 +101,4 @@ def main():
|
|
89 |
|
90 |
if __name__ == "__main__":
|
91 |
main()
|
|
|
|
16 |
|
17 |
MAX_INPUT_TOKEN_LENGTH = 4096
|
18 |
|
19 |
+
def generate_response(input_text, temperature=0.5, max_new_tokens=50):
|
20 |
input_ids = tokenizer.encode(input_text, return_tensors='pt').to(model.device)
|
21 |
|
22 |
if input_ids.shape[1] > MAX_INPUT_TOKEN_LENGTH:
|
|
|
28 |
input_ids=input_ids,
|
29 |
streamer=streamer,
|
30 |
max_new_tokens=max_new_tokens,
|
31 |
+
do_sample=True,
|
32 |
+
top_k=40,
|
33 |
+
top_p=0.9,
|
34 |
temperature=temperature,
|
35 |
eos_token_id=[tokenizer.eos_token_id]
|
36 |
)
|
|
|
46 |
if not outputs:
|
47 |
raise ValueError("No se gener贸 ninguna respuesta.")
|
48 |
|
|
|
49 |
response = "".join(outputs).strip().split("\n")[0]
|
50 |
return response
|
51 |
except Exception as e:
|
|
|
62 |
|
63 |
if 'job_title' in df.columns:
|
64 |
job_titles = df['job_title'].tolist()
|
|
|
|
|
|
|
|
|
65 |
|
66 |
+
# Definir el prompt con in-context learning
|
67 |
+
initial_prompt = (
|
68 |
+
"Here are some examples of job title extraction:\n"
|
69 |
+
"Example 1:\n"
|
70 |
+
"List: ['Data Scientist', 'Machine Learning Engineer', 'AI Researcher']\n"
|
71 |
+
"First job title: 'Data Scientist'\n"
|
72 |
+
"\n"
|
73 |
+
"Example 2:\n"
|
74 |
+
"List: ['Software Developer', 'Backend Engineer', 'Frontend Developer']\n"
|
75 |
+
"First job title: 'Software Developer'\n"
|
76 |
+
"\n"
|
77 |
+
"Now, extract the first job title from the following list:\n"
|
78 |
+
f"List: {job_titles}\n"
|
79 |
+
"First job title:"
|
80 |
+
)
|
81 |
+
|
82 |
+
st.write("Prompt inicial con In-context Learning:")
|
83 |
+
st.write(initial_prompt)
|
84 |
|
85 |
if st.button("Generar respuesta"):
|
86 |
with st.spinner("Generando respuesta..."):
|
|
|
101 |
|
102 |
if __name__ == "__main__":
|
103 |
main()
|
104 |
+
|