<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Language Detection Model
Import classes needed for preprocessing, training and testing.
Step1:  Preprocess the database
Setup the names of the source and destination directories below
Step2:  Begin preprocessing the language data
Step3:  Train the language detection model and save as an object.
Step4:  Test the model trained during the last step.
Set the name of the training file in test_file_name below
<ASSISTANT_TASK:>
Python Code:
import LangByWord as lbw
import BuildTrainingDataFiles as btdf
Explanation: Language Detection Model
Import classes needed for preprocessing, training and testing.
End of explanation
# Set the input directory for preprocessing here:
base_input_dir = '/Users/frank/data/LanguageDetectionModel/txt'
# Set the output directory for the preprocessing here:
base_output_dir = '/Users/frank/data/LanguageDetectionModel/exp_data_test'
Explanation: Preprocess the database
Setup the names of the source and destination directories below:
End of explanation
build_obj = btdf.BuildTrainingDataFiles()
build_obj.start_building(base_input_dir, base_output_dir)
Explanation: Begin preprocessing the language data
End of explanation
lo = lbw.LangByWord()
lo.train(base_output_dir, max_words_per_lang=0, report_freq=0)
lo.print_most_prob_words()
object_file = 'LbyW_obj.pck'
lo.save_object_to_file(object_file)
Explanation: Train the language detection model and save as an object.
End of explanation
test_file_name = '/Users/frank/data/LanguageDetectionModel/europarl.test'
lo2 = lbw.LangByWord.load_object_from_file(object_file)
lo2.test_on_test(test_file_name, report_freq=0)
Explanation: Test the model trained during the last step.
Set the name of the training file in test_file_name below:
End of explanation
<END_TASK>