| 105 | return emb |
| 106 | |
| 107 | def to_sample(self, inputs): |
| 108 | inputs = self.parse_input_fn(inputs) |
| 109 | neg = [] |
| 110 | pos = [] |
| 111 | if len(inputs) == 2 and inputs[1] is not None: |
| 112 | neg.append(inputs[1]) |
| 113 | if len(inputs) == 3: |
| 114 | pos.append(inputs[2]) |
| 115 | |
| 116 | if self.pos_sample_fn is not None: |
| 117 | src, pos_from_fn = self.pos_sample_fn(inputs[0]) |
| 118 | pos.append(pos_from_fn) |
| 119 | else: |
| 120 | src = inputs[0] |
| 121 | if self.neg_sample_fn is not None: |
| 122 | neg.append(self.neg_sample_fn(inputs[0])) |
| 123 | pos = tf.concat(pos, axis=-1) |
| 124 | neg = tf.concat(neg, axis=-1) |
| 125 | return src, pos, neg |
| 126 | |
| 127 | def __call__(self, inputs): |
| 128 | src, pos, negs = self.to_sample(inputs) |