XiangPan's picture
[Xiang Pan] upload
9c8ab32
raw
history blame
1.56 kB
fi = open("multinli_1.0_train.txt", "r")
output_file = open("multinli_sub.txt", "w")
output_index_list = []
count_entailment = 0
count_neutral = 0
count_contradiction = 0
for line_index, line in enumerate(fi):
parts = line.strip().split("\t")
premise = parts[5]
hypothesis = parts[6]
label = parts[0]
prem_words = []
hyp_words = []
for word in premise.split():
if word not in [".", "?", "!"]:
prem_words.append(word.lower())
for word in hypothesis.split():
if word not in [".", "?", "!"]:
hyp_words.append(word.lower())
prem_filtered = " ".join(prem_words)
hyp_filtered = " ".join(hyp_words)
if hyp_filtered in prem_filtered:
#print(premise, hypothesis, label, parts[1])
#print(label)
if label == "entailment":
count_entailment += 1
if label == "neutral":
count_neutral += 1
print(premise, hypothesis, label)
if label == "contradiction":
count_contradiction += 1
print(premise, hypothesis, label)
output_index_list.append(line_index)
# output_file.write(line)
#print(premise, hypothesis, label)
# open json file
with open('multinli_1.0_train.jsonl', 'r') as f:
for line_index, line in enumerate(f):
if line_index in output_index_list:
output_file.write(line)
# load json file
# data = json.load(f)
print("Entailment:", count_entailment)
print("Contradiction:", count_contradiction)
print("Neutral:", count_neutral)