|
|
|
|
|
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: |
|
|
|
|
|
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) |
|
|
|
|
|
|
|
|
|
|
|
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) |
|
|
|
|
|
|
|
print("Entailment:", count_entailment) |
|
print("Contradiction:", count_contradiction) |
|
print("Neutral:", count_neutral) |
|
|