def generate_best_dataset(best_path, output_path='<STR_LIT>', create_val=False):
if not os.path.isdir(output_path):<EOL><INDENT>os.mkdir(output_path)<EOL><DEDENT>if not os.path.isdir(os.path.join(output_path, '<STR_LIT:train>')):<EOL><INDENT>os.makedirs(os.path.join(output_path, '<STR_LIT:train>'))<EOL><DEDENT>if not os.path.isdir(os.path.join(output_path, '<STR_LIT:test>')):<EOL><INDENT>os.makedirs(os.path.join(output_path, '<STR_LIT:test>'))<EOL><DEDENT>if not os.path.isdir(os.path.join(output_path, '<STR_LIT>')) and create_val:<EOL><INDENT>os.makedirs(os.path.join(output_path, '<STR_LIT>'))<EOL><DEDENT>for article_type in article_types:<EOL><INDENT>files = glob(os.path.join(best_path, article_type, '<STR_LIT>'))<EOL>files_train, files_test = train_test_split(files, random_state=<NUM_LIT:0>, test_size=<NUM_LIT:0.1>)<EOL>if create_val:<EOL><INDENT>files_train, files_val = train_test_split(files_train, random_state=<NUM_LIT:0>, test_size=<NUM_LIT:0.1>)<EOL>val_words = generate_words(files_val)<EOL>val_df = create_char_dataframe(val_words)<EOL>val_df.to_csv(os.path.join(output_path, '<STR_LIT>', '<STR_LIT>'.format(article_type)), index=False)<EOL><DEDENT>train_words = generate_words(files_train)<EOL>test_words = generate_words(files_test)<EOL>train_df = create_char_dataframe(train_words)<EOL>test_df = create_char_dataframe(test_words)<EOL>train_df.to_csv(os.path.join(output_path, '<STR_LIT:train>', '<STR_LIT>'.format(article_type)), index=False)<EOL>test_df.to_csv(os.path.join(output_path, '<STR_LIT:test>', '<STR_LIT>'.format(article_type)), index=False)<EOL>print("<STR_LIT>".format(article_type))<EOL><DEDENT>
Generate CSV file for training and testing data

Input
=====
best_path: str, path to BEST folder which contains unzipped subfolder
    'article', 'encyclopedia', 'news', 'novel'

cleaned_data: str, path to output folder, the cleaned data will be saved
    in the given folder name where training set will be stored in `train` folder
    and testing set will be stored on `test` folder

create_val: boolean, True or False, if True, divide training set into training set and
    validation set in `val` folder