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

setting emb_szs colab_learner is ignored causing function call to exit in error #3986

Open
watplatt opened this issue Dec 2, 2023 · 0 comments

Comments

@watplatt
Copy link

watplatt commented Dec 2, 2023

Be sure you've searched the forums for the error message you received. Also, unless you're an experienced fastai developer, first ask on the forums to see if someone else has seen a similar issue already and knows how to solve it. Only file a bug report here when you're quite confident it's not an issue with your local setup.

Please see this model example of how to fill out an issue correctly. Please try to emulate that example as appropriate when opening an issue.

Please confirm you have the latest versions of fastai, fastcore, and nbdev prior to reporting a bug (delete one): YES / NO

Name: fastcore
Version: 1.5.29

Name: fastai
Version: 2.7.12

nbdev not installed.

Describe the bug
A clear and concise description of what the bug is.

learn = collab_learner(dls, n_factors = 4, use_nn=True, emb_szs=[(165328, 4), (185, 4)], y_range=(-30.0, 30.0), layers=[100,50])

yields the following error message:

AttributeError Traceback (most recent call last)
Input In [70], in <cell line: 8>()
...
----> 8 learn = collab_learner(dls, n_factors = 4, use_nn=True, emb_szs=[(165328, 4), (185, 4)], y_range=(-30.0, 30.0), layers=[100,50]) # use_nn=True - neural net

File ~/.conda/envs/myfastai/lib/python3.9/site-packages/fastai/collab.py:95, in collab_learner(dls, n_factors, use_nn, emb_szs, layers, config, y_range, loss_func, **kwargs)
92 @Delegates(Learner.init)
93 def collab_learner(dls, n_factors=50, use_nn=False, emb_szs=None, layers=None, config=None, y_range=None, loss_func=None, **kwargs):
94 "Create a Learner for collaborative filtering on dls."
---> 95 emb_szs = get_emb_sz(dls, ifnone(emb_szs, {}))
96 if loss_func is None: loss_func = MSELossFlat()
97 if config is None: config = tabular_config()

File ~/.conda/envs/myfastai/lib/python3.9/site-packages/fastai/tabular/model.py:32, in get_emb_sz(to, sz_dict)
27 def get_emb_sz(
28 to:Tabular|TabularPandas,
29 sz_dict:dict=None # Dictionary of {'class_name' : size, ...} to override default emb_sz_rule
30 ) -> list: # List of embedding sizes for each category
31 "Get embedding size for each cat_name in Tabular or TabularPandas, or populate embedding size manually using sz_dict"
---> 32 return [_one_emb_sz(to.classes, n, sz_dict) for n in to.cat_names]

File ~/.conda/envs/myfastai/lib/python3.9/site-packages/fastai/tabular/model.py:32, in (.0)
27 def get_emb_sz(
28 to:Tabular|TabularPandas,
29 sz_dict:dict=None # Dictionary of {'class_name' : size, ...} to override default emb_sz_rule
30 ) -> list: # List of embedding sizes for each category
31 "Get embedding size for each cat_name in Tabular or TabularPandas, or populate embedding size manually using sz_dict"
---> 32 return [_one_emb_sz(to.classes, n, sz_dict) for n in to.cat_names]

File ~/.conda/envs/myfastai/lib/python3.9/site-packages/fastai/tabular/model.py:23, in _one_emb_sz(classes, n, sz_dict)
21 sz_dict = ifnone(sz_dict, {})
22 n_cat = len(classes[n])
---> 23 sz = sz_dict.get(n, int(emb_sz_rule(n_cat))) # rule of thumb
24 return n_cat,sz

AttributeError: 'list' object has no attribute 'get'

To Reproduce
Steps to reproduce the behavior:

  1. pass a dls whose emb_szs showed
  2. emb_szs = get_emb_sz(dls.train_ds, {})
    print(emb_szs)

[(165328, 600), (185, 30)]

So the number of users and items were the same; just the embedding vector lengths were changed.

Expected behavior
A clear and concise description of what you expected to happen.

I expected it to return a functioning learner.

Error with full stack trace

Place between these lines with triple backticks:

AttributeError                            Traceback (most recent call last)
Input In [70], in <cell line: 8>()
...
----> 8 learn = collab_learner(dls, n_factors = 4, use_nn=True, emb_szs=[(165328, 4), (185, 4)], y_range=(-30.0, 30.0), layers=[100,50]) # use_nn=True - neural net

File ~/.conda/envs/myfastai/lib/python3.9/site-packages/fastai/collab.py:95, in collab_learner(dls, n_factors, use_nn, emb_szs, layers, config, y_range, loss_func, **kwargs)
     92 @delegates(Learner.__init__)
     93 def collab_learner(dls, n_factors=50, use_nn=False, emb_szs=None, layers=None, config=None, y_range=None, loss_func=None, **kwargs):
     94     "Create a Learner for collaborative filtering on `dls`."
---> 95     emb_szs = get_emb_sz(dls, ifnone(emb_szs, {}))
     96     if loss_func is None: loss_func = MSELossFlat()
     97     if config is None: config = tabular_config()

File ~/.conda/envs/myfastai/lib/python3.9/site-packages/fastai/tabular/model.py:32, in get_emb_sz(to, sz_dict)
     27 def get_emb_sz(
     28     to:Tabular|TabularPandas, 
     29     sz_dict:dict=None # Dictionary of {'class_name' : size, ...} to override default `emb_sz_rule` 
     30 ) -> list: # List of embedding sizes for each category
     31     "Get embedding size for each cat_name in `Tabular` or `TabularPandas`, or populate embedding size manually using sz_dict"
---> 32     return [_one_emb_sz(to.classes, n, sz_dict) for n in to.cat_names]

File ~/.conda/envs/myfastai/lib/python3.9/site-packages/fastai/tabular/model.py:32, in <listcomp>(.0)
     27 def get_emb_sz(
     28     to:Tabular|TabularPandas, 
     29     sz_dict:dict=None # Dictionary of {'class_name' : size, ...} to override default `emb_sz_rule` 
     30 ) -> list: # List of embedding sizes for each category
     31     "Get embedding size for each cat_name in `Tabular` or `TabularPandas`, or populate embedding size manually using sz_dict"
---> 32     return [_one_emb_sz(to.classes, n, sz_dict) for n in to.cat_names]

File ~/.conda/envs/myfastai/lib/python3.9/site-packages/fastai/tabular/model.py:23, in _one_emb_sz(classes, n, sz_dict)
     21 sz_dict = ifnone(sz_dict, {})
     22 n_cat = len(classes[n])
---> 23 sz = sz_dict.get(n, int(emb_sz_rule(n_cat)))  # rule of thumb
     24 return n_cat,sz

AttributeError: 'list' object has no attribute 'get'

Additional context
Add any other context about the problem here.

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

No branches or pull requests

1 participant