-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Added warning for unsupported Facebook FastText modes #3223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added warning for unsupported Facebook FastText modes #3223
Conversation
@mpenkov, any feedback on this PR? it's my 1st contribution, lemme know if I have done it correctly? |
loss_names = {0 : "Negative_Sampling_Loss", 1 : "Hierarchical_Softmax_Loss", 2 : "Softmax_Loss", 3 : "OneVsAll_Loss"} | ||
model_name = {1 : "Continuous_Bag_Of_Words", 2 : "Skip_Gram", 3 : "Supervised"} | ||
if m.loss == 3 or m.loss == 4: | ||
warnings.warn(f'Provided an un-supported Facebook FastText loss mode (i.e. un-supported loss: {loss_names[m.loss]}), \n it may lead to inconsistent gensim model likely to fail later. \n Currently Supported loss modes are {loss_names[0]}, {loss_names[1]}') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't unsupported modes raise an exception? What's the use-case for loading an unsupported mode with a warning?
warnings.warn(f'Provided an un-supported Facebook FastText loss mode (i.e. un-supported loss: {loss_names[m.loss]}), \n it may lead to inconsistent gensim model likely to fail later. \n Currently Supported loss modes are {loss_names[0]}, {loss_names[1]}') | |
logger.warning(f"{model_file } contains an unsupported Facebook FastText loss mode '{loss_names[m.loss]}'. Loading it may lead to errors later on. Supported loss modes are '{loss_names[0]}', '{loss_names[1]}'.") |
@@ -807,6 +809,14 @@ def _load_fasttext_format(model_file, encoding='utf-8', full_model=True): | |||
with utils.open(model_file, 'rb') as fin: | |||
m = gensim.models._fasttext_bin.load(fin, encoding=encoding, full_model=full_model) | |||
|
|||
# Warnings regarding unsupported FB FT modes | |||
loss_names = {0 : "Negative_Sampling_Loss", 1 : "Hierarchical_Softmax_Loss", 2 : "Softmax_Loss", 3 : "OneVsAll_Loss"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code style: no space before :
:
Here and also in the line below please.
loss_names = {0 : "Negative_Sampling_Loss", 1 : "Hierarchical_Softmax_Loss", 2 : "Softmax_Loss", 3 : "OneVsAll_Loss"} | |
loss_names = {0: "Negative_Sampling_Loss", 1: "Hierarchical_Softmax_Loss", 2: "Softmax_Loss", 3: "OneVsAll_Loss"} |
if m.loss == 3 or m.loss == 4: | ||
warnings.warn(f'Provided an un-supported Facebook FastText loss mode (i.e. un-supported loss: {loss_names[m.loss]}), \n it may lead to inconsistent gensim model likely to fail later. \n Currently Supported loss modes are {loss_names[0]}, {loss_names[1]}') | ||
if m.model == 3: | ||
warnings.warn(f'Provided an un-supported Facebook FastText model mode (i.e. un-supported loss: {model_name[m.model]}), \n it may lead to inconsistent gensim model likely to fail later. \n Currently Supported model modes are {model_name[1]}, {model_name[2]}') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dtto as above: either logger.warning
, or an exception.
Closing in favour of #3222 because it's simpler. But thanks for contribution! |
Fixes #3179: warn the user about the unsupported FastText mode they have chosen, and also inform them what the supported modes are.