-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement softmax as splittable aggregation
- Loading branch information
1 parent
66afa63
commit 2b9e714
Showing
6 changed files
with
52 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from typing import Sequence | ||
|
||
import jpype | ||
|
||
from neuralogic.core.constructs.function.function import Aggregation | ||
|
||
|
||
class Softmax(Aggregation): | ||
__slots__ = ("agg_terms",) | ||
|
||
def __init__( | ||
self, | ||
name: str, | ||
*, | ||
agg_terms: Sequence[int] = None, | ||
): | ||
super().__init__(name) | ||
if agg_terms is not None: | ||
agg_terms = tuple(int(i) for i in agg_terms) | ||
self.agg_terms = agg_terms | ||
|
||
def __call__(self, entity=None, *, agg_terms: Sequence[int] = None): | ||
softmax = Softmax(self.name, agg_terms=agg_terms) | ||
return Aggregation.__call__(softmax, entity) | ||
|
||
def is_parametrized(self) -> bool: | ||
return self.agg_terms is not None | ||
|
||
def get(self): | ||
return jpype.JClass("cz.cvut.fel.ida.algebra.functions.combination.Softmax")(self.agg_terms) | ||
|
||
def __str__(self): | ||
if self.agg_terms is None: | ||
return "softmax" | ||
return f"softmax(agg_terms={self.agg_terms})" |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters