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

Standing PR for TensorFlow learning refactor #518

Merged
merged 27 commits into from Jan 17, 2017
Merged

Standing PR for TensorFlow learning refactor #518

merged 27 commits into from Jan 17, 2017

Conversation

henryre
Copy link
Member

@henryre henryre commented Jan 14, 2017

  • Refactor of learning primitives (NoiseAwareModel)
  • Wrapper for TensorFlow models with automatic saving and loading utilities (TFNoiseAwareModel)
  • Adds LogisticRegression as a supported model (updates tutorial to reflect)
  • Updates to hyperparameter searchers
  • Adds reLSTM as a contributor model for relation extraction

@henryre henryre requested a review from ajratner January 14, 2017 02:09
@ajratner
Copy link
Contributor

Looking good so far... ping me on slack when ready for review!

@henryre
Copy link
Member Author

henryre commented Jan 17, 2017

@ajratner Ok good for a review!
cc: @stephenbach

There are two major improvement opportunities, but they can come after the release:

  • Sparse tensor computations for LogisticRegression
  • Same-session model loading for reLSTM

@ajratner
Copy link
Contributor

ajratner commented Jan 17, 2017 via email

Copy link
Contributor

@ajratner ajratner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks awesome. Minor comments, mostly documentation

DEP_SIMILAR,
GenerativeModel,
GenerativeModelWeights,
NaiveBayes,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stephenbach Should we still be supporting NaiveBayes?


def __init__(self, name):
self.name = name
super(NoiseAwareModel, self).__init__()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the point of this line?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks cool. Probably none though...

def __init__(self, save_file=None, name='reLSTM'):
"""LSTM for relation extraction"""
# Define metadata
self.mx_len = None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we get definitions for these params (esp. mx_len, n_v)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

# Super constructor
super(reLSTM, self).__init__(save_file=save_file, name=name)

def _mark(self, l, h, idx):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either make input vars more verbose or explain in doc string (just being more sensitive here given past documentation issues around this module...)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same with mids below

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

# Get arguments and lemma sequence
args = [
(c[0].get_word_start(), c[0].get_word_end(), 1),
(c[1].get_word_start(), c[1].get_word_end(), 2)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Marker indices should be consistent with doc string above (1,2 vs. 0,1)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤓

(c[1].get_word_start(), c[1].get_word_end(), 2)
]
s = self._mark_sentence(
[w.lower() for w in c.get_parent().lemmas], args
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Easy addition to make the sentence token type configurable here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

tx = np.zeros((self.mx_len, batch_size), dtype=np.int32)
tlen = np.zeros(batch_size, dtype=np.int32)
# Pad or trim each x
# TODO: fix for arguments outside max length
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either fix or explain what's going on here / what is currently implemented pre-fix

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will add doc

x.name: x for x in tf.get_collection(
tf.GraphKeys.GLOBAL_VARIABLES, scope=scope.name)
}
# Take mean across sentences
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it standard to take mean across sentences here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, simplest sentence embedding technique. Can improve down the road, but easy enough for now.

@@ -42,200 +37,85 @@ def score(self, session, X_test, test_labels, gold_candidate_set=None, b=0.5, se
return s.score(test_marginals, train_marginals, b=b,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we ever set self.X_train any more (see lines before, and again comes up below)? If not we should get rid of this, and get the training marginals in a different way, or just not display them here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine just getting rid of this, whatever is fast & cleans this loose thread up

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll get rid of this. Never really display them in practice anyway.

"from snorkel.learning import LogReg\n",
"disc_model = LogReg()"
"from snorkel.learning import LogisticRegression\n",
"disc_model = LogisticRegression()"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a comment in the tutorial just mentioning the reLSTM?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add it to another tutorial. LSTM will likely perform much worse on the intro tutorial than LR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok if that's the case makes sense

@henryre
Copy link
Member Author

henryre commented Jan 17, 2017

@ajratner Changes made, testing out now

@coveralls
Copy link

Coverage Status

Coverage increased (+5.8%) to 51.943% when pulling 22cfd8f on lstm into c573fd8 on dev.

@coveralls
Copy link

Coverage Status

Coverage increased (+5.8%) to 51.92% when pulling c28502f on lstm into cb256ca on dev.

@henryre
Copy link
Member Author

henryre commented Jan 17, 2017

No even one invited you, Coveralls #yolo

@henryre henryre merged commit 465a3f3 into dev Jan 17, 2017
@henryre henryre deleted the lstm branch January 17, 2017 20:03
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.

None yet

3 participants