Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"""
def _embed(self, edge: tuple):
return self.kv[edge[0]] * self.kv[edge[1]]
class WeightedL1Embedder(EdgeEmbedder):
"""
Weighted L1 node features
"""
def _embed(self, edge: tuple):
return np.abs(self.kv[edge[0]] - self.kv[edge[1]])
class WeightedL2Embedder(EdgeEmbedder):
"""
Weighted L2 node features
"""
def _embed(self, edge: tuple):
return (self.kv[edge[0]] - self.kv[edge[1]]) ** 2
"""
def _embed(self, edge: tuple):
return (self.kv[edge[0]] + self.kv[edge[1]]) / 2
class HadamardEmbedder(EdgeEmbedder):
"""
Hadamard product node features
"""
def _embed(self, edge: tuple):
return self.kv[edge[0]] * self.kv[edge[1]]
class WeightedL1Embedder(EdgeEmbedder):
"""
Weighted L1 node features
"""
def _embed(self, edge: tuple):
return np.abs(self.kv[edge[0]] - self.kv[edge[1]])
class WeightedL2Embedder(EdgeEmbedder):
"""
Weighted L2 node features
"""
def _embed(self, edge: tuple):
return (self.kv[edge[0]] - self.kv[edge[1]]) ** 2
entities=tokens,
weights=features)
return edge_kv
class AverageEmbedder(EdgeEmbedder):
"""
Average node features
"""
def _embed(self, edge: tuple):
return (self.kv[edge[0]] + self.kv[edge[1]]) / 2
class HadamardEmbedder(EdgeEmbedder):
"""
Hadamard product node features
"""
def _embed(self, edge: tuple):
return self.kv[edge[0]] * self.kv[edge[1]]
class WeightedL1Embedder(EdgeEmbedder):
"""
Weighted L1 node features
"""
def _embed(self, edge: tuple):
return np.abs(self.kv[edge[0]] - self.kv[edge[1]])
token = str(tuple(sorted(edge)))
embedding = self._embed(edge)
tokens.append(token)
features.append(embedding)
# Build KV instance
edge_kv = KeyedVectors(vector_size=self.kv.vector_size)
edge_kv.add(
entities=tokens,
weights=features)
return edge_kv
class AverageEmbedder(EdgeEmbedder):
"""
Average node features
"""
def _embed(self, edge: tuple):
return (self.kv[edge[0]] + self.kv[edge[1]]) / 2
class HadamardEmbedder(EdgeEmbedder):
"""
Hadamard product node features
"""
def _embed(self, edge: tuple):
return self.kv[edge[0]] * self.kv[edge[1]]