Ejemplo n.º 1
0
def main():
    #args = argparse.ArgumentParser().parse_args()
    args = argumentparser.ArgumentParser()
    if args.run_all == 1:
        # Try all combinations
        #models = ['cnn-rand', 'cnn-static', 'cnn-non-static', 'cnn-3']
        models = ['cnn-3', 'cnn-non-static', 'cnn-static','cnn-rand']
        #data_dirs = ['data/', '/home/fanyy/sohu/raw_data/','/home/fanyy/sohu/raw_data_short/', '/home/fanyy/sohu/raw_data_short/stopwords/']
        data_dirs = ['data/', '/home/fanyy/sohu/raw_data/','/home/fanyy/sohu/raw_data_short/']
        nb_words = [10000]
        max_sequence_len = [200, 500]
        batch_size = [64]

        for model in models:
            for data_dir in data_dirs:
                for nb in nb_words:
                    for max_len in max_sequence_len:
                        for b_size in batch_size:
                            args.model_name = model
                            args.data_dir = data_dir
                            args.nb_words = nb
                            args.max_sequence_len = max_len
                            args.batch_size = b_size
                            try:
                                run(args)
                            except:
                                print("exception!!!")
                            else:
                                print("OK!")
    else:
        run(args)
Ejemplo n.º 2
0
    def __init__(self):
        """Get command line arguments to check which mode is enabled

        """
        args = argumentparser.ArgumentParser().parse()
        pws = list()

        config = configreader.ConfigReader().read()

        self.source_port = int(config['NSDP']['SourcePort'])
        self.dest_port = int(config['NSDP']['DestPort'])
        self.interface = config['NSDP']['Interface']
        self.dest_ip = config['NSDP']['DestIP']
        self.delay = config.getfloat('NSDP', 'Delay')
        self.network = network.Network(self.interface, self.dest_ip,
                                       self.source_port, self.dest_port)
        self.quiet = False

        if args['sniffer'] == True:
            self.mode = 'sniffer'
        elif args['discover'] == True:
            self.mode = 'discover'
            if args["target"] is not None:
                self.discovermode = "target"
                self.target = args["target"][0]
                self.fd = None
            else:
                self.discovermode = "targetlist"
                self.fd = args["targetlist"][0]

            if args["delay"] is not None:
                self.delay = args["delay"][0]
        elif args['setpassword'] == True:
            self.mode = 'setpassword'
            self.oldpassword = args["currentpassword"][0]
            self.newpassword = args["newpassword"][0]
            self.macaddress = args["macaddress"][0]
        elif args['reboot'] == True:
            self.mode = 'reboot'
            self.password = args['password'][0]
            self.macaddress = args['macaddress'][0]
        elif args['bruteforce'] is not None:
            self.mode = 'bruteforce'
            self.fd = args['bruteforce'][0]
            self.password = args['newpassword'][0]
            self.macaddress = args['macaddress'][0]

        if args['quiet'] == True:
            self.quiet = True
Ejemplo n.º 3
0
    def __init__(self):
        self.argumentParser = ap.ArgumentParser(self)
        self.fileFinder = ff.FileFinder(self)
        self.inputs = 1
        self.nLayers = self.argumentParser.nLayers()
        self.nNodes = self.argumentParser.nNodes()
        self.outputs = 1
        self.networkType = self.argumentParser.type()
        self.network = nn.NeuralNetwork(self)
        self.network.constructNetwork(inputs=self.inputs,
                                      nNodes=self.nNodes,
                                      nLayers=self.nLayers,
                                      outputs=self.outputs,
                                      networkType=self.networkType)
        self.saver = ckps.CheckpointSaver(self, self.argumentParser().save)
        self.networkTrainer = nt.NetworkTrainer(self, self.saver)

        self.function = lambda r: r / r * np.random.normal(
            0, 1)  # +np.sin(7.0*np.pi*r)
        self.function = lambda r: 1 / r**12 - 1 / r**6
        self.function = lambda r: 4 * (1.0 / (r**12) - 1.0 /
                                       (r**6)) - 4 * (1.0 / (2.5**12) - 1.0 /
                                                      (2.5**6))

        self.dataGenerator = gen.DataGenerator(0.87, 2.5, self)
        self.dataGenerator.setFunction(self.function)

        if not self.argumentParser().file == None:
            self.dataGenerator.setGeneratorType("file")
        else:
            self.dataGenerator.setGeneratorType("function")
        #self.dataGenerator.setGeneratorType("VMC")
        #self.dataGenerator.setGeneratorType("noise")

        self.dataSize = int(9987)

        self.numberOfEpochs = int(100)
        self.batchSize = int(500)
        self.testSize = self.dataSize  #int(600)
        self.testInterval = 5000
        self.printer = printer.Printer(self)
        self.printer.printSetup()
        self.plotter = plotter.Plotter(self)
Ejemplo n.º 4
0
import sys

sys.path.append("../CBOW_HS/")
from cbow_hs_model import CBOWModel
from input_data import InputData
import torch.optim as optim
from tqdm import tqdm
import argumentparser as argumentparser

args = argumentparser.ArgumentParser()

# hyper parameters
WINDOW_SIZE = args.window_size  # 上下文窗口c
BATCH_SIZE = args.batch_size  # mini-batch
MIN_COUNT = args.min_count  # 需要剔除的 低频词 的频
EMB_DIMENSION = args.embed_dimension  # embedding维度
LR = args.learning_rate  # 学习率
NEG_COUNT = args.neg_count  # 负采样数
EPOCH = args.epoch


class Word2Vec:
    def __init__(self, input_file_name, output_file_name):
        self.output_file_name = output_file_name
        self.data = InputData(input_file_name, MIN_COUNT)
        self.model = CBOWModel(self.data.word_count, EMB_DIMENSION).cuda()
        self.lr = LR
        self.optimizer = optim.SGD(self.model.parameters(), lr=self.lr)

    def train(self):
        for _ in range(1, EPOCH + 1):