-
Notifications
You must be signed in to change notification settings - Fork 0
/
Preprocess.py
60 lines (44 loc) · 1.43 KB
/
Preprocess.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import os
import random
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt # %matplotlib inline
import seaborn as sns
from argparse import ArgumentParser
import re
from glob import glob
from tqdm import tqdm
from itertools import combinations
from Utils.Preprocessing_utils import *
import torch
import torch.nn as nn
from torch.nn import functional as F
from torch.utils.data import Dataset, DataLoader
import pytorch_lightning as pl
import transformers
from transformers import AutoTokenizer, AutoModel
transformers.logging.set_verbosity_error()
from rank_bm25 import BM25Okapi, BM25L, BM25Plus
# from sentence_transformers import SentenceTransformer
import warnings
warnings.filterwarnings('ignore')
def code_cpp_preprocessing():
''' Args Set '''
args = set_pp_args()
''' Seed Set '''
set_seeds(args.seed)
''' Make Preprocessed Data Directory '''
pp_mkdir(args)
''' CUDA'''
device = torch.device('cuda') if torch.cuda.is_available() else torch.device('cpu')
''' Tokenizer '''
tokenizer = AutoTokenizer.from_pretrained(args.text_pretrained_model)
tokenizer.truncation_side = args.truncation_side
''' Train Data Preprocessing and Generation '''
train_df = create_df(args)
train_df_bm25 = get_pairs(train_df, tokenizer, args)
f_split(train_df_bm25, args)
'''Test Code preprocessing '''
test_code_df(args)
if __name__ == "__main__":
code_cpp_preprocessing()