model_es = word_vectors.load_model('resources/big/vectors_es_100.bin') model_pt = word_vectors.load_model('resources/big/vectors_pt_100.bin') logging.info("computing equal words...") equal_words = model_es.vocab.keys() & model_pt.vocab.keys() print("Equal words number in the Wikipedia's:", len(equal_words)) SAMPLE_SIZE = 20 print("Sample", SAMPLE_SIZE, "equal words found:", random.sample(equal_words, SAMPLE_SIZE)) T = linear_trans.load_linear_transformation( 'resources/big/trans_es_100_pt_100.npz') clf = classifier.build_classifier() X_train, y_train = classifier.features_and_labels(training_friend_pairs, model_es, model_pt, T) logging.info("training...") clf.fit(X_train, y_train) equal_friend_pairs = (classifier.FriendPair(word, word, None) for word in equal_words) logging.info("computing features...") X_equal, _ = classifier.features_and_labels(equal_friend_pairs, model_es, model_pt, T) logging.info("predicting equal words...")
def command_classify(args_): training_friend_pairs = util.read_words( args_.training_friends_file_name) testing_friend_pairs = util.read_words(args_.testing_friends_file_name) model_es, model_pt = util.read_models(args_) T = linear_trans.load_linear_transformation( args_.translation_matrix_file_name) clf = classifier.build_classifier(CLF_OPTIONS[args_.classifier]) if args_.cross_validation: friend_pairs = training_friend_pairs + testing_friend_pairs X, y, = classifier.features_and_labels( friend_pairs, model_es, model_pt, T, backwards=args_.backwards, topx=args_.top, use_taxonomy=args_.use_taxonomy) measures = classifier.classify_with_cross_validation(X, y, clf=clf) print('') print("Cross-validation measures with 95% of confidence:") for measure_name, (mean, delta) in measures.items(): print( "{measure_name}: {mean:0.4f} ± {delta:0.4f} --- [{inf:0.4f}, {sup:0.4f}]" .format(measure_name=measure_name, mean=mean, delta=delta, inf=mean - delta, sup=mean + delta)) print('') mean_measures = { measure_name: mean for measure_name, (mean, delta) in measures.items() } _print_metrics_matrix(mean_measures) _print_confusion_matrix(mean_measures) else: X_train, y_train = classifier.features_and_labels( training_friend_pairs, model_es, model_pt, T, backwards=args_.backwards, topx=args_.top, use_taxonomy=args_.use_taxonomy) X_test, y_test = classifier.features_and_labels( testing_friend_pairs, model_es, model_pt, T, backwards=args_.backwards, topx=args_.top, use_taxonomy=args_.use_taxonomy) measures = classifier.classify(X_train, X_test, y_train, y_test, clf) print('') _print_metrics_matrix(measures) _print_confusion_matrix(measures)