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

Update GridSearch and add to tutorial #439

Merged
merged 12 commits into from
Sep 27, 2016
Merged

Update GridSearch and add to tutorial #439

merged 12 commits into from
Sep 27, 2016

Conversation

henryre
Copy link
Member

@henryre henryre commented Sep 24, 2016

Berg gets back on the board

Fixes #436

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.

Nice! Two overall comments (besides inline):

  1. Need documentation of the optional params in the doc string so we know what they are :)
  2. Let's just make this the default in the tutorial?

@@ -97,7 +97,7 @@ def predict(self, X, b=0.5):
"""Return numpy array of elements in {-1,0,1} based on predicted marginal probabilities."""
return np.array([1 if p > b else -1 if p < b else 0 for p in self.marginals(X)])

def score(self, X_test, L_test, gold_candidate_set, b=0.5, set_unlabeled_as_neg=True):
def score(self, X_test, L_test, gold_candidate_set, b=0.5, set_unlabeled_as_neg=True, disp=True):
Copy link
Contributor

Choose a reason for hiding this comment

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

display for readability?

def search_space(self):
return product(*self.param_val_ranges)

def fit(self, X_test, L_test, gold_candidate_set, b=0.5, set_unlabeled_as_neg=True, **model_hyperparams):
Copy link
Contributor

@ajratner ajratner Sep 24, 2016

Choose a reason for hiding this comment

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

Some minor things:

  • I would call e.g. X_validation to make it clear that they shouldn't use the test set here?
  • L_test is a vector of labels, so should be e.g. validation_labels (upper case single letter reserved for matrices)

p, r, f1 = scores[:3]
tp, fp, tn, fn = self.model.score(X_test, L_test, gold_candidate_set, b, set_unlabeled_as_neg, disp=False)
p, r = float(len(tp)) / (len(tp) + len(fp)), float(len(tp)) / (len(tp) + len(fn))
f1 = 2.0 * (p * r) / (p + r) if (p + r) > 0 else 0
Copy link
Contributor

Choose a reason for hiding this comment

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

We should put these as standard utility fns




class RandomSearch(GridSearch):
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor: I was thinking RandomSearch would be over a continuous space of param values, rather than filtering a set of given discreet values as here; I think that would be more convenient because then the user only needs to specify a range rather than a set of values?

Copy link
Member Author

Choose a reason for hiding this comment

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

Shhhhhhhhh values

Copy link
Contributor

Choose a reason for hiding this comment

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

Well played

@henryre
Copy link
Member Author

henryre commented Sep 25, 2016

Ok @ajratner changes made

@ajratner
Copy link
Contributor

@henryre looks good, added a bit of text in tutorial. Two questions remaining:

  • What's default if they don't have any dev labels? What were you doing before (we can discuss this in person)
  • Did you check to make sure adding this in preserves or improves the tutorial score (if not, we need to debug)?

@henryre
Copy link
Member Author

henryre commented Sep 26, 2016

@ajratner

  • Let's add the no labels option later. Needs a discussion about best practices. Previous solution was: pick a random hold out set, then train the models and select the w s.t. sqrt(np.mean((p - 0.5)^2)) is maximized where p were the predicted marginals for the hold out set (i.e. measures how spread out the marginals are)
  • 90% certain it does improve performance (from memory), but will double check shortly

Update: 0.4 F1 from non-grid-search tutorial, 0.667 for grid-search tutorial

@henryre
Copy link
Member Author

henryre commented Sep 26, 2016

lol progressbar broke the build

@stephenbach
Copy link
Contributor

Might be helpful. Same issue: keras-team/keras#2110

@ajratner
Copy link
Contributor

So let's just put in how to proceed without grid search (if you don't have dev set labeled)- this will preempt a lot of questions!

@henryre
Copy link
Member Author

henryre commented Sep 27, 2016

Dev set F1: 0.4 -> 0.57
Test set F1: 0.7 -> 0.63

@ajratner
Copy link
Contributor

LGTM- will merge in after Travis passes; we should merge into dev and master

@ajratner ajratner merged commit 3b8154b into dev Sep 27, 2016
@ajratner ajratner deleted the grid-search branch September 27, 2016 07:29
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