Skip to content

Commit

Permalink
Merge pull request #10 from Qukaiyi/add-type-check-for-ClassifierFeat…
Browse files Browse the repository at this point in the history
…ure-1

Update __init__ method of meta.py
  • Loading branch information
andychisholm committed Mar 7, 2018
2 parents 89eb83e + 6ca432c commit 5ce1f0b
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions nel/features/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@

class ClassifierFeature(Feature):
""" Computes a feature score based on the output of a classifier over a set of features. """
def __init__(self, classifier):
self.classifier = classifier
def __init__(self, classifier=None, classifier_model_tag=None):
if (classifier_model_tag is None) == (classifier is None):
raise Exception('You must provide a classifier_model_tag or classifier instance, but not both.')
self.classifier = classifier or Classifier.load(classifier_model_tag)


def compute_doc_state(self, doc):
doc = self.classifier.mapper(doc)
Expand Down Expand Up @@ -41,3 +44,4 @@ def id(self):

def predict(self, fv):
return self.classifier.model.predict_proba(fv)[0][1]

0 comments on commit 5ce1f0b

Please sign in to comment.