snorkel-team / snorkel

A system for quickly generating training data with weak supervision
https://snorkel.org
Apache License 2.0
5.81k stars 857 forks source link

AttributeError: 'Graph' object has no attribute 'node' #1494

Closed amitoengg closed 5 years ago

amitoengg commented 5 years ago

I am getting Graph' object has no attribute 'node' error when i call LabelModel.fit on a simple example. Not sure whats wrong. (adding cardinality param doesnt help)

Installation

Ubuntu subsystem on Windows 10 (same error in standalone Ubuntu) Python 3.6.7 Same error message on 0.9.0 and 0.9.1

pip3 install snorkel==0.9.0

Collecting snorkel==0.9.0 Downloading https://files.pythonhosted.org/packages/42/12/9c5ac9e097574a0657026af7cd127fddbe8f0888dc4fccedb26a8c29e1b6/snorkel-0.9.0-py3-none-any.whl (131kB) 100% |████████████████████████████████| 133kB 666kB/s Requirement already satisfied: pandas<0.25.0,>=0.24.0 in /usr/local/lib/python3.6/dist-packages (from snorkel==0.9.0) Requirement already satisfied: scipy<2.0.0,>=1.2.0 in /usr/local/lib/python3.6/dist-packages (from snorkel==0.9.0) Requirement already satisfied: tensorboardX<2.0,>=1.6 in /usr/local/lib/python3.6/dist-packages (from snorkel==0.9.0) Requirement already satisfied: torch<1.2.0,>=1.1.0 in /usr/local/lib/python3.6/dist-packages (from snorkel==0.9.0) Requirement already satisfied: networkx<3.0,>=2.2 in /usr/local/lib/python3.6/dist-packages (from snorkel==0.9.0) Requirement already satisfied: tqdm<5.0.0,>=4.29.0 in /usr/local/lib/python3.6/dist-packages (from snorkel==0.9.0) Requirement already satisfied: numpy<2.0.0,>=1.16.0 in /usr/local/lib/python3.6/dist-packages (from snorkel==0.9.0) Requirement already satisfied: scikit-learn<0.22.0,>=0.20.2 in /usr/local/lib/python3.6/dist-packages (from snorkel==0.9.0) Requirement already satisfied: python-dateutil>=2.5.0 in /usr/lib/python3/dist-packages (from pandas<0.25.0,>=0.24.0->snorkel==0.9.0) Requirement already satisfied: pytz>=2011k in /usr/local/lib/python3.6/dist-packages (from pandas<0.25.0,>=0.24.0->snorkel==0.9.0) Requirement already satisfied: protobuf>=3.8.0 in /usr/local/lib/python3.6/dist-packages (from tensorboardX<2.0,>=1.6->snorkel==0.9.0) Requirement already satisfied: six in /usr/lib/python3/dist-packages (from tensorboardX<2.0,>=1.6->snorkel==0.9.0) Requirement already satisfied: decorator>=4.3.0 in /usr/local/lib/python3.6/dist-packages (from networkx<3.0,>=2.2->snorkel==0.9.0) Requirement already satisfied: joblib>=0.11 in /usr/local/lib/python3.6/dist-packages (from scikit-learn<0.22.0,>=0.20.2->snorkel==0.9.0) Requirement already satisfied: setuptools in /usr/lib/python3/dist-packages (from protobuf>=3.8.0->tensorboardX<2.0,>=1.6->snorkel==0.9.0) Installing collected packages: snorkel Successfully installed snorkel-0.9.0

Code

import numpy as np
from snorkel.labeling import LabelModel
L = np.array([[0, 0, -1], [-1, 0, 1], [1, -1, 0]])
Y_dev = [0, 1, 0]
label_model = LabelModel(verbose=False)
label_model.fit(L)

Traceback (most recent call last): File "/usr/local/lib/python3.6/dist-packages/snorkel/labeling/model/label_model.py", line 743, in fit self._create_tree() File "/usr/local/lib/python3.6/dist-packages/snorkel/labeling/model/label_model.py", line 554, in _create_tree self.c_tree = get_clique_tree(nodes, []) File "/usr/local/lib/python3.6/dist-packages/snorkel/labeling/model/graph_utils.py", line 49, in get_clique_tree S = G2.node[i]["members"].intersection(G2.node[j]["members"]) AttributeError: 'Graph' object has no attribute 'node'

dataframing commented 5 years ago

Hi @amitoengg, this is due to a recent issue I noted on #1491: networkx made a backwards-incompatible change to their Graph attributes, combined with snorkel assuming that they wouldn't make backwards-incompatible changes until 3.0. The patch has been merged to master, but in the meantime you can make sure to also specify networkx==2.3.0 in order for the LabelModel to run just fine.

Let me know if this works!

eggie5 commented 5 years ago

I'm getting this too starting 2 days ago when my job started failing...

bhancock8 commented 5 years ago

@eggie5 are you running from Snorkel from source (in which case, if you pulled from master since #1492 was merged, I'd be surprised and there's more we need to look into) or from pip? If it's from pip, that's because we haven't pushed up the patch yet to PyPI. It should be up soon!

eggie5 commented 5 years ago

I'm commenting about the pip release per my comments here https://github.com/snorkel-team/snorkel/commit/4d579fa9ea96c6e09b0a8f10b2f9a92330e41d9e#commitcomment-35546869 . Any estimate on the new pip release?

henryre commented 5 years ago

We released Snorkel v0.9.3 last night, which contains this patch. Closing for now, feel free to reopen if this still isn't working.

Raj9417 commented 5 years ago

Hi @amitoengg, this is due to a recent issue I noted on #1491: networkx made a backwards-incompatible change to their Graph attributes, combined with snorkel assuming that they wouldn't make backwards-incompatible changes until 3.0. The patch has been merged to master, but in the meantime you can make sure to also specify networkx==2.3.0 in order for the LabelModel to run just fine.

Let me know if this works!

This Solve the problem for me Thanks.

hmubarak commented 4 years ago

hi, i am suing snorkel 0.9.5 (pip install snorkel) and networkx 2.3 but still have the same problem: AttributeError: 'Graph' object has no attribute 'node'

I am trying 01_spam_tutorial.ipynb which is part of Snorkel tutorial on GitHub without any modification: label_model = LabelModel(cardinality=2, verbose=True) label_model.fit(L_train=L_train, n_epochs=500, log_freq=100, seed=123) <===== Error!

any solution please? thanks

bhancock8 commented 4 years ago

@hmubarak could you check in the virtual environment where you're running the tutorial and confirm what version of networkx is present? (e.g., run pip freeze | grep networkx and see a result like networkx==2.4)

JanSawicki commented 3 years ago

I am facing the same issue. Modules versions are:

networkx==2.3 snorkel==0.9.7

I am using the code from the tutorial.

arlu0001 commented 3 years ago

Having the same issue. I need networkx==2.5 because of this #1667 issue, but then I get the AttributError where I need networkx==2.3?

snorkel==0.9.7 Python 3.9.1