def init_model(): characters = list("0123456789abcd ") characters.append("<EOS>") global int2char int2char = list(characters) global char2int char2int = {c: i for i, c in enumerate(characters)} global VOCAB_SIZE VOCAB_SIZE = len(characters) dyparams = dy.DynetParams() dyparams.set_random_seed(666) dyparams.init() pc = dy.ParameterCollection() lstm = dy.LSTMBuilder(LAYERS, INPUT_DIM, HIDDEN_DIM, pc) params = {} params["lookup"] = pc.add_lookup_parameters((VOCAB_SIZE, INPUT_DIM)) params["R"] = pc.add_parameters((LSTM_OUTPUT_SIZE, HIDDEN_DIM)) params["bias"] = pc.add_parameters((LSTM_OUTPUT_SIZE)) params["w1"] = pc.add_parameters((N1, LSTM_OUTPUT_SIZE)) params["w2"] = pc.add_parameters((MLP_OUTPUT_SIZE, N1)) params["b1"] = pc.add_parameters((N1)) params["b2"] = pc.add_parameters((MLP_OUTPUT_SIZE)) trainer = dy.RMSPropTrainer(pc) return (lstm, params, pc), trainer
import argparse from random import shuffle import sys import string from nltk.corpus import stopwords as SW #import hunspell_checker #from hunspell_checker import HunspellChecker import attacks from tqdm import tqdm import pickle import pandas as pd import dynet_config dynet_config.set(random_seed=42) import dynet as dy dyparams = dy.DynetParams() dyparams.set_mem(8000) dynet_config.set_gpu() import numpy as np np.random.seed(42) import random random.seed(42) sys.path.insert(0, 'defenses/scRNN/') sys.path.append('spell_checkers/') nlp = English() spell = SpellChecker() from corrector import ScRNNChecker # personal logging lib import log