Esempio n. 1
0
 def _parse(self, string):
     s = string.split()
     sentences = [s]
     if self._mode == 'bert':
         i, m = constituency_bert(self._tokenizer, sentences)
     elif self._mode == 'xlnet':
         i, m = constituency_xlnet(self._tokenizer, sentences)
     else:
         raise Exception(
             'mode not supported, only supported `bert` or `xlnet`'
         )
     charts_val, tags_val = self._sess.run(
         (self._charts, self._tags),
         {self._input_ids: i, self._word_end_mask: m},
     )
     for snum, sentence in enumerate(sentences):
         chart_size = len(sentence) + 1
         chart = charts_val[snum, :chart_size, :chart_size, :]
     return s, tags_val[0], chart_decoder.decode(chart)
Esempio n. 2
0
    def _parse(self, string):
        s = string.split()
        sentences = [s]
        if self._mode == 'bert':
            f = constituency_bert
        elif self._mode == 'xlnet':
            f = constituency_xlnet
        else:
            raise ValueError(
                'mode not supported, only supported `bert` or `xlnet`')
        i, m, tokens = f(self._tokenizer, sentences)

        r = self._execute(
            inputs=[i, m],
            input_labels=['input_ids', 'word_end_mask'],
            output_labels=['charts', 'tags'],
        )
        charts_val, tags_val = r['charts'], r['tags']

        for snum, sentence in enumerate(sentences):
            chart_size = len(sentence) + 1
            chart = charts_val[snum, :chart_size, :chart_size, :]
        return s, tags_val[0], chart_decoder.decode(chart)