April 2017
Beginner to intermediate
358 pages
9h 30m
English
We can now test our improved prediction function using similar code to before. First, we define a prediction function, which also takes our list of valid words:
from operator import itemgetter def improved_prediction(word, net, dictionary, shear=0.2, scale=1.0): captcha = create_captcha(word, shear=shear, scale=scale) prediction = predict_captcha(captcha, net) if prediction not in dictionary: distances = sorted([(word, compute_distance(prediction, word)) for word in dictionary], key=itemgetter(1)) best_word = distances[0] prediction = best_word[0] return word == prediction, word, prediction
We compute the distance between our predicted word and each other word in the dictionary, and sort it by distance (lowest ...
Read now
Unlock full access