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

3.3 KiB

import random
with open('dev-0/in.tsv', 'r') as f:
    dev_x = f.readlines()
m_vocabulary = ['windows', 'pc', 'lagi', 'komputer', 'komputerze', 'aucie', 'auto', 'samochód', 'samochodzie', 'piwie', 'piwo', 'alkoholu', 'alkohol', 'żonie', 'żona', 'xboxie', 'xbox', 'mecz', 'meczu', 'XD', 'stary', 'staremu']
f_vocabulary = ['ciasto', 'porodzie', 'ciąży', 'ciąża', 'tabletki', '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.5128610338348603