|
import json |
|
import jsonlines |
|
import argparse |
|
import pandas as pd |
|
import pprint |
|
from random import * |
|
|
|
def main(args): |
|
mainDict = {} |
|
with jsonlines.open(args.norwegian_input_file) as reader: |
|
for obj in reader: |
|
|
|
neutral = "" |
|
entailment = "" |
|
contradiction = "" |
|
prompt = "" |
|
|
|
if mainDict.get(obj['promptID'], None): |
|
prompt = obj['sentence1'] |
|
entailment = mainDict[obj['promptID']].get('entailment','') |
|
contradiction = mainDict[obj['promptID']].get('contradiction','') |
|
neutral = mainDict[obj['promptID']].get('neutral','') |
|
|
|
if obj['gold_label'] == "neutral": |
|
neutral = obj['sentence2'] |
|
elif obj['gold_label'] == "contradiction": |
|
contradiction = obj['sentence2'] |
|
elif obj['gold_label'] == "entailment": |
|
entailment = obj['sentence2'] |
|
|
|
mainDict[obj['promptID']] = {'prompt': prompt, 'entailment' : entailment, 'neutral' : neutral, 'contradiction' : contradiction} |
|
|
|
myList = [] |
|
for promptID in mainDict: |
|
myList.append({'sent0':mainDict[promptID]['prompt'], 'sent1':mainDict[promptID]['entailment'], 'hard_neg':mainDict[promptID]['contradiction']}) |
|
|
|
df = pd.DataFrame.from_records(myList) |
|
|
|
|
|
df.replace("", float("NaN"), inplace=True) |
|
df.dropna(subset = ["sent0","sent1","hard_neg"], inplace=True) |
|
|
|
|
|
english = pd.read_csv(args.english_input_file) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
combined = pd.concat([df, english]) |
|
|
|
combined = combined.sample(frac=1).reset_index(drop=True) |
|
|
|
|
|
combined.to_csv(args.output_file, index=False) |
|
|
|
if __name__ == '__main__': |
|
parser = argparse.ArgumentParser() |
|
parser.add_argument('--norwegian_input_file', help="Norwegian json file.", required=True) |
|
parser.add_argument('--english_input_file', help="English csv file.", required=True) |
|
parser.add_argument('--output_file', help="Output file.", required=True) |
|
|
|
args = parser.parse_args() |
|
main(args) |
|
|