def predict(url):
	concept = ClarifaiCustomModel()
	max_confidence = 0.0
	classification = None
	for word in language.keys():
		#print word
		result = concept.predict(url, word)
		confidence = result['urls'][0]['score']
		print word, confidence
		if confidence > max_confidence:
			max_confidence = confidence
			classification = word
	if classification == None:
		return None
	else:
		return (classification, max_confidence)
Esempio n. 2
0
from clarifai_basic import ClarifaiCustomModel
from json import dumps
from classifications import language

concept = ClarifaiCustomModel()

for model in language.keys():
	print "current model to train: " + model
	for url in language[model]:
		concept.positive(url, model)
		#print "training url:%s on model %s" % (url, model)
	for key, value in language.iteritems():
		if key != model:
			for neg_url in value:
				print neg_url
				concept.negative(neg_url, model)
	concept.train(model)

#print "making url:%s from model: %s a negative case." %(neg_url, key)


'''
for url in language['letter_c']:
	concept.positive(url, "letter_c")

for neg_url in language['letter_a']:
	concept.negative(neg_url, "letter_c")
	
for neg_url in language['letter_b']:
	concept.negative(neg_url, "letter_c")
for neg_url in language['applause']: