示例#1
0
def test_classify():

    model = load_model()

    r1 = classify("I want the UK to stay EU #remain #remain #remain", model)
    assert round(float(r1["pro_brexit"]), 4) == 0.4284

    r2 = classify("I want the UK to leave EU #BrexitNow", model)
    assert round(float(r2["pro_brexit"]), 4) == 0.8875
示例#2
0
 def __init__(self):
     """model: keras model with weights loaded, ready to make predictions"""
     self.wait = 0
     self.auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
     self.auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
     self.api = tweepy.API(self.auth)
     self.lastTweeted = ""
     self.lastTweetedCount = 0
     self.model = load_model()
示例#3
0
def test_load_model():
    assert isinstance(load_model(), Model)
示例#4
0
def classify(txt, model):
	"""
	Params:
		txt is the text to classify
		model is the model used to perform the classification
	"""
	x, x_s = main_clean(txt)
	results = model.predict([x, x_s]) #> array([[0.57155126, 0.42844874]], dtype=float32)
	results = results[0] #> array([0.57155126, 0.42844874], dtype=float32)
	response = {"text": txt, "pro_brexit": results[1]}
	return response

if __name__ == "__main__":

	model = load_model()

	if APP_ENV=="production":
		example_texts = [
			"I want the UK to stay EU #remain #remain #remain",
			"I want the UK to leave EU #BrexitNow",
		]
		for user_text in example_texts:
			results = classify(user_text, model)
			print(results)
	else:
		while True:
			user_text = input("Your Text (press ENTER at any time to quit): ")
			if user_text in ["", "exit", "exit()"]: break
			results = classify(user_text, model)
			print(results)