llm-ie 0.2.0__py3-none-any.whl → 0.2.2__py3-none-any.whl

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/data_types.py CHANGED
@@ -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)
llm_ie/extractors.py CHANGED
@@ -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}.'+ \
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: llm-ie
3
- Version: 0.2.0
3
+ Version: 0.2.2
4
4
  Summary: An LLM-powered tool that transforms everyday language into robust information extraction pipelines.
5
5
  License: MIT
6
6
  Author: Enshuo (David) Hsu
@@ -6,10 +6,10 @@ llm_ie/asset/prompt_guide/BinaryRelationExtractor_prompt_guide.txt,sha256=z9Xg0f
6
6
  llm_ie/asset/prompt_guide/MultiClassRelationExtractor_prompt_guide.txt,sha256=D5DphUHw8SUERUVdcIjUynuTmYJa6-PwBlF7FzxNsvQ,2276
7
7
  llm_ie/asset/prompt_guide/ReviewFrameExtractor_prompt_guide.txt,sha256=XbnU8byLGGUA3A3lT0bb2Hw-ggzhcqD3ZuKzduod2ww,1944
8
8
  llm_ie/asset/prompt_guide/SentenceFrameExtractor_prompt_guide.txt,sha256=8nj9OLPJMtr9Soi5JU3Xk-HC7pKNoI54xA_A4u7I5j4,2620
9
- llm_ie/data_types.py,sha256=2RKP4wXDuku-Tn4s8uzzUFavG1fZ2e47SaY8oL57LsI,10923
9
+ llm_ie/data_types.py,sha256=hPz3WOeAzfn2QKmb0CxHmRdQWZQ4G9zq8U-RJBVFdYk,14329
10
10
  llm_ie/engines.py,sha256=m9ytGUX61jEy9SmVHbb90mrfGMAwC6dV-v7Jke1U7Ho,9296
11
- llm_ie/extractors.py,sha256=i0m8uFaKXiVY1ucjvzbUFbV1slPYfZ3EGOZrolnFVHA,44079
11
+ llm_ie/extractors.py,sha256=EVuHqW1lW0RpGmnRNmX4ih6ppfvy2gYOAOgc8Pngfkw,44103
12
12
  llm_ie/prompt_editor.py,sha256=dbu7A3O7O7Iw2v-xCgrTFH1-wTLAGf4SHDqdeS-He2Q,1869
13
- llm_ie-0.2.0.dist-info/METADATA,sha256=9CPC3OAd2J0nROZ7z8DI7lvGKOO2H2uAnVQv_YDFItg,40052
14
- llm_ie-0.2.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
15
- llm_ie-0.2.0.dist-info/RECORD,,
13
+ llm_ie-0.2.2.dist-info/METADATA,sha256=V7gi1wZN_FlaW2ZfdsGKtEGi2s-AjIvssrkjjd7ubWU,40052
14
+ llm_ie-0.2.2.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
15
+ llm_ie-0.2.2.dist-info/RECORD,,
File without changes