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
Mohamad Al Mdfaa 2023-06-17 12:36:16 +03:00 committed by GitHub
parent 16292e162d
commit 9389fa492b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 3 deletions

View File

@ -250,8 +250,10 @@ class Model:
def phrases2classes(phrases: List[str], classes: List[str]) -> np.ndarray: def phrases2classes(phrases: List[str], classes: List[str]) -> np.ndarray:
class_ids = [] class_ids = []
for phrase in phrases: for phrase in phrases:
try: for class_ in classes:
class_ids.append(classes.index(phrase)) if class_ in phrase:
except ValueError: class_ids.append(classes.index(class_))
break
else:
class_ids.append(None) class_ids.append(None)
return np.array(class_ids) return np.array(class_ids)