def embed_sent(self, x: sent.Sentence) -> expression_seqs.ExpressionSequence: # TODO refactor: seems a bit too many special cases that need to be distinguished batched = batchers.is_batched(x) first_sent = x[0] if batched else x if hasattr(first_sent, "get_array"): if not batched: return expression_seqs.LazyNumpyExpressionSequence( lazy_data=x.get_array()) else: return expression_seqs.LazyNumpyExpressionSequence( lazy_data=batchers.mark_as_batch([s for s in x]), mask=x.mask) else: if not batched: embeddings = [self.embed(word) for word in x] else: embeddings = [] for word_i in range(x.sent_len()): embeddings.append( self.embed( batchers.mark_as_batch( [single_sent[word_i] for single_sent in x]))) return expression_seqs.ExpressionSequence(expr_list=embeddings, mask=x.mask)
def embed_speech_sent(self, x): # TODO refactor: seems a bit too many special cases that need to be distinguished # x = x.batches[0] batched = batchers.is_batched(x) first_sent = x[0] if batched else x if hasattr(first_sent, "get_array"): if not batched: return expression_seqs.LazyNumpyExpressionSequence( lazy_data=x.get_array()) else: return expression_seqs.LazyNumpyExpressionSequence( lazy_data=batchers.mark_as_batch([s for s in x]), mask=x.mask) else: raise ValueError("!! Expected to use above") return expression_seqs.ExpressionSequence(expr_list=embeddings, mask=x.mask)