def sample(self, seed=None, length=None, diversity=1.0):
        """Sample the model"""
        self.sample_model.reset_states()

        if length is None:
            length = 100 if self.vectorizer.word_tokens else 500

        if seed is None:
            seed = random.choice(self.seeds)
            print('Using seed: ', end='')
            print_cyan(seed)
            print('-' * 50)

        preds = None
        seed_vector = self.vectorizer.vectorize(seed)
        # Feed in seed string
        print_cyan(seed, end=' ' if self.vectorizer.word_tokens else '')
        for char_index in np.nditer(seed_vector):
            preds = self.sample_model.predict(np.array([[char_index]]),
                                              verbose=0)

        sampled_indices = np.array([], dtype=np.int32)
        # Sample the model one token at a time
        for i in range(length):
            char_index = 0
            if preds is not None:
                char_index = sample_preds(preds[0][0], diversity)
            sampled_indices = np.append(sampled_indices, char_index)
            preds = self.sample_model.predict(np.array([[char_index]]),
                                              verbose=0)
        sample = self.vectorizer.unvectorize(sampled_indices)
        print(sample)
        return sample
Beispiel #2
0
def display_main_menu(state):
    label_to_scanner = {
        str(i): scanner
        for i, scanner in enumerate(SCANNERS, start=1)
    }
    while True:
        print(MAIN_MENU_TITLE.upper())
        print()
        for label, scanner in label_to_scanner.items():
            print_cyan(f'({label}) {scanner.get_menu_item_label()}')
        print()
        await_valid_input(
            'ENTER SELECTION', sorted([k for k in label_to_scanner.keys()]),
            lambda label: label_to_scanner[label].initiate_scan(state))
Beispiel #3
0
    def enter_queue(self):
        self.sem_queue.acquire()
        for i in range(0, self.num_people):
            if random.randint(0, 2) == MALE:
                self.start_male_time.append(time.time())

                self.queue.put([MALE, self.count_person])
                self.count_person += 1
                male_enqueue_message = (
                    '|ENQUEUE|> People #{0}: A man has arrived to the queue'.
                    format(self.count_person - 1))
                print_cyan(male_enqueue_message)
                sleep(random.randint(1, 7))

            elif random.randint(0, 2) == FEMALE:
                self.start_female_time.append(time.time())

                self.queue.put([FEMALE, self.count_person])
                self.count_person += 1
                female_enqueue_message = (
                    '|ENQUEUE|> People #{0}: A woman has arrived to the queue'.
                    format(self.count_person - 1))
                print_red(female_enqueue_message)
                sleep(random.randint(1, 7))
            else:
                self.start_third_gender_time.append(time.time())

                self.queue.put([THIRD_GENDER, self.count_person])
                self.count_person += 1
                third_gender_message = (
                    '|ENQUEUE|> People #{0}: A third gender people has arrived to the queue'
                    .format(self.count_person - 1))
                print(third_gender_message)
                sleep(random.randint(1, 7))
        start_timers = {
            'start_female_time': self.start_female_time,
            'start_male_time': self.start_male_time,
            'start_third_gender_time': self.start_third_gender_time
        }
        self.queue_time.put(start_timers)
        self.sem_queue.release()