Skip to content
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 "tensorflow.keras" compatibility in "KeyedVectors.get_keras_embedding" function. #2911

Closed
wants to merge 1 commit into from

Conversation

andrewsapw
Copy link

@andrewsapw andrewsapw commented Aug 3, 2020

Since TensorFlow 2.0+, Keras is the part of TensorFlow library, so I added "from tensorflow.keras.layers import Embedding" as possible import to "Embedding" layer (the old way to import is allowed too) in "get_keras_embedding" function.

Fixes #2842 and closes #2729.

Since TensorFlow 2.0+, Keras is the part of TensorFlow library, so I added "from tensorflow.keras.layers import Embedding" as possible import to "Embedding" layer (the old way to import is allowed too) in "get_keras_embedding" function.
@piskvorky
Copy link
Owner

Thanks! A duplicate of #2729 (and #2842) but those are stale, so let's continue here.

@piskvorky piskvorky requested a review from mpenkov August 3, 2020 14:12
@piskvorky piskvorky added this to the 4.0.0 milestone Aug 3, 2020
@gojomo
Copy link
Collaborator

gojomo commented Aug 4, 2020

For the reasons listed in #2886, and in the spirit of #2873 (slim this module) & #2852 (reduce gensim surface area), I'd prefer to remove this one-line-of-recipe code from KeyedVectors.

It could easily live as a utility function elsewhere, or just be part of some example code in some doc/tutorial/notebook.

It's not inherent to the KeyedVectors type, and conditional-importing inside a method is a pretty bad 'code smell' indicating this is out-of-place.

@piskvorky
Copy link
Owner

piskvorky commented Aug 4, 2020

That is true, though mostly orthogonal to this PR. We want both {modernize import, move fnc elsewhere}.

@andrewsapw as a user, where would you expect this function to live, were would you look for it first?
What's your use-case when calling it?

@andrewsapw
Copy link
Author

andrewsapw commented Aug 4, 2020

That is true, though mostly orthogonal to this PR. We want both {modernize import, move fnc elsewhere}.

@andrewsapw as a user, where would you expect this function to live, were would you look for it first?
What's your use-case when calling it?

I agree that KeyedVectors if pretty big, and because of that it's not always obvious how to use it. On the other hand, this function is actual helpful for newbies, so mb gensim.utils is the right place for such small functions.
Regarding tutorials, it's hard to navigate there: plenty of notebooks and all kind of files (.png, .gif, .md and so on) in one place, so i think it can be reorganized to be more friendly to new people, maybe I can help with that.

@piskvorky
Copy link
Owner

piskvorky commented Aug 4, 2020

Are you talking about the official tutorials, https://radimrehurek.com/gensim/auto_examples/index.html ?

Or what .png, .gif files?

@andrewsapw
Copy link
Author

@gojomo
Copy link
Collaborator

gojomo commented Aug 4, 2020

If it needs a module, maybe a new gensim.keras or gensim.integrations.keras. But really, since the functionality is just...

https://github.com/RaRe-Technologies/gensim/blob/4b7e372cf289b1bfa154db28a042618f96e91226/gensim/models/keyedvectors.py#L1619-L1627

...putting it in a "example of using gensim word-vectors with Keras" wiki page, or demo-notebook, would be just as understandable/discoverable as the existing utility function.

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.

KeyedVectors importing keras instead of tensorflow.keras?
3 participants