Spaces:
Sleeping
Sleeping
Update ✨Entity Linking Application✨.py
Browse files- ✨Entity Linking Application✨.py +69 -75
✨Entity Linking Application✨.py
CHANGED
|
@@ -283,7 +283,6 @@ def main_cli():
|
|
| 283 |
input_sentence_user = st.text_input("Enter a sentence:", "", disabled=st.session_state.running)
|
| 284 |
input_mention_user = st.text_input("Enter a textural reference (mention) that is inside the sentence:", "", disabled=st.session_state.running)
|
| 285 |
deep_search = st.selectbox("Perform deep search? (Useful for difficult mentions)", ['Yes', 'No'], index=1, disabled=st.session_state.running)
|
| 286 |
-
disambi = st.selectbox("Run acronym disambiguation? (Enable it if the mention include an acronym or if it is nested)", ['Yes', 'No'], index=0, disabled=st.session_state.running)
|
| 287 |
|
| 288 |
if st.button("Run Entity Linking", key="run_button", disabled=st.session_state.running):
|
| 289 |
if input_sentence_user and input_mention_user:
|
|
@@ -296,82 +295,77 @@ def main_cli():
|
|
| 296 |
list_with_full_names = []
|
| 297 |
list_with_names_to_show = []
|
| 298 |
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
|
| 344 |
-
|
| 345 |
-
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
|
| 358 |
-
|
| 359 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 360 |
|
| 361 |
-
|
| 362 |
-
print(response.choices[0].message.content)
|
| 363 |
-
for i in kati:
|
| 364 |
-
context = i.split(":")[-1].strip()
|
| 365 |
-
original_name = i.split(":")[0].strip()
|
| 366 |
-
list_with_full_names.append(context)
|
| 367 |
-
list_with_names_to_show.append(original_name)
|
| 368 |
-
|
| 369 |
-
name = ",".join(list_with_full_names)
|
| 370 |
|
| 371 |
-
else:
|
| 372 |
-
name = input_mention_user
|
| 373 |
-
list_with_full_names.append(name)
|
| 374 |
-
list_with_names_to_show.append(name)
|
| 375 |
|
| 376 |
input_sentence_user = input_sentence_user.replace(input_mention_user, name) # Changing the mention to the correct one
|
| 377 |
|
|
|
|
| 283 |
input_sentence_user = st.text_input("Enter a sentence:", "", disabled=st.session_state.running)
|
| 284 |
input_mention_user = st.text_input("Enter a textural reference (mention) that is inside the sentence:", "", disabled=st.session_state.running)
|
| 285 |
deep_search = st.selectbox("Perform deep search? (Useful for difficult mentions)", ['Yes', 'No'], index=1, disabled=st.session_state.running)
|
|
|
|
| 286 |
|
| 287 |
if st.button("Run Entity Linking", key="run_button", disabled=st.session_state.running):
|
| 288 |
if input_sentence_user and input_mention_user:
|
|
|
|
| 295 |
list_with_full_names = []
|
| 296 |
list_with_names_to_show = []
|
| 297 |
|
| 298 |
+
response = client.chat.completions.create(
|
| 299 |
+
messages=[
|
| 300 |
+
{
|
| 301 |
+
"role": "system",
|
| 302 |
+
"content": """
|
| 303 |
+
I will give you one or more labels within a sentence. Your task is as follows:
|
| 304 |
+
|
| 305 |
+
Identify each label in the sentence, and check if it is an acronym.
|
| 306 |
+
|
| 307 |
+
If the label is an acronym, respond with the full name of the acronym.
|
| 308 |
+
If the label is not an acronym, respond with the label exactly as it was given to you.
|
| 309 |
+
If a label contains multiple terms (e.g., 'phase and DIC microscopy'), treat each term within the label as a separate label.
|
| 310 |
+
|
| 311 |
+
This means you should identify and explain each part of the label individually.
|
| 312 |
+
Each part should be on its own line in the response.
|
| 313 |
+
Context-Specific Terms: If the sentence context suggests a relevant term that applies to each label (such as "study" in 'morphological, sedimentological, and stratigraphical study'), add that term to each label’s explanation.
|
| 314 |
+
|
| 315 |
+
Use context clues to determine the appropriate term to add (e.g., 'study' or 'microscopy').
|
| 316 |
+
Output Format: Your response should contain only the explanations, formatted as follows:
|
| 317 |
+
|
| 318 |
+
Each label or part of a label should be on a new line.
|
| 319 |
+
Do not include any additional text, and do not repeat the original sentence.
|
| 320 |
+
Example 1:
|
| 321 |
+
|
| 322 |
+
Input:
|
| 323 |
+
|
| 324 |
+
label: phase and DIC microscopy
|
| 325 |
+
context: Tardigrades have been extracted from samples using centrifugation with Ludox AM™ and mounted on individual microscope slides in Hoyer's medium for identification under phase and DIC microscopy.
|
| 326 |
+
Expected response:
|
| 327 |
+
|
| 328 |
+
phase: phase microscopy
|
| 329 |
+
DIC microscopy: Differential interference contrast microscopy
|
| 330 |
+
Example 2:
|
| 331 |
+
|
| 332 |
+
Input:
|
| 333 |
+
|
| 334 |
+
label: morphological, sedimentological, and stratigraphical study
|
| 335 |
+
context: This paper presents results of a morphological, sedimentological, and stratigraphical study of relict beach ridges formed on a prograded coastal barrier in Bream Bay, North Island New Zealand.
|
| 336 |
+
Expected response:
|
| 337 |
+
|
| 338 |
+
morphological: morphological study
|
| 339 |
+
sedimentological: sedimentological study
|
| 340 |
+
stratigraphical: stratigraphical study
|
| 341 |
+
IMPORTANT:
|
| 342 |
+
|
| 343 |
+
Each label, even if nested within another, should be treated as an individual item.
|
| 344 |
+
Each individual label or acronym should be output on a separate line.
|
| 345 |
+
"""
|
| 346 |
+
},
|
| 347 |
+
{
|
| 348 |
+
"role": "user",
|
| 349 |
+
"content": f"label:{input_mention_user}, context:{input_sentence_user}"
|
| 350 |
+
}
|
| 351 |
+
],
|
| 352 |
+
temperature=1.0,
|
| 353 |
+
top_p=1.0,
|
| 354 |
+
max_tokens=1000,
|
| 355 |
+
model=model_name
|
| 356 |
+
)
|
| 357 |
+
|
| 358 |
+
|
| 359 |
+
kati = response.choices[0].message.content.splitlines()
|
| 360 |
+
print(response.choices[0].message.content)
|
| 361 |
+
for i in kati:
|
| 362 |
+
context = i.split(":")[-1].strip()
|
| 363 |
+
original_name = i.split(":")[0].strip()
|
| 364 |
+
list_with_full_names.append(context)
|
| 365 |
+
list_with_names_to_show.append(original_name)
|
| 366 |
|
| 367 |
+
name = ",".join(list_with_full_names)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 368 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 369 |
|
| 370 |
input_sentence_user = input_sentence_user.replace(input_mention_user, name) # Changing the mention to the correct one
|
| 371 |
|