Esempio n. 1
0
    def infer(self, instance, *args, **kwargs):
        instance = instance.strip().lower()
        if not all([ord(c) < 128 for c in instance]):
            print('Non ASCII symbols in the string, returning empty slots', file=sys.stderr)
            return {}

        tokens = tokenize_reg(instance)
        if len(tokens) > 0:
            return self.predict_slots(tokens)
        else:
            return {}
Esempio n. 2
0
    def __call__(self, batch, *args, **kwargs):
        if isinstance(batch[0], str):
            batch = [tokenize_reg(instance.strip()) for instance in batch]

        slots = [{}] * len(batch)

        m = [i for i, v in enumerate(batch) if v]
        if m:
            batch = [batch[i] for i in m]
            tags_batch = self._ner_network.predict_for_token_batch(batch)
            for i, tokens, tags in zip(m, batch, tags_batch):
                slots[i] = self.predict_slots(tokens, tags)
        return slots
Esempio n. 3
0
    def __call__(self, batch, *args, **kwargs):
        if isinstance(batch[0], str):
            batch = [tokenize_reg(instance.strip()) for instance in batch]

        slots = [{}] * len(batch)

        m = [i for i, v in enumerate(batch) if v]
        if m:
            batch = [batch[i] for i in m]
            # tags_batch = self._ner_network.predict_for_token_batch(batch)
            # batch example: [['is', 'there', 'anything', 'else']]
            for i, tokens in zip(m, batch):
                # tokens are['is', 'there', 'anything', 'else']
                slots[i] = self._predict_slots(tokens, self.threshold)
                # slots[i] example {'food': 'steakhouse'}
        # slots we want, example : [{'pricerange': 'moderate', 'area': 'south'}]
        return slots
Esempio n. 4
0
    def __call__(self, batch, *args, **kwargs):
        if isinstance(batch[0], str):
            batch = [tokenize_reg(instance.strip()) for instance in batch]

        slots = [{}] * len(batch)

        m = [i for i, v in enumerate(batch) if v]
        if m:
            batch = [batch[i] for i in m]
            # tags_batch = self._ner_network.predict_for_token_batch(batch)
            # batch example: [['is', 'there', 'anything', 'else']]
            for i, tokens in zip(m, batch):
                # tokens are['is', 'there', 'anything', 'else']
                slots_values_lists = self._predict_slots(tokens)
                if self.return_all:
                    slots[i] = dict(slots_values_lists)
                else:
                    slots[i] = {slot: val_list[0] for slot, val_list in slots_values_lists.items()}
                # slots[i] example {'food': 'steakhouse'}
        # slots we want, example : [{'pricerange': 'moderate', 'area': 'south'}]
        return slots
Esempio n. 5
0
 def __call__(self, batch, *args, **kwargs):
     if isinstance(batch[0], str):
         batch = [tokenize_reg(utterance) for utterance in batch]
     return self._net.predict_on_batch(batch)