def generate(mod, run, language, textgrid, overwrite=False): name = os.path.basename(os.path.splitext(run)[0]) run_name = name.split('_')[-1] # extract the name of the run save_all = None # Defining paths model_name = 'glove_model' check_folder( os.path.join(Paths().path2derivatives, 'fMRI/raw-features', language, model_name)) path = os.path.join( Paths().path2derivatives, 'fMRI/raw-features', language, model_name, 'raw-features_{}_{}_{}.csv'.format(language, model_name, run_name)) #### generating raw-features #### if (os.path.exists(path)) & (not overwrite): raw_features = pd.read_csv(path) else: raw_features = mod.generate(run, language, textgrid) save_all = path #### Retrieving data of interest #### # columns2retrieve = [function.__name__ for function in mod.functions] columns2retrieve = [ 'embedding-{}'.format(index) for index in range(mod.param['embedding-size']) ] return raw_features[:textgrid.offsets.count()], columns2retrieve, save_all
def generate(mod, run, language, textgrid, overwrite=False): from .WORDRATE import model from .WORDRATE.utils import wordrate, function_words, content_words name = os.path.basename(os.path.splitext(run)[0]) run_name = name.split('_')[-1] # extract the name of the run save_all = None mod = model.Wordrate([content_words, function_words, wordrate], language) # all functions model_name = 'wordrate_model' check_folder( os.path.join(Paths().path2derivatives, 'fMRI/raw-features', language, model_name)) path = os.path.join( Paths().path2derivatives, 'fMRI/raw-features', language, model_name, 'raw-features_{}_{}_{}.csv'.format(language, model_name, run_name)) #### parameters studied #### parameters = sorted([wordrate]) #### generating raw-features #### if (os.path.exists(path)) & (not overwrite): raw_features = pd.read_csv(path) else: raw_features = mod.generate(run, language, textgrid) save_all = path #### Retrieving data of interest #### columns2retrieve = [ function.__name__ for function in model.Wordrate(parameters, language).functions ] return raw_features[:textgrid.offsets.count()], columns2retrieve, save_all
def generate(mod, run, language, textgrid, overwrite=False): name = os.path.basename(os.path.splitext(run)[0]) run_name = name.split('_')[-1] # extract the name of the run save_all = None mod = model.EnergySpectrum([rms], language) # all functions for now model_name = 'rms_model' check_folder( os.path.join(Paths().path2derivatives, 'fMRI/raw-features', language, model_name)) path = os.path.join( Paths().path2derivatives, 'fMRI/raw-features', language, model_name, 'raw-features_{}_{}_{}.csv'.format(language, model_name, run_name)) #### parameters studied #### parameters = sorted([rms]) #### generating raw-features #### if (os.path.exists(path)) & (not overwrite): raw_features = pd.read_csv(path) else: raw_features = mod.generate(run, language, textgrid, slice_period=10e-3) save_all = path #### Retrieving data of interest #### columns2retrieve = [ function.__name__ for function in model.EnergySpectrum(parameters, language).functions ] return raw_features[:textgrid.offsets.count()], columns2retrieve, save_all
def generate(mod, run, language, textgrid, overwrite=False): name = os.path.basename(os.path.splitext(run)[0]) run_name = name.split('_')[-1] # extract the name of the run save_all = None model_name = 'bottomup_model' check_folder(os.path.join(Paths().path2derivatives, 'fMRI/raw-features', language, model_name)) path = os.path.join(Paths().path2derivatives, 'fMRI/raw-features', language, model_name, 'raw-features_{}_{}_{}.csv'.format(language, model_name, run_name)) #### generating raw-features #### if (os.path.exists(path)) & (not overwrite): raw_features = pd.read_csv(path) else: raw_features = mod.generate(run, language, textgrid) save_all = path #### Retrieving data of interest #### columns2retrieve = ['bottomup'] textgrid = pd.read_csv(os.path.join(paths.path2data, 'text', language, 'BOTTOMUP', 'onsets-offsets', '{}_{}_{}_onsets-offsets_{}'.format('text', language, 'BOTTOMUP', run_name)+'.csv')) # df with onsets-offsets-word return raw_features[:textgrid.offsets.count()], columns2retrieve, save_all
def generate(mod, run, language, textgrid, overwrite=False): name = os.path.basename(os.path.splitext(run)[0]) run_name = name.split('_')[-1] # extract the name of the run save_all = None model_name = 'mfcc_model' check_folder(os.path.join(Paths().path2derivatives, 'fMRI/raw-features', language, model_name)) path = os.path.join(Paths().path2derivatives, 'fMRI/raw-features', language, model_name, 'raw-features_{}_{}_{}.csv'.format(language, model_name, run_name)) #### generating raw-features #### if (os.path.exists(path)) & (not overwrite): raw_features = pd.read_csv(path) else: raw_features = mod.generate(run, language) save_all = path #### Retrieving data of interest #### columns2retrieve = ["mfcc #{}".format((i)//3) if i%3==0 else ("mfcc' #{}".format((i)//3) if i%3==1 else "mfcc'' #{}".format((i)//3)) for i in range(mod.num_cepstral*3)] textgrid = pd.read_csv(os.path.join(paths.path2data, 'wave', language, 'MFCC', 'onsets-offsets', '{}_{}_{}_onsets-offsets_{}'.format('wave', language, 'MFCC', run_name)+'.csv')) # df with onsets-offsets-word return raw_features[:textgrid.offsets.count()], columns2retrieve, save_all
def generate(mod, run, language, textgrid, overwrite=False): from .OTHER import model from .OTHER.utils import sentence_onset name = os.path.basename(os.path.splitext(run)[0]) run_name = name.split('_')[-1] # extract the name of the run save_all = None mod = model.Other([sentence_onset], language) # all functions model_name = 'other_sentence_onset' check_folder( os.path.join(Paths().path2derivatives, 'fMRI/raw-features', language, model_name)) path = os.path.join( Paths().path2derivatives, 'fMRI/raw-features', language, model_name, 'raw-features_{}_{}_{}.csv'.format(language, model_name, run_name)) #### generating raw-features #### if (os.path.exists(path)) & (not overwrite): raw_features = pd.read_csv(path) else: raw_features = mod.generate(run, language, textgrid) save_all = path #### Retrieving data of interest #### columns2retrieve = [function.__name__ for function in mod.functions] return raw_features[:textgrid.offsets.count()], columns2retrieve, save_all
################################################################ import sys import os root = os.path.dirname( os.path.dirname(os.path.dirname(os.path.dirname( os.path.abspath(__file__))))) if root not in sys.path: sys.path.append(root) import pandas as pd import numpy as np from utilities.settings import Params, Paths params = Params() paths = Paths() class Bottomup(object): """Container module with an encoder, a recurrent module, and a decoder.""" def __init__(self, language): super(Bottomup, self).__init__() self.language = language def __name__(self): return 'bottomup' def generate(self, path, language, textgrid): # create specific onsets-offsets source = 'text' model_category = 'BOTTOMUP'