Spaces:
Sleeping
Sleeping
File size: 3,353 Bytes
246df79 |
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 60 61 62 63 64 65 |
"""
Example of training a model using this package.
"""
from Pinpoint.FeatureExtraction import *
from Pinpoint.RandomForest import *
# Performs feature extraction from the provided Extremist, Counterpoise, and Baseline datasets.
extractor = feature_extraction(violent_words_dataset_location=r"datasets/swears",
baseline_training_dataset_location=r"datasets/far-right/LIWC2015 Results (Storm_Front_Posts).csv")
extractor.MAX_RECORD_SIZE = 50000
extractor.dump_training_data_features(
feature_file_path_to_save_to=r"outputs/training_features.json",
extremist_data_location=r"datasets/far-right/LIWC2015 Results (extreamist-messages.csv).csv",
baseline_data_location=r"datasets/far-right/LIWC2015 Results (non-extreamist-messages.csv).csv")
# Trains a model off the features file created in the previous stage
model = random_forest()
model.RADICAL_LANGUAGE_ENABLED = True
model.BEHAVIOURAL_FEATURES_ENABLED = True
model.PSYCHOLOGICAL_SIGNALS_ENABLED = True
model.train_model(features_file= r"outputs/training_features.json",
force_new_dataset=True, model_location=r"outputs/far-right-radical-language.model") # , model_location=r"Pinpoint/model/my.model"
model.create_model_info_output_file(location_of_output_file="outputs/far-right-radical-language-output.txt",
training_data_csv_location=r"outputs/training_features.json.csv")
#############################################################################################
model.RADICAL_LANGUAGE_ENABLED = False
model.BEHAVIOURAL_FEATURES_ENABLED = True
model.PSYCHOLOGICAL_SIGNALS_ENABLED = False
model.train_model(features_file= r"outputs/training_features.json",
force_new_dataset=True, model_location=r"outputs/far-right-behavioural.model") # , model_location=r"Pinpoint/model/my.model"
model.create_model_info_output_file(location_of_output_file="outputs/far-right-behavioural-output.txt",
training_data_csv_location=r"outputs/training_features.json.csv")
############################################################################
model.RADICAL_LANGUAGE_ENABLED = False
model.BEHAVIOURAL_FEATURES_ENABLED = False
model.PSYCHOLOGICAL_SIGNALS_ENABLED = True
model.train_model(features_file= r"outputs/training_features.json",
force_new_dataset=True, model_location=r"outputs/far-right-psychological.model") # , model_location=r"Pinpoint/model/my.model"
model.create_model_info_output_file(location_of_output_file="outputs/far-right-psychological-output.txt",
training_data_csv_location=r"outputs/training_features.json.csv")
##############################################################################################
model.RADICAL_LANGUAGE_ENABLED = True
model.BEHAVIOURAL_FEATURES_ENABLED = False
model.PSYCHOLOGICAL_SIGNALS_ENABLED = False
model.train_model(features_file= r"outputs/training_features.json",
force_new_dataset=True, model_location=r"outputs/far-right-baseline.model") # , model_location=r"Pinpoint/model/my.model"
model.create_model_info_output_file(location_of_output_file="outputs/far-right-baseline-output.txt",
training_data_csv_location=r"outputs/training_features.json.csv")
print("Finished") |