Skip to content

Commit

Permalink
Add set_name to SS3 and fix bug in SS3.learn
Browse files Browse the repository at this point in the history
The ``set_name`` method allows to set the model's name after the object
creation.

There was a bug when learning documents when using non-string category
label, now the learn method properly supports non-string category
labels.
  • Loading branch information
sergioburdisso committed Feb 19, 2020
1 parent 31eccbc commit 5b1c355
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion pyss3/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,8 @@ def __get_category__(self, name):
If category name doesn't exist, creates a new one.
"""
name = name.lower()
if type(name) is str:
name = name.lower()
try:
return self.__categories_index__[name]
except KeyError:
Expand Down Expand Up @@ -841,6 +842,15 @@ def get_name(self):
"""
return self.__name__

def set_name(self, name):
"""
Set the model's name.
:param name: the model's name.
:type name: str
"""
self.__name__ = name

def set_hyperparameters(self, s=None, l=None, p=None, a=None):
"""
Set hyperparameter values.
Expand Down Expand Up @@ -2044,13 +2054,16 @@ def fit(self, x_train, y_train, n_grams=1, prep=True, leave_pbar=True):
y_train = list(cats)

Print.info("about to start training", offset=1)
verbosity = Print.get_verbosity()
Print.set_verbosity(VERBOSITY.NORMAL)
for i in tqdm(range(len(x_train)), desc=" Training",
leave=leave_pbar, disable=Print.is_quiet()):
self.learn(
x_train[i], y_train[i],
n_grams=n_grams, prep=prep, update=False
)
self.__prune_tries__()
Print.set_verbosity(verbosity)
Print.info("finished --time: %.1fs" % (time() - stime), offset=1)
self.update_values(force=True)

Expand Down

0 comments on commit 5b1c355

Please sign in to comment.