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

Depreciated function from networkx used in snorkel/labeling/model/graph_utils.py #1530

Closed martingui8 closed 4 years ago

martingui8 commented 4 years ago

Problem description

snorkel/labeling/model/graph_utils.py is using a depreciated function of package networkx: .node() which has been replaced in latest versions of networkx by .nodes().

Trying to use label_model.fit(L) thus raises the following error if networkx has been updated when installing an other package.


AttributeError Traceback (most recent call last)

in ----> 1 label_model.fit(L) ~/miniconda3/envs/snorkel/lib/python3.7/site-packages/snorkel/labeling/model/label_model.py in fit(self, L_train, Y_dev, class_balance, **kwargs) 741 self._set_class_balance(class_balance, Y_dev) 742 self._set_constants(L_shift) --> 743 self._create_tree() 744 lf_analysis = LFAnalysis(L_train) 745 self.coverage = lf_analysis.lf_coverages() ~/miniconda3/envs/snorkel/lib/python3.7/site-packages/snorkel/labeling/model/label_model.py in _create_tree(self) 552 def _create_tree(self) -> None: 553 nodes = range(self.m) --> 554 self.c_tree = get_clique_tree(nodes, []) 555 556 def _execute_logging(self, loss: torch.Tensor) -> Metrics: ~/miniconda3/envs/snorkel/lib/python3.7/site-packages/snorkel/labeling/model/graph_utils.py in get_clique_tree(nodes, edges) 47 for i in G2.nodes: 48 for j in G2.nodes: ---> 49 S = G2.node[i]["members"].intersection(G2.node[j]["members"]) 50 w = len(S) 51 if w > 0: AttributeError: 'Graph' object has no attribute 'node' ## Solution Replacing .node() by .nodes(), but I assume that updating to networkx>=2.4 would require other modifications that might make this change more complicated than it seems. For users: downgrading networkx to version 2.3 using: `conda install networkx=2.3` or equivalent if you are using an other environment manager than conda. ## Additional context How you installed Snorkel (conda, pip, source): conda OS: PopOs 18.04 (Ubuntu) Python version: 3.7.6 Snorkel version: 0.9.0
bhancock8 commented 4 years ago

You are correct, the issue is that networkx changed their syntax between minor versions. You may find #1491 and #1494 relevant. Our Python requirements currently upperbound networkx to be <2.4.

martingui8 commented 4 years ago

Thanks for your confirmation @bhancock8. Is it planned to update graph_utils to recover compatibility with networkx' current version or should I close this issue?

bhancock8 commented 4 years ago

I think we'll keep the current requirements for the near future, since it's stable. Though if this becomes a blocker for people in the places where they're using Snorkel, we'd love to hear about it and can bump up the priority for updating the code everywhere to match the latest networkx version.