llm-ie 0.2.0__tar.gz → 0.2.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {llm_ie-0.2.0 → llm_ie-0.2.2}/PKG-INFO +1 -1
- {llm_ie-0.2.0 → llm_ie-0.2.2}/pyproject.toml +1 -1
- {llm_ie-0.2.0 → llm_ie-0.2.2}/src/llm_ie/data_types.py +81 -1
- {llm_ie-0.2.0 → llm_ie-0.2.2}/src/llm_ie/extractors.py +1 -1
- {llm_ie-0.2.0 → llm_ie-0.2.2}/README.md +0 -0
- {llm_ie-0.2.0 → llm_ie-0.2.2}/src/llm_ie/__init__.py +0 -0
- {llm_ie-0.2.0 → llm_ie-0.2.2}/src/llm_ie/asset/PromptEditor_prompts/comment.txt +0 -0
- {llm_ie-0.2.0 → llm_ie-0.2.2}/src/llm_ie/asset/PromptEditor_prompts/rewrite.txt +0 -0
- {llm_ie-0.2.0 → llm_ie-0.2.2}/src/llm_ie/asset/prompt_guide/BasicFrameExtractor_prompt_guide.txt +0 -0
- {llm_ie-0.2.0 → llm_ie-0.2.2}/src/llm_ie/asset/prompt_guide/BinaryRelationExtractor_prompt_guide.txt +0 -0
- {llm_ie-0.2.0 → llm_ie-0.2.2}/src/llm_ie/asset/prompt_guide/MultiClassRelationExtractor_prompt_guide.txt +0 -0
- {llm_ie-0.2.0 → llm_ie-0.2.2}/src/llm_ie/asset/prompt_guide/ReviewFrameExtractor_prompt_guide.txt +0 -0
- {llm_ie-0.2.0 → llm_ie-0.2.2}/src/llm_ie/asset/prompt_guide/SentenceFrameExtractor_prompt_guide.txt +0 -0
- {llm_ie-0.2.0 → llm_ie-0.2.2}/src/llm_ie/engines.py +0 -0
- {llm_ie-0.2.0 → llm_ie-0.2.2}/src/llm_ie/prompt_editor.py +0 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
from typing import List, Dict, Iterable
|
|
1
|
+
from typing import List, Dict, Tuple, Iterable, Callable
|
|
2
|
+
import importlib.util
|
|
2
3
|
import json
|
|
3
4
|
|
|
4
5
|
|
|
@@ -281,3 +282,82 @@ class LLMInformationExtractionDocument:
|
|
|
281
282
|
json_file, indent=4)
|
|
282
283
|
json_file.flush()
|
|
283
284
|
|
|
285
|
+
|
|
286
|
+
def _viz_preprocess(self) -> Tuple:
|
|
287
|
+
"""
|
|
288
|
+
This method preprocesses the entities and relations for visualization.
|
|
289
|
+
"""
|
|
290
|
+
if importlib.util.find_spec("ie_viz") is None:
|
|
291
|
+
raise ImportError("ie_viz not found. Please install ie_viz (```pip install ie-viz```).")
|
|
292
|
+
|
|
293
|
+
if self.has_frame():
|
|
294
|
+
entities = [{"entity_id": frame.frame_id, "start": frame.start, "end": frame.end, "attr": frame.attr} for frame in self.frames]
|
|
295
|
+
else:
|
|
296
|
+
raise ValueError("No frames in the document.")
|
|
297
|
+
|
|
298
|
+
if self.has_relation():
|
|
299
|
+
relations = []
|
|
300
|
+
for relation in self.relations:
|
|
301
|
+
rel = {"entity_1_id": relation['frame_1'], "entity_2_id": relation['frame_2']}
|
|
302
|
+
relations.append(rel)
|
|
303
|
+
else:
|
|
304
|
+
relations = None
|
|
305
|
+
|
|
306
|
+
return entities, relations
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
def viz_serve(self, host: str = '0.0.0.0', port: int = 5000, theme:str = "light",
|
|
310
|
+
color_attr_key:str=None, color_map_func:Callable=None):
|
|
311
|
+
"""
|
|
312
|
+
This method serves a visualization App of the document.
|
|
313
|
+
|
|
314
|
+
Parameters:
|
|
315
|
+
-----------
|
|
316
|
+
host : str, Optional
|
|
317
|
+
The host address to run the server on.
|
|
318
|
+
port : int, Optional
|
|
319
|
+
The port number to run the server on.
|
|
320
|
+
theme : str, Optional
|
|
321
|
+
The theme of the visualization. Must be either "light" or "dark".
|
|
322
|
+
color_attr_key : str, Optional
|
|
323
|
+
The attribute key to be used for coloring the entities.
|
|
324
|
+
color_map_func : Callable, Optional
|
|
325
|
+
The function to be used for mapping the entity attributes to colors. When provided, the color_attr_key and
|
|
326
|
+
theme will be overwritten. The function must take an entity dictionary as input and return a color string (hex).
|
|
327
|
+
"""
|
|
328
|
+
entities, relations = self._viz_preprocess()
|
|
329
|
+
from ie_viz import serve
|
|
330
|
+
|
|
331
|
+
serve(text=self.text,
|
|
332
|
+
entities=entities,
|
|
333
|
+
relations=relations,
|
|
334
|
+
host=host,
|
|
335
|
+
port=port,
|
|
336
|
+
theme=theme,
|
|
337
|
+
color_attr_key=color_attr_key,
|
|
338
|
+
color_map_func=color_map_func)
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
def viz_render(self, theme:str = "light", color_attr_key:str=None, color_map_func:Callable=None) -> str:
|
|
342
|
+
"""
|
|
343
|
+
This method renders visualization html of the document.
|
|
344
|
+
|
|
345
|
+
Parameters:
|
|
346
|
+
-----------
|
|
347
|
+
theme : str, Optional
|
|
348
|
+
The theme of the visualization. Must be either "light" or "dark".
|
|
349
|
+
color_attr_key : str, Optional
|
|
350
|
+
The attribute key to be used for coloring the entities.
|
|
351
|
+
color_map_func : Callable, Optional
|
|
352
|
+
The function to be used for mapping the entity attributes to colors. When provided, the color_attr_key and
|
|
353
|
+
theme will be overwritten. The function must take an entity dictionary as input and return a color string (hex).
|
|
354
|
+
"""
|
|
355
|
+
entities, relations = self._viz_preprocess()
|
|
356
|
+
from ie_viz import render
|
|
357
|
+
|
|
358
|
+
return render(text=self.text,
|
|
359
|
+
entities=entities,
|
|
360
|
+
relations=relations,
|
|
361
|
+
theme=theme,
|
|
362
|
+
color_attr_key=color_attr_key,
|
|
363
|
+
color_map_func=color_map_func)
|
|
@@ -896,7 +896,7 @@ class MultiClassRelationExtractor(RelationExtractor):
|
|
|
896
896
|
if len(rel_json) > 0:
|
|
897
897
|
if "RelationType" in rel_json[0]:
|
|
898
898
|
rel = rel_json[0]["RelationType"]
|
|
899
|
-
if rel in pos_rel_types:
|
|
899
|
+
if rel in pos_rel_types or rel == "No Relation":
|
|
900
900
|
return rel_json[0]["RelationType"]
|
|
901
901
|
else:
|
|
902
902
|
warnings.warn(f'Extracted relation type "{rel}", which is not in the return of possible_relation_types_func: {pos_rel_types}.'+ \
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{llm_ie-0.2.0 → llm_ie-0.2.2}/src/llm_ie/asset/prompt_guide/BasicFrameExtractor_prompt_guide.txt
RENAMED
|
File without changes
|
{llm_ie-0.2.0 → llm_ie-0.2.2}/src/llm_ie/asset/prompt_guide/BinaryRelationExtractor_prompt_guide.txt
RENAMED
|
File without changes
|
|
File without changes
|
{llm_ie-0.2.0 → llm_ie-0.2.2}/src/llm_ie/asset/prompt_guide/ReviewFrameExtractor_prompt_guide.txt
RENAMED
|
File without changes
|
{llm_ie-0.2.0 → llm_ie-0.2.2}/src/llm_ie/asset/prompt_guide/SentenceFrameExtractor_prompt_guide.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|