wuenlp_tools.models.ssc
Local SSC model inference (scene + suspense) without HTTP APIs.
1"""Local SSC model inference (scene + suspense) without HTTP APIs.""" 2 3from wuenlp_tools.models.ssc.local import ( 4 is_ssc_local_enabled, 5 resolve_scene_model_path, 6 resolve_suspense_model_path, 7 scene_segment_local, 8 suspense_annotate_local, 9) 10 11__all__ = [ 12 "is_ssc_local_enabled", 13 "resolve_scene_model_path", 14 "resolve_suspense_model_path", 15 "scene_segment_local", 16 "suspense_annotate_local", 17]
def
is_ssc_local_enabled() -> bool:
def
resolve_scene_model_path() -> str:
def
resolve_suspense_model_path(task: str) -> str:
132def resolve_suspense_model_path(task: str) -> str: 133 task_key = task.lower() 134 env_key = f"SSC_MODEL_{task_key.upper()}" 135 if env_key in os.environ: 136 return os.environ[env_key] 137 root = get_ssc_suspense_model_root() 138 suffix = _SUSPENSE_CHECKPOINT_SUFFIXES[task_key] 139 prefix = _SUSPENSE_TASK_PREFIX[task_key] 140 return f"{root}/{prefix}_{suffix}"
def
scene_segment_local( doc: wuenlp.impl.uima.UIMANLPStructs.UIMADocument, *, overwrite: bool = False) -> wuenlp.impl.uima.UIMANLPStructs.UIMADocument:
172def scene_segment_local(doc: UIMADocument, *, overwrite: bool = False) -> UIMADocument: 173 if doc.system_scenes and not overwrite: 174 logger.info("Document {} already has system scenes. Skipping", doc) 175 return doc 176 LabelSet, _, _, annotate_document = _load_ssc_modules() 177 model = _get_scene_model(resolve_scene_model_path()) 178 with _ssc_import_context(): 179 from model import SSCClassLabel 180 181 label_set = SSCClassLabel.from_dict( 182 { 183 "names": list(_SCENE_COARSE_LABEL_NAMES), 184 "annotated_type_str": "UIMASystemScene", 185 } 186 ) 187 model.config.label_set = label_set 188 return annotate_document(doc=doc, model=model, overwrite=overwrite, label_set=label_set)
def
suspense_annotate_local( doc: wuenlp.impl.uima.UIMANLPStructs.UIMADocument, task: str, *, overwrite: bool = False) -> wuenlp.impl.uima.UIMANLPStructs.UIMADocument:
191def suspense_annotate_local( 192 doc: UIMADocument, 193 task: str, 194 *, 195 overwrite: bool = False, 196) -> UIMADocument: 197 task_key = task.lower() 198 if task_key not in _TASK_LABEL_SETS: 199 raise ValueError(f"Unknown suspense task {task!r}") 200 LabelSet, _, _, annotate_document = _load_ssc_modules() 201 model_path = resolve_suspense_model_path(task_key) 202 model = _get_suspense_model(task_key, model_path) 203 label_set = _resolve_task_label_set(task_key) 204 model.config.label_set = label_set 205 return annotate_document(doc=doc, model=model, overwrite=overwrite, label_set=label_set)