Skip to content

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

Closed

Conversation

karan121bhukar
Copy link

@karan121bhukar karan121bhukar commented Aug 31, 2021

Fixes #3179: warn the user about the unsupported FastText mode they have chosen, and also inform them what the supported modes are.

@karan121bhukar
Copy link
Author

@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]}')
Copy link
Owner

@piskvorky piskvorky Feb 19, 2022

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?

Suggested change
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"}
Copy link
Owner

@piskvorky piskvorky Feb 19, 2022

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.

Suggested change
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]}')
Copy link
Owner

@piskvorky piskvorky Feb 19, 2022

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.

@piskvorky piskvorky changed the title Added warning for unsupported FB FT modes #3179 Added warning for unsupported FB FT modes Feb 19, 2022
@piskvorky piskvorky changed the title Added warning for unsupported FB FT modes Added warning for unsupported Facebook FastText modes Feb 19, 2022
@piskvorky
Copy link
Owner

Closing in favour of #3222 because it's simpler. But thanks for contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Gensim's FastText model reads in unsupported modes from Facebook's FastText
2 participants