|
|
@ -12,23 +12,26 @@ logger = logging.getLogger("Slither-simil") |
|
|
|
def train(args): |
|
|
|
def train(args): |
|
|
|
|
|
|
|
|
|
|
|
try: |
|
|
|
try: |
|
|
|
|
|
|
|
last_data_train_filename = "last_data_train.txt" |
|
|
|
model_filename = args.model |
|
|
|
model_filename = args.model |
|
|
|
solc = args.solc |
|
|
|
solc = args.solc |
|
|
|
dirname = args.input |
|
|
|
dirname = args.input |
|
|
|
ext = args.filter |
|
|
|
ext = args.filter |
|
|
|
|
|
|
|
nsamples = args.nsamples |
|
|
|
|
|
|
|
|
|
|
|
if dirname is None: |
|
|
|
if dirname is None: |
|
|
|
logger.error('The train mode requires the input parameter.') |
|
|
|
logger.error('The train mode requires the input parameter.') |
|
|
|
sys.exit(-1) |
|
|
|
sys.exit(-1) |
|
|
|
|
|
|
|
|
|
|
|
contracts = load_contracts(dirname, ext=ext, nsamples=None) |
|
|
|
contracts = load_contracts(dirname, ext=ext, nsamples=nsamples) |
|
|
|
with open("data.txt", 'w') as f: |
|
|
|
logger.info('Saving extracted data into', last_data_train_filename) |
|
|
|
|
|
|
|
with open(last_data_train_filename, 'w') as f: |
|
|
|
for contract in contracts: |
|
|
|
for contract in contracts: |
|
|
|
for function,ir in encode_contract(contract,solc).items(): |
|
|
|
for function,ir in encode_contract(contract,solc).items(): |
|
|
|
if ir != []: |
|
|
|
if ir != []: |
|
|
|
f.write(" ".join(ir)+"\n") |
|
|
|
f.write(" ".join(ir)+"\n") |
|
|
|
|
|
|
|
|
|
|
|
model = train_unsupervised(input='data.txt', model='skipgram') |
|
|
|
model = train_unsupervised(input=last_data_train_filename, model='skipgram') |
|
|
|
model.save_model(model_filename) |
|
|
|
model.save_model(model_filename) |
|
|
|
print(model.get_words()) |
|
|
|
print(model.get_words()) |
|
|
|
|
|
|
|
|
|
|
|