本文整理汇总了Python中random.Random方法的典型用法代码示例。如果您正苦于以下问题:Python random.Random方法的具体用法?Python random.Random怎么用?Python random.Random使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类random
的用法示例。
在下文中一共展示了random.Random方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _makenet
# 需要导入模块: import random [as 别名]
# 或者: from random import Random [as 别名]
def _makenet(x, num_layers, dropout, random_seed):
from keras.layers import Dense, Dropout
dropout_seeder = random.Random(random_seed)
for i in range(num_layers - 1):
# add intermediate layers
if dropout:
x = Dropout(dropout, seed=dropout_seeder.randint(0, 10000))(x)
x = Dense(1024, activation="relu", name='dense_layer_{}'.format(i))(x)
if dropout:
# add the final dropout layer
x = Dropout(dropout, seed=dropout_seeder.randint(0, 10000))(x)
return x
示例2: __init__
# 需要导入模块: import random [as 别名]
# 或者: from random import Random [as 别名]
def __init__(self):
global FLAGS
self.FLAGS = FLAGS
self.unk_token = "UNK"
self.entry_match_token = "entry_match"
self.column_match_token = "column_match"
self.dummy_token = "dummy_token"
self.tf_data_type = {}
self.tf_data_type["double"] = tf.float64
self.tf_data_type["float"] = tf.float32
self.np_data_type = {}
self.np_data_type["double"] = np.float64
self.np_data_type["float"] = np.float32
self.operations_set = ["count"] + [
"prev", "next", "first_rs", "last_rs", "group_by_max", "greater",
"lesser", "geq", "leq", "max", "min", "word-match"
] + ["reset_select"] + ["print"]
self.word_ids = {}
self.reverse_word_ids = {}
self.word_count = {}
self.random = Random(FLAGS.python_seed)
示例3: __init__
# 需要导入模块: import random [as 别名]
# 或者: from random import Random [as 别名]
def __init__(self, seed=None):
Data.__init__(self)
self.output = ''
self.yesno_callback = False
self.yesno_casual = False # whether to insist they answer
self.clock1 = 30 # counts down from finding last treasure
self.clock2 = 50 # counts down until cave closes
self.is_closing = False # is the cave closing?
self.panic = False # they tried to leave during closing?
self.is_closed = False # is the cave closed?
self.is_done = False # caller can check for "game over"
self.could_fall_in_pit = False # could the player fall into a pit?
self.random_generator = random.Random()
if seed is not None:
self.random_generator.seed(seed)
示例4: demo_bw
# 需要导入模块: import random [as 别名]
# 或者: from random import Random [as 别名]
def demo_bw():
# demo Baum Welch by generating some sequences and then performing
# unsupervised training on them
print()
print("Baum-Welch demo for market example")
print()
model, states, symbols = _market_hmm_example()
# generate some random sequences
training = []
import random
rng = random.Random()
rng.seed(0)
for i in range(10):
item = model.random_sample(rng, 5)
training.append([(i[0], None) for i in item])
# train on those examples, starting with the model that generated them
trainer = HiddenMarkovModelTrainer(states, symbols)
hmm = trainer.train_unsupervised(training, model=model,
max_iterations=1000)
示例5: setUp
# 需要导入模块: import random [as 别名]
# 或者: from random import Random [as 别名]
def setUp(self):
self.rand = random.Random(None)
self.numDonors = 20
self.numPrizes = 40
self.event = randgen.build_random_event(
self.rand, num_runs=20, num_prizes=self.numPrizes, num_donors=self.numDonors
)
for prize in self.rand.sample(
list(self.event.prize_set.all()), self.numPrizes // 10
):
prize.key_code = True
prize.save()
randgen.generate_prize_key(self.rand, prize=prize).save()
self.templateEmail = post_office.models.EmailTemplate.objects.create(
name='testing_prize_shipping_notification',
description='',
subject='A Test',
content=self.testTemplateContent,
)
self.sender = 'nobody@nowhere.com'
示例6: setUp
# 需要导入模块: import random [as 别名]
# 或者: from random import Random [as 别名]
def setUp(self):
self.rand = random.Random(None)
self.event = randgen.generate_event(self.rand)
self.event.save()
self.run = randgen.generate_run(self.rand, event=self.event)
self.run.order = 1
self.run.save()
self.prize = randgen.generate_prize(
self.rand,
event=self.event,
start_run=self.run,
end_run=self.run,
random_draw=True,
)
self.prize.key_code = True
self.prize.save()
models.PrizeKey.objects.bulk_create(
randgen.generate_prize_key(self.rand, prize=self.prize) for _ in range(100)
)
self.prize_keys = self.prize.prizekey_set.all()
示例7: setUp
# 需要导入模块: import random [as 别名]
# 或者: from random import Random [as 别名]
def setUp(self):
self.rand = random.Random(None)
self.superuser = User.objects.create_superuser(
'superuser', 'super@example.com', 'password',
)
self.processor = User.objects.create(username='processor', is_staff=True)
self.processor.user_permissions.add(
Permission.objects.get(name='Can change donor'),
Permission.objects.get(name='Can change donation'),
)
self.head_processor = User.objects.create(
username='head_processor', is_staff=True
)
self.head_processor.user_permissions.add(
Permission.objects.get(name='Can change donor'),
Permission.objects.get(name='Can change donation'),
Permission.objects.get(name='Can send donations to the reader'),
)
self.event = randgen.build_random_event(self.rand)
self.session = self.client.session
self.session['admin-event'] = self.event.id
self.session.save()
示例8: seeded_range
# 需要导入模块: import random [as 别名]
# 或者: from random import Random [as 别名]
def seeded_range(seed, start, stop=None, step=1, extra=None):
"""
A filter to produce deterministic random numbers.
Produce a random item from range(start, stop[, step]), use the value and
optional ``extra`` value to set the seed for the random number generator.
Basic usage::
ansible_fqdn|seeded_range(60)
"hello"|seeded_range(1, 10, extra="world")
"""
hashed_seed = new_hash('sha1')
hashed_seed.update(seed)
if extra is not None:
hashed_seed.update(extra)
hashed_seed = hashed_seed.digest()
# We rely on randrange's interpretation of parameters
return Random(hashed_seed).randrange(start, stop, step)
示例9: PredictAnswer
# 需要导入模块: import random [as 别名]
# 或者: from random import Random [as 别名]
def PredictAnswer(ContextSummary, question, tokenizer, estimator):
data = {'data': [{'title': 'Random',
'paragraphs': [{'context': ContextSummary,
'qas': [{'answers': [],
'question': question,
'id': '56be4db0acb8001400a502ec'}]}]}],
'version': '1.1'}
FLAGS.interact = True
eval_examples = read_squad_examples(data = data, is_training=False)
eval_features, all_results = testing_model(eval_examples, tokenizer, estimator)
output_prediction_file = os.path.join(FLAGS.output_dir, "predictions.json")
output_nbest_file = os.path.join(FLAGS.output_dir, "nbest_predictions.json")
output_null_log_odds_file = os.path.join(FLAGS.output_dir, "null_odds.json")
Prediction = write_predictions(eval_examples, eval_features, all_results,
FLAGS.n_best_size, FLAGS.max_answer_length,
FLAGS.do_lower_case, output_prediction_file,
output_nbest_file, output_null_log_odds_file)
return list(Prediction.values())[0]
开发者ID:Nagakiran1,项目名称:Extending-Google-BERT-as-Question-and-Answering-model-and-Chatbot,代码行数:21,代码来源:run_squad.py
示例10: ids_tensor
# 需要导入模块: import random [as 别名]
# 或者: from random import Random [as 别名]
def ids_tensor(cls, shape, vocab_size, rng=None, name=None):
"""Creates a random int32 tensor of the shape within the vocab size."""
if rng is None:
rng = random.Random()
total_dims = 1
for dim in shape:
total_dims *= dim
values = []
for _ in range(total_dims):
values.append(rng.randint(0, vocab_size - 1))
return tf.constant(value=values, dtype=tf.int32, shape=shape, name=name)
示例11: read_samples
# 需要导入模块: import random [as 别名]
# 或者: from random import Random [as 别名]
def read_samples(self, split, index, n=1):
items = self.files[split][index:index+n]
items = [(self.read_file(filename), meta) for filename, meta in items]
res = []
for item, meta in items:
rng = random.Random(str(self.random_seed) + meta['filename'])
res.append(Sample(item, None, meta.copy(), rng))
return res
示例12: read_samples
# 需要导入模块: import random [as 别名]
# 或者: from random import Random [as 别名]
def read_samples(self, split, index, n=1):
items = self.data[split][index: index+n]
return [Sample(item, item+5, {'meta': item}, random.Random(self.random_seed + item))
for item in items]
示例13: read_samples
# 需要导入模块: import random [as 别名]
# 或者: from random import Random [as 别名]
def read_samples(self, split, index, n=1):
items = self.files[split][index:index+n]
items = [(Path(filename).read_text(), meta) for filename, meta in items]
res = []
for item, meta in items:
rng = random.Random(str(self.random_seed) + meta['filename'])
res.append(Sample(item, None, meta.copy(), rng))
return res
示例14: read_samples
# 需要导入模块: import random [as 别名]
# 或者: from random import Random [as 别名]
def read_samples(self, split, index, n=1):
items = self.files[split][index:index+n]
items = [(self.read_file(filename), meta) for filename, meta in items]
res = []
for item, meta in items:
rng = random.Random(str(self.random_seed) + meta['filename'])
res.append(Sample(item, None, meta.copy(), rng))
return res
示例15: read_samples
# 需要导入模块: import random [as 别名]
# 或者: from random import Random [as 别名]
def read_samples(self, split, index, n=1):
items = self.files[split][index:index+n]
items = [(Path(filename).read_text(), meta) for filename, meta in items]
res = []
for item, meta in items:
rng = random.Random(str(self.random_seed) + meta['filename'])
res.append(Sample(item, None, meta.copy(), rng))
return res