fix: improve phrases2classes implementation (#143)
This commit improves the phrases2classes implementation by using a regular expression to match sub-phrases in the phrases list. This makes the implementation more accurate and efficient.pull/160/head
parent
16292e162d
commit
9389fa492b
|
@ -250,8 +250,10 @@ class Model:
|
|||
def phrases2classes(phrases: List[str], classes: List[str]) -> np.ndarray:
|
||||
class_ids = []
|
||||
for phrase in phrases:
|
||||
try:
|
||||
class_ids.append(classes.index(phrase))
|
||||
except ValueError:
|
||||
for class_ in classes:
|
||||
if class_ in phrase:
|
||||
class_ids.append(classes.index(class_))
|
||||
break
|
||||
else:
|
||||
class_ids.append(None)
|
||||
return np.array(class_ids)
|
||||
|
|
Loading…
Reference in New Issue