11import re
22
3- import jieba # type: ignore
43from inspect_ai .scorer import Score , Scorer , Target , mean , scorer , stderr
54from inspect_ai .solver import TaskState
6- from rouge import Rouge # type: ignore
7- from sentence_transformers import SentenceTransformer , util
85
96SENTENCE_TRANSFORMER_REPO = (
107 "sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2"
@@ -24,6 +21,9 @@ def split_sentences(text: str, is_zh: bool) -> list[str]:
2421
2522def tokenize_sentence (sentence : str , is_zh : bool ) -> str :
2623 """Tokenize sentences (for ROUGE-L scoring)."""
24+ # Import jieba here to avoid loading it in the global scope
25+ import jieba # type: ignore
26+
2727 return " " .join (jieba .cut (sentence )) if is_zh else sentence
2828
2929
@@ -58,6 +58,9 @@ def rouge_l_scorer(is_zh: bool) -> Scorer:
5858 and provides the result alongside the model-generated output and a
5959 detailed explanation.
6060 """
61+ # Import rouge here to avoid loading it in the global scope
62+ from rouge import Rouge # type: ignore
63+
6164 rouge = Rouge ()
6265
6366 async def score (state : TaskState , target : Target ) -> Score :
@@ -111,6 +114,9 @@ def semantic_similarity_scorer() -> Scorer:
111114 Scorer: A scoring function that computes semantic similarity and provides
112115 both the similarity score and a detailed explanation of the result.
113116 """
117+ # Import SentenceTransformer here to avoid loading it in the global scope
118+ from sentence_transformers import SentenceTransformer , util # type: ignore
119+
114120 model = SentenceTransformer (SENTENCE_TRANSFORMER_REPO )
115121
116122 async def score (state : TaskState , target : Target ) -> Score :
0 commit comments