petite-difference-challenge2/run.ipynb
2022-04-20 21:00:41 +02:00

3.2 KiB

import random
with open('dev-0/in.tsv', 'r') as f:
    dev_x = f.readlines()
m_vocabulary = ['komputer', 'komputerze', 'aucie', 'auto', 'samochód', 'samochodzie', 'piwie', 'piwo', 'alkoholu', 'alkohol', 'żonie', 'żona', 'xboxie', 'xbox', 'co', 'e', 'XD', 'stary', 'staremu']
f_vocabulary = ['zakupy', 'zakupach', 'mężem', 'mąż', 'nasze', 'my', 'dzieckiem', 'dziecko', 'domu', 'dom', 'mieszkaniu', 'mieszkanie', 'kocham', 'kocha', 'chłopakowai', 'chłopak', 'haha', 'boże', 'uh', 'uhh', ":)", 'mama', 'mamie', 'włosy']
def predict(text):
    score = 0

    for word in m_vocabulary:
        if word in text:
            score += 1

    for word in f_vocabulary:
        if word in text:
            score -= 1

    if score == 0:
        return random.randint(0, 1)
    if score >0:
        return 1
    if score <0:
        return 0
with open('dev-0/expected.tsv', 'r') as f:
    dev_y = f.readlines()
dev = zip(dev_x, dev_y)
correct = 0
incorrect = 0

with open('dev-0/out.tsv', 'wt') as f:
    for x, y in list(dev):
        f.write(str(predict(x))+'\n')
        if predict(x) == int(y):
            correct += 1
        else:
            incorrect += 1
    
correct/(correct+incorrect)
0.5122792230182751