<filename>get_antonym.py
# @ title show antonym

import pandas as pd
import csv
from itertools import combinations
import random
import sys

in_csv = '/content/drive/MyDrive/Data/predict/test_results.tsv'
file1 = open(in_csv, 'r')
Lines_predict = file1.readlines()
number_lines = sum(1 for row in (open(in_csv)))
with open('/content/bert/datasets/chinese_dictionary-master/log_antonym.txt', 'w') as f:
    original_stdout = sys.stdout
    sys.stdout = f
    in_csv = '/content/bert/datasets/chinese_dictionary-master/wordpairs.csv'
    file1 = open(in_csv, 'r')
    Lines_test = file1.readlines()
    num = 0
    for i in range(number_lines):
        cur_test = Lines_test[i+1].replace('\n', '')
        cur_pre = Lines_predict[i]
        cur_pre = cur_pre.replace('\n', '').split("\t")
        try:
            max_prob = max([float(ele) for ele in cur_pre])
            predict = cur_pre.index(str(max_prob))
            if predict == 0:
                antonym = cur_test.split("\t")
                print(antonym[3:])
                num = num+1
        except ValueError:
            print(i, cur_test, Lines_predict[i])
            break
    sys.stdout=original_stdout

print(num)

<filename>get_antonym.py
# @ title show antonym

import pandas as pd
import csv
from itertools import combinations
import random
import sys

in_csv = '/content/drive/MyDrive/Data/predict/test_results.tsv'
file1 = open(in_csv, 'r')
Lines_predict = file1.readlines()
number_lines = sum(1 for row in (open(in_csv)))
with open('/content/bert/datasets/chinese_dictionary-master/log_antonym.txt', 'w') as f:
    original_stdout = sys.stdout
    sys.stdout = f
    in_csv = '/content/bert/datasets/chinese_dictionary-master/wordpairs.csv'
    file1 = open(in_csv, 'r')
    Lines_test = file1.readlines()
    num = 0
    for i in range(number_lines):
        cur_test = Lines_test[i+1].replace('\n', '')
        cur_pre = Lines_predict[i]
        cur_pre = cur_pre.replace('\n', '').split("\t")
        try:
            max_prob = max([float(ele) for ele in cur_pre])
            predict = cur_pre.index(str(max_prob))
            if predict == 0:
                antonym = cur_test.split("\t")
                print(antonym[3:])
                num = num+1
        except ValueError:
            print(i, cur_test, Lines_predict[i])
            break
    sys.stdout=original_stdout

print(num)

# @ title show antonym