<commit_before>from sys import stderr, stdin, argv
from model import Representation
from nltk.classify.maxent import MaxentFeatureEncodingI
import numpy as np


def main():
    lang_map = {
        0: 'bg',
        1: 'bs',
        2: 'cz',
        3: 'es-AR',
        4: 'es-ES',
        5: 'hr',
        6: 'id',
        7: 'mk',
        8: 'my',
        9: 'pt-BR',
        10: 'pt-PT',
        11: 'sk',
        12: 'sr',
        13: 'xx',
    }
#    lang_map = {
#        0: 'bs',
#        1: 'cz',
#        2: 'hr',
#        3: 'sk',
#        4: 'sr',
#    }
    lang_map = {
        0: 'bs',
        1: 'hr',
        2: 'sr',
    }
    lang_map = {
        0: 'pt-BR',
        1: 'pt-PT',
    }
    mtx = np.loadtxt(stdin, np.float)
    labels = mtx[:, 0]
    train = mtx[:, 1:]
    r = Representation('dummy', 'svm', rbm_hiddenDimension=10, simple_field=3, maxent_encoding=MaxentFeatureEncodingI(), pca_dimension=50, svm_ktype='svc', svm_kernel='linear')
    r.encode(train)
    stderr.write('Encoded\n')
    r.train_classifier(labels)
    stderr.write('Trained\n')
    acc = 0
    N = 0
    with open(argv[1]) as f:
        for l in f:
            fs = l.strip().split()
            lab = int(fs[0])
            vec = np.array(map(float, fs[1:]))
            cl = r.classify_vector(vec)
            try:
                guess = int(cl[0])
            except IndexError:
                guess = int(cl + 0.5)
            N += 1
            if int(guess) == int(lab):
                acc += 1
            print('{0}\t{1}'.format(lang_map[guess], lang_map[int(lab)]))
    print(float(acc) / N)

if __name__ == '__main__':
    main()<commit_msg>remove nltk import<commit_after>from sys import stderr, stdin, argv
from model import Representation
import numpy as np


def main():
    lang_map = {
        0: 'bg',
        1: 'bs',
        2: 'cz',
        3: 'es-AR',
        4: 'es-ES',
        5: 'hr',
        6: 'id',
        7: 'mk',
        8: 'my',
        9: 'pt-BR',
        10: 'pt-PT',
        11: 'sk',
        12: 'sr',
        13: 'xx',
    }
#    lang_map = {
#        0: 'bs',
#        1: 'cz',
#        2: 'hr',
#        3: 'sk',
#        4: 'sr',
#    }
    lang_map = {
        0: 'bs',
        1: 'hr',
        2: 'sr',
    }
    lang_map = {
        0: 'pt-BR',
        1: 'pt-PT',
    }
    mtx = np.loadtxt(stdin, np.float)
    labels = mtx[:, 0]
    train = mtx[:, 1:]
    r = Representation('dummy', 'svm', rbm_hiddenDimension=10, simple_field=3, pca_dimension=50, svm_ktype='svc', svm_kernel='linear')
    r.encode(train)
    stderr.write('Encoded\n')
    r.train_classifier(labels)
    stderr.write('Trained\n')
    acc = 0
    N = 0
    with open(argv[1]) as f:
        for l in f:
            fs = l.strip().split()
            lab = int(fs[0])
            vec = np.array(map(float, fs[1:]))
            cl = r.classify_vector(vec)
            try:
                guess = int(cl[0])
            except IndexError:
                guess = int(cl + 0.5)
            N += 1
            if int(guess) == int(lab):
                acc += 1
            print('{0}\t{1}'.format(lang_map[guess], lang_map[int(lab)]))
    print(float(acc) / N)

if __name__ == '__main__':
    main()
{'fraction_non_alphanumeric': 0.1727471156844403, 'fraction_numerical': 0.029310882444652322, 'mean_word_length': 1.5379746835443038, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3720252', 'n_tokens_mistral': 1231, 'n_tokens_neox': 1198, 'n_words': 272}