本文整理汇总了Python中decode.decode方法的典型用法代码示例。如果您正苦于以下问题:Python decode.decode方法的具体用法?Python decode.decode怎么用?Python decode.decode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类decode
的用法示例。
在下文中一共展示了decode.decode方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: xor
# 需要导入模块: import decode [as 别名]
# 或者: from decode import decode [as 别名]
def xor(genomes):
# Task parameters
xor_inputs = [(0.0,0.0),(0.0,1.0),(1.0,0.0),(1.0,1.0)]
expected_outputs = [0.0, 1.0, 1.0, 0.0]
# Iterate through potential solutions
for genome_key, genome in genomes:
cppn = CPPN.create(genome)
substrate = decode(cppn,sub_in_dims,sub_o_dims,sub_sh_dims)
sum_square_error = 0.0
for inputs, expected in zip(xor_inputs, expected_outputs):
inputs = inputs + (1.0,)
actual_output = substrate.activate(inputs)[0]
sum_square_error += ((actual_output - expected)**2.0)/4.0
genome.fitness = 1.0 - sum_square_error
# Inititalize population
示例2: report_output
# 需要导入模块: import decode [as 别名]
# 或者: from decode import decode [as 别名]
def report_output(pop):
'''
Reports the output of the current champion for the xor task.
pop -- population to be reported
'''
genome = pop.best_genome
cppn = CPPN.create(genome)
substrate = decode(cppn,sub_in_dims,sub_o_dims,sub_sh_dims)
sum_square_error = 0.0
print("\n=================================================")
print("\tChampion Output at Generation: {}".format(pop.current_gen))
print("=================================================")
for inputs, expected in zip(xor_inputs, expected_outputs):
print("Input: {}\nExpected Output: {}".format(inputs,expected))
inputs = inputs + (1.0,)
actual_output = substrate.activate(inputs)[0]
sum_square_error += ((actual_output - expected)**2.0)/4.0
print("Actual Output: {}\nLoss: {}\n".format(actual_output,sum_square_error))
print("Total Loss: {}".format(sum_square_error))
示例3: xor
# 需要导入模块: import decode [as 别名]
# 或者: from decode import decode [as 别名]
def xor(genomes):
# Task parameters
task_input = [(0.0,0.0),(0.0,1.0),(1.0,0.0),(1.0,1.0)]
task_output = [0.0, 1.0, 1.0, 0.0]
for genome_key, genome in genomes:
cppn = CPPN.create(genome)
substrate = decode(cppn, input_dim, output_dim, hidden_dim)
sum_square_error = 0.0
# Test substrate on task
for inputs, expected in zip(task_input, task_output):
inputs += 0.0,
substrate_output = substrate.activate(inputs)[0]
sum_square_error += ((substrate_output - expected)**2.0)/4.0
genome.fitness = 1.0 - sum_square_error
# Evolutionary run
示例4: process_decode
# 需要导入模块: import decode [as 别名]
# 或者: from decode import decode [as 别名]
def process_decode(self, infile, outfile):
inf = io.open(infile, 'r', encoding='utf-8')
# search until blank line:
header = ""
header_lines = []
for line in inf:
line = line.rstrip()
# we hit a blank line, and we have at least one line already
if not line and len(header_lines) > 0:
break
header_lines.append(line)
header = " ".join(header_lines)
(conf_name, mask, version, ls_len) = decode.decode_conf_name(header)
s = self.states.decode_states.get(version, None)
if s is None:
inf.close()
return
body_text = ""
for line in inf:
body_text += line
inf.close()
state = decode.DecodeState(s.common, conf_name, mask,
s.header_grammar, s.body_grammar, {},
s.space_before, s.space_after, decode.Done())
msg = decode.decode(header, body_text, state, ls_len)
outf = io.open(outfile, 'w', encoding='utf-8')
outf.write(msg)
outf.close()
示例5: decode_all
# 需要导入模块: import decode [as 别名]
# 或者: from decode import decode [as 别名]
def decode_all(rnn_predictor, valid_source_data, dictionary, beam_size, viterbi_size):
start_time = time.time()
system = []
for i, source in enumerate(valid_source_data):
start_time_sentence = time.time()
top_result, _, _, _ = decode(source, dictionary, rnn_predictor, beam_size, viterbi_size)
decode_time_sentence = time.time() - start_time_sentence
print('decoding sentence: {} time: {:.2f}'.format(i, decode_time_sentence), end='\r')
system.append(top_result)
decode_time = time.time() - start_time
return system, decode_time
示例6: train
# 需要导入模块: import decode [as 别名]
# 或者: from decode import decode [as 别名]
def train(rnn_trainer, rnn_predictor, train_data, valid_target_data, valid_source_data, dictionary,
epoch_size, model_directory, beam_size, viterbi_size):
start_time = time.time()
log_path = os.path.join(model_directory, 'log.txt')
log_file = open(log_path, 'w')
best_epoch = None
best_metrics = None
for epoch in range(epoch_size):
# Train one epoch and save the model
train_epoch(rnn_trainer, train_data, model_directory, epoch)
# Decode all sentences
rnn_predictor.restore_from_directory(model_directory)
system, decode_time = decode_all(rnn_predictor, valid_source_data, dictionary, beam_size, viterbi_size)
# Evaluate results
metrics = evaluate(system, valid_target_data)
# Print metrics
log_text = 'decoding precision: {:.2f} recall: {:.2f} f-score: {:.2f} accuracy: {:.2f}\n'.format(*metrics)
log_text += 'decoding total time: {:.2f} average time: {:.2f}'.format(decode_time, decode_time / len(system))
print(log_text)
print(log_text, file=log_file)
# Write decoded results to file
decode_path = os.path.join(model_directory, 'decode-{}.txt'.format(epoch))
with open(decode_path, 'w') as file:
file.write('\n'.join(system))
# Update best epoch
if not best_epoch or best_metrics[2] < metrics[2]:
best_epoch = epoch
best_metrics = metrics
total_time = time.time() - start_time
print('best epoch:', best_epoch)
print('best epoch metrics: precision: {:.2f} recall: {:.2f} f-score: {:.2f} accuracy: {:.2f}'.format(*best_metrics))
print('total experiment time:', total_time)
print()
return best_metrics, best_epoch
示例7: makechoise
# 需要导入模块: import decode [as 别名]
# 或者: from decode import decode [as 别名]
def makechoise():
seleccion = 0
print '''Options:
0.- Exit
1.- Download Anime
2.- Download Subtitle only
3.- Login
4.- Login As Guest
5.- Download an entire Anime(Autocatch links)
6.- Run Queue
7.- Settings
'''
try:
seleccion = int(input("> "))
except:
try:
os.system('cls')
except:
try:
os.system('clear')
except:
pass
print "ERROR: Invalid option."
makechoise()
if seleccion == 1 :
ultimate.ultimate(raw_input('Please enter Crunchyroll video URL:\n'), '', '')
elif seleccion == 2 :
decode.decode(raw_input('Please enter Crunchyroll video URL:\n'))
elif seleccion == 3 :
username = raw_input(u'Username: ')
password = getpass('Password(don\'t worry the password are typing but hidden:')
login.login(username, password)
makechoise()
elif seleccion == 4 :
login.login('', '')
makechoise()
elif seleccion == 5 :
autocatch()
queueu('.\\queue.txt')
elif seleccion == 6 :
queueu('.\\queue.txt')
elif seleccion == 7 :
settings_()
makechoise()
elif seleccion == 8 :
import debug
elif seleccion == 0 :
sys.exit()
else:
try:
os.system('cls')
except:
try:
os.system('clear')
except:
pass
print "ERROR: Invalid option."
makechoise()
#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#( )#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
示例8: __init__
# 需要导入模块: import decode [as 别名]
# 或者: from decode import decode [as 别名]
def __init__(self):
self.encode_states = {}
self.decode_states = {}
# get the latest version and work backwards
version = cfp_common.CfpCommon.get_latest_common().version()
self.latest_version = version
while version >= 0:
common = cfp_common.CfpCommon.get_common_for_version(version)
if common is None:
continue
# encode state
header_grammar = nltk.data.load("file:%s" %
common.header_cfg_filename(),
'cfg')
body_grammar = nltk.data.load("file:%s" %
common.body_cfg_filename(),
'cfg')
space_before = re.compile('\s([%s])' %
common.chars_to_remove_a_space_before())
space_after = re.compile('([%s])\s' %
common.chars_to_remove_a_space_after())
last_or_nots = common.choose_last_or_nots()
estate = encode.EncodeState("", None, common, header_grammar,
body_grammar, {}, space_before,
space_after, last_or_nots, None)
self.encode_states[version] = estate
# decode state
de_header_grammar = decode.load_and_norm_grammar(
common.header_cfg_filename())
de_body_grammar = decode.load_and_norm_grammar(
common.body_cfg_filename())
de_space_before = re.compile(
'([%s])' % common.chars_to_remove_a_space_before())
de_space_after = re.compile(
'([%s])' % common.chars_to_remove_a_space_after())
destate = decode.DecodeState(common, "", 0, de_header_grammar,
de_body_grammar, {}, de_space_before,
de_space_after, None)
self.decode_states[version] = destate
version -= 1
示例9: makechoise
# 需要导入模块: import decode [as 别名]
# 或者: from decode import decode [as 别名]
def makechoise():
seleccion = 0
print '''Options:
0.- Exit
1.- Download Anime
2.- Download Subtitle only
3.- Login
4.- Login As Guest
5.- Download an entire Anime(Autocatch links)
6.- Run Queue
7.- Settings
'''
try:
seleccion = int(input("> "))
except:
try:
os.system('cls')
except:
try:
os.system('clear')
except:
pass
print "ERROR: Invalid option."
makechoise()
if seleccion == 1 :
ultimate.ultimate(raw_input('Please enter Crunchyroll video URL:\n'), '', '')
elif seleccion == 2 :
decode.decode(raw_input('Please enter Crunchyroll video URL:\n'))
elif seleccion == 3 :
username = raw_input(u'Username: ')
password = getpass('Password(don\'t worry the password are typing but hidden:')
login.login(username, password)
makechoise()
elif seleccion == 4 :
login.login('', '')
makechoise()
elif seleccion == 5 :
autocatch()
queueu('.\\queue.txt')
elif seleccion == 6 :
queueu('.\\queue.txt')
elif seleccion == 7 :
settings_()
makechoise()
elif seleccion == 8 :
import debug
elif seleccion == 0 :
sys.exit()
else:
try:
os.system('cls')
except:
try:
os.system('clear')
except:
pass
print "ERROR: Invalid option."
makechoise()
#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#( )#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#