def __init__(self, num_layers=12, model_dim=512, num_heads=8, ffn_dim=2048, transformer_layer=12, dropout=0.0): super(transformer, self).__init__() self.CLS = nn.Parameter(torch.FloatTensor(6, model_dim)) self.SEP = nn.Parameter(torch.FloatTensor(1, model_dim)) self.enc = encoder(num_layers, model_dim, num_heads, ffn_dim, dropout) self.linear = nn.Linear(model_dim, 5, bias=False) # self.sigmoid = nn.Sigmoid() ## fit for Multimodal-Transformer self.output_linear = nn.Linear(5, 1, bias=False)
def main(): # load dataset df = pd.read_csv('movies_metadata.csv') df = df.loc[:, ['title', 'genres', 'overview']] df = df[pd.notnull(df.overview)] df = df[pd.notnull(df.title)] df = df[pd.notnull(df.genres)] # Training parameters max_len_desc = 300 max_len_title = 50 max_input_len = max_len_title + max_len_desc genres_to_be_predicted = [ 'Drama', 'Comedy', 'Documentary', 'Science Fiction', 'Romance' ] num_classes = len(genres_to_be_predicted) params = { 'GENRES': genres_to_be_predicted, 'VOCABULARY_SIZE': 20000, 'EMBEDDING_DIM': 100, 'MAX_LEN_DESC': max_len_desc, 'MAX_LEN_TITLE': max_len_title, 'INPUT_LEN': max_input_len, 'NUM_DENSE_1': 512, 'NUM_CLASSES': num_classes, 'NUM_EPOCHS': 4, 'BATCH_DIM': 64 } # init custom classes p = preprocessor(genres=params['GENRES']) e = encoder(max_words=params['VOCABULARY_SIZE'], maxlen_desc=params['MAX_LEN_DESC'], maxlen_title=params['MAX_LEN_TITLE']) m = model_classifier() # prepare data for training df = p.preprocess(df) X, y = e.encode(df) X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.30, random_state=1000) e.save() # create and train model model = m.define_model(params) history = m.train_model(X_train, X_test, y_train, y_test) # save m.save_model() m.save_params()
def lancer(): if var_demo.get() == 0: if var_mode.get() == "encode": if var_choix.get() == "fichier": valeur = entre_file.get() elif var_choix.get() == "texte": valeur = var_texte.get() encoder(var_choix.get(), valeur, var_save.get()) else: valeur = entre_file.get() if var_correc.get() == 0: decoder(valeur, var_save.get(), True) else: print("sans correection") decoder(valeur, var_save.get(), False) else: valeur = entre_texte_demo.get() temps, s_bytes, s_trit1, len_Trit, nb0, s_trit3, s_trit4, s_dna, dicoDebut, dicoReverse, dicoI3, ID, dicoP, dicoIX, dicoIX_dna, dicoFinal, s_dna_final = encoder( "texte", valeur, var_save.get()) var_afficher = afficherEncodage(valeur, temps, s_bytes, s_trit1, len_Trit, nb0, s_trit3, s_trit4, s_dna, dicoDebut, dicoReverse, dicoI3, ID, dicoP, dicoIX, dicoIX_dna, dicoFinal, s_dna_final) fenetre_demo = Tk() fenetre_demo.title( "Démonstration de l'encodage d'un texte vers de l'ADN") barre = Scrollbar(fenetre_demo) label_demo = Text(fenetre_demo, yscrollcommand=barre.set) barre.config(command=label_demo.yview) barre.pack(side="right", fill='y') label_demo.pack(expand=1, fill="both") label_demo.insert(0.0, var_afficher)
joindre_salon_ok["seq"]=1 joindre_salon_ok["Type"]=11 joindre_salon_nok={} joindre_salon_nok["taille"]=125 joindre_salon_nok["seq"]=1 joindre_salon_nok["Type"]=12 ack={} ack["taille"]=125 ack["seq"]=1 ack["Type"]=63 print("---------- TEST TYPE 1 ----------\n") print(inscription) test1=encode.encoder(inscription) print("\n{0}\n".format(test1)) test1bis=decode.decoder(test1) print(test1bis) print("\n---------- TEST TYPE 2 ----------\n") print(film) test2=encode.encoder(film) print("\n{0}\n".format(test2)) test2bis=decode.decoder(test2) print(test2bis) print("\n---------- TEST TYPE 3 ----------\n") print(user) test3=encode.encoder(user) print("\n{0}\n".format(test3)) test3bis=decode.decoder(test3) print(test3bis)
from decode import decoder from encode import encoder f1 = open("file1.txt", 'wb') f2 = open("file2.txt", 'wb') str1 = encoder('godofwarpauplatinapaunotoba') str2 = encoder('godofwarpalplatinapaunotoba') f1.write(str1.encode('utf8')) f2.write(str2.encode('utf8')) f1.close() f2.close()
mem_size = 99 #code = open("/Users/paul/xenotations_first.txt", "r") def load_from_fime(path): code = open(path, "r") c = code.readlines() clean_code = list(map(lambda x: x.rstrip(), c)) return clean_code logging.info("INIT STACK") new_stack = stack() logging.info("INIT PARSER") new_decoder = parser() new_encoder = encoder() if args.path: logging.info("LOAD CODE") clean_code = load_from_fime(args.path) else: logging.error("No Input Specification") exit() logging.info("INIT MEMORY") new_mem = pointer(clean_code, mem_size) new_interp = interpreter(new_decoder, new_stack, new_encoder, new_mem) logging.info("START EXECUTION") while True:
from decode import decoder from encode import encoder assert decoder(encoder("alodicksiano")) == "alodicksiano" assert decoder(encoder("alodicksiano")) == "alodicksiano" assert decoder(encoder("alodicksiano")) == "alodicksiano" assert decoder(encoder("123456789 123456789 123456789 123456789") ) == "123456789 123456789 123456789 123456789"
Entry(self, textvariable=self.keyheight, width=40).grid(row=5, column=1, sticky='W') self.keywidth = StringVar() Label(self, text="照片的宽(pixel):").grid(row=6, sticky='W', pady=5) Entry(self, textvariable=self.keywidth, width=40).grid(row=6, column=1, sticky='W') def xz(): filename = tkinter.filedialog.askopenfilename() if filename != '': Label(self, text=filename).grid(row=7, column=1, sticky='w') self.filename_in=filename def xz2(): filename = tkinter.filedialog.asksaveasfilename() if filename != '': Label(self, text=filename).grid(row=8, column=1, sticky='w') self.filename_out=filename Label(self, text="输入文件夹:").grid(row=7, column=0, sticky='W', pady=5) Button(self, text=" ... ", command=xz).grid(row=7, column=2, sticky='W', padx=2) Label(self, text="输出文件夹:").grid(row=8, column=0, sticky='W', pady=5) Button(self, text=" ... ", command=xz2).grid(row=8, column=2, sticky='W', padx=2) Button(self,text='确定',width=5,height=2, command=self.quit).grid(row=14,column=1,sticky='W',padx=100) app = Application() app.mainloop() en.encoder(app.filename_in,"output.mp4",int(app.interval.get()),int(app.keywidth.get()),int(app.keyheight.get()))